Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Define Slope of EMA(20)

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    #16
    Originally posted by Harry View Post
    For the MACD there is no average true range, but there is only the difference between the current value of the MACD and the prior value of the MACD. This difference can be used as a substitute for the ATR.

    You would therefore replace the ATR with an average of the absolute amount of the one bar momentum. The code would look like this.

    Code:
    #region variables
    ....
    private Momentum slopeMACD;
    private DataSeries (absSlopeMACD); 
    ...
    #endregion
    
    private override void OnStartUp()
    {
         slopeMACD = Momentum( MACD(12,26,9), 1);
         absSlopeAverage = SMA(absSlopeMACD, normPeriod);
    }
    
    private override void OnBarUpdate()
    {
         ....
         absSlopeMACD.Set(Math.Abs(slopeMACD[0]);
         double divisor = absSlopeAverage[0];
         if (divisor > 0) 
             normalizedSlope = slopeMACD[0] / divisor;
         else
             normalizedSlope = 0;
         ...
    }
    One cannot change the access level of virtual methods. Both OnStartUp() and OnBarUpdate () should be protected, not private.

    Comment


      #17
      Originally posted by arbuthnot View Post
      Code:
      private [B]DataSeries (absSlopeMACD)[/B];
      
      private override void [B]OnStartUp()[/B] {     ...
      absSlopeAverage = SMA(absSlopeMACD, normPeriod); }
      Hi Harry

      I've been fascinated to read this thread, as much for the approaches to coding as for the ideas about 'slope'.

      I have a couple of questions, if you have a spare moment, about the coding you've used.

      I notice that you define the data series by

      Code:
      private DataSeries (absSlopeMACD);
      whereas when I've done this myself, I've used this approach:

      In Variables (without parentheses):

      Code:
      private DataSeries testseries;
      and in Initialize

      Code:
      testseries =  new DataSeries(this);
      Would you possibly be able to explain why you chose the approach you have, esp. the placing the name of the series in parentheses and how this differs from the other approach? Also, does this approach mean you don't have to state anything in Initialize?

      Moreover, I'd appreciate it if you could explain in a few words what the OnStartUp method does and how it differs from OnBarUpdate. I've seen this only once or twice in indicators and have never really grasped its purpose.

      Thanks very much in advance.
      I was simply tired and in a hurry when I wrote down the lines. Of course you do not need any parentheses when defining a variable. You also need to initialize the DataSeries. And of course it should read "protected override void OnStartUp()". I did not pay attention to the details, but simply wanted to explain how to approach the slope issue.

      Comment


        #18
        Of course I understand you were tired. You've made a great contribution to this and other threads. Thanks.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Max238, Today, 01:28 AM
        5 responses
        41 views
        0 likes
        Last Post Max238
        by Max238
         
        Started by giulyko00, Yesterday, 12:03 PM
        3 responses
        12 views
        0 likes
        Last Post NinjaTrader_BrandonH  
        Started by habeebft, Today, 07:27 AM
        1 response
        14 views
        0 likes
        Last Post NinjaTrader_ChristopherS  
        Started by AveryFlynn, Today, 04:57 AM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by r68cervera, Today, 05:29 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_ChelseaB  
        Working...
        X