The R-squared adaptive EMA indicator is made of different curves drawn on price chart. The main concept behind this new moving average is the capability to adapt its period thanks to the comparison made with the coefficient of determination / average of the least squares with an exponential moving average.
The adaptive formula will tend to make the MA the more precise to the current price direction from the last X “Period”.
Another great idea of this indicator is to draw “floating levels” above or below the EMA which are calculated with percentage of the highest and lowest values of the EMA within the last Y “flLookBack” periods.
The adaptive function code of this indicator can be use in many other indicators and new original concept, I suppose I’ll post more of them into the library in the future days/weeks.
The original idea came from forex-tsd forum, author: mladen.
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 |
//PRC_r-squared adaptive Exponential Moving Average | indicator //25.01.2017 //Nicolas @ www.prorealcode.com //Sharing ProRealTime knowledge //--- parameters // Period = 20 // flLookBack = 25 // Floating levels lookback period // flLevelUp = 90 // Floating levels up level % // flLevelDown = 10 // Floating levels down level % //--- Data = customclose SumX = 0 SumXX = 0 SumXY = 0 SumYY = 0 SumY = 0 if barindex>Period then // adaptive r-squared periods for k=0 to period-1 do tprice = Data[k] SumX = SumX+(k+1) SumXX = SumXX+((k+1)*(k+1)) SumXY = SumXY+((k+1)*tprice) SumYY = SumYY+(tprice*tprice) SumY = SumY+tprice next Q1 = SumXY - SumX*SumY/period Q2 = SumXX - SumX*SumX/period Q3 = SumYY - SumY*SumY/period iRsq=((Q1*Q1)/(Q2*Q3)) //returned moving average avg = exponentialaverage[Period+Period*(iRsq-0.25)](Data) //floating levels mini = lowest[flLookBack](avg) maxi = highest[flLookBack](avg) rrange = maxi-mini flu = mini+flLevelUp*rrange/100.0 fld = mini+flLevelDown*rrange/100.0 flm = mini+0.5*rrange endif RETURN avg coloured(0,191,255) STYLE(line,2) as "Adaptive average", flu coloured(0,191,255) STYLE(dottedline,1) as "upper level", fld coloured(244,164,96) STYLE(dottedline,1) as "lower level", flm coloured(100,100,100) STYLE(dottedline,1) as "median level" |
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 :PRC is also on YouTube, subscribe to our channel for exclusive content and tutorials
Ce code n’est valable que sur la V10.3 ? sur le 10.2 il y a une erreur de syntaxe dans le ficher visiblement
Oui en effet, c’est un indicateur “10.3” à cause uniquement de la mise en forme des courbes à la ligne RETURN.