This indicator returns a moving average converging toward the price the more a trend makes new higher-highs or lower-lows depending on the detected trend.
Settings
- Length: Controls the initial moving average smoothing factor (2 / (Length + 1)), as well as the period of rolling maximums/minimums.
- Increment: Smoothing factor increment (2 / (Increment+ 1)) for new higher-high/lower-low, lower values would return a faster converging moving average.
- Fast: Fast moving average smoothing factor.
Usage
The proposed moving average can be used like most slow moving averages.
Having a moving average able to converge closer to the price the longer a trend lasts allows users to obtain more timely crosses.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 |
// by LuxAlgo length=100 incr=10 fast=10 If barindex > length then //Settings src = customclose //Calculations once ma = 0 once fma = 0 once alpha = 0 once k = 1/incr upper = highest[length] lower = lowest[length] initma = average[length](src) cross = src crosses under ma or src crosses over ma If cross then alpha = 2 /(length+1) elsif (src > ma and upper > upper[1]) or (src < ma and lower < lower[1]) then alpha = alpha + k endif ma = ma[1] + alpha[1]*(src - ma[1]) If ma = 0 then ma = initma endif If cross then fma = (src+fma[1])/2 elsif src > ma then fma = MAX(src,fma[1])+((src-fma[1])/fast) else fma = MIN(src,fma[1])+((src-fma[1])/fast) Endif If fma = 0 then fma = src endif If fma > ma then r = 10 g = 255 b = 10 else r = 255 g = 10 b = 10 Endif Colorbetween(fma,ma,r,g,b,30) Endif Return fma coloured("red",100), ma style(line,3)coloured (r,g,b,255) |
Share this
No information on this site is investment advice or a solicitation to buy or sell any financial instrument. Past performance is not indicative of future results. Trading may expose you to risk of loss greater than your deposits and is only suitable for experienced investors who have sufficient financial means to bear such risk.
ProRealTime ITF files and other attachments :
Filename : download the ITF files
How to import ITF files into ProRealTime platform?
PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials