I would like to code a rough gradient in a moving average. My clumsy idea was to try code the SMA, must be higher than SMA of 5 periods ago plus a value, which is X below.
indicator5 = Average[C](close)
indicator6 = Average[C](close)
c3 = (indicator5 > indicator6[5]+X)
Above not working.
Help appreciated
Try
c3 = (indicator5 - indicator6[5]+X)
This could also help https://www.prorealcode.com/reply/70279/
The best way to measure a gradient is with a ratio of y and x.
c = 100
x = 5
y = average[c] - average[c](close[x-1])
Ratio = (y/x)
Negative ratio results are a downward sloping MA and the lower the number the steeper the angle. Positive ratio results are an upward sloping MA and the greater the number the steeper the angle.
If you convert it to a percentage of the average p bars back then it is even more usable.
p = 100
x = 5
y = average[p] - average[p](close[x-1])
Ratio = ((y/x)/average[p](close[x-1]))*100
return ratio
Above added as Log 217 here …
Snippet Link Library