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 Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        559 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        324 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        101 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        546 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        547 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X