Announcement

Collapse
No announcement yet.

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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        156 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        90 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        138 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        130 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        107 views
        0 likes
        Last Post CarlTrading  
        Working...
        X