Change in MA slope

What script would I use to identify a change in the MA from a previous peak so that it is reflecting a change in the slope of the MA? For example, the 40MA falls by more than 2% from the last peak.

Hi Brad,

We can use a highest high function for this. The only caveat is that we need to set an appropriate look back. I’ve gone with 80 as it is double the MA length.

// calc the moving average
m1 = MA(BARS=40);

// get the highest high of the MA
h1 = HIGHESTHIGH(m1, BARS=80);

// calc the change down
c1 = (h1 - m1) / h1 * 100;

// is it above 2%
c1 CrossesAbove 2

Hope this helps

Mathew