## Reverse EMA

Hello. I wonder if anyone here implemented Ehlers REMA.

Here is a sample code on pinescript.

```//@version=3 // Copyright (c) 2018-present, Alex Orekhov (everget) // Ehlers Reverse Exponential Moving Average script may be freely distributed under the MIT license. study("Ehlers Reverse Exponential Moving Average", shorttitle="EREMA") trendAlpha = input(title="Trend Alpha", type=float, defval=0.05) cycleAlpha = input(title="Cycle Alpha", type=float, defval=0.3) src = input(title="Source", type=source, defval=close) erema(src, alpha) => delta = 1 - alpha ema = 0.0 ema := alpha * src + delta * nz(ema[1]) // Compute Reverse EMA re1 = delta * ema + nz(ema[1]) re2 = pow(delta, 2) * re1 + nz(re1[1]) re3 = pow(delta, 4) * re2 + nz(re2[1]) re4 = pow(delta, 8) * re3 + nz(re3[1]) re5 = pow(delta, 16) * re4 + nz(re4[1]) re6 = pow(delta, 32) * re5 + nz(re5[1]) re7 = pow(delta, 64) * re6 + nz(re6[1]) re8 = pow(delta, 128) * re7 + nz(re7[1]) erema = ema - alpha * re8 eremaTrend = erema(src, trendAlpha) eremaTrendColor = #674ea7 eremaCycle = erema(src, cycleAlpha) eremaCycleColor = eremaCycle > 0 ? #0ebb23 : red eremaTrendPlot = plot(eremaTrend, title="Trend", linewidth=2, color=eremaTrendColor, transp=0) eremaCyclePlot = plot(eremaCycle, title="Cycle", linewidth=2, color=eremaCycleColor, transp=0) fillColor = eremaTrend >= 0 and eremaCycle >= 0 ? #0ebb23 : eremaTrend < 0 and eremaCycle < 0 ? red : color(white, 100) fill(eremaTrendPlot, eremaCyclePlot, color=fillColor, transp=80) hline(0, title="Zero Level", linestyle=dotted, color=#989898)```

Gary Antonacci states that: "Zakamulin compared absolute momentum to 3 different moving average methods applied to 155 years of stock market data. He found that absolute momentum performed best and was one of only two methods that beat buy and hold with statistical significance. The other was a reverse exponential moving average."

So, it might be worth giving it a try. I'm rather new to Python and not able to adapt the code yet. But feel free to give it a try, and if no one comes up with it during the upcoming weeks, I will post my own interptretation right here.

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.

If you explain what it does and how it works in english i may be able to ham-jam something together. Just reading through your code - not sure what the variable Alpha represents.

2

Well, here you go. Another EREMA script but its A TS script.

```Function: _ReverseEMA { Adapted from Reverse EMA Indicator (C) 2017 John F. Ehlers TASC Sep 2017 } Inputs: AA( numericsimple ) ; Vars: CC( 0 ),EMA( 0 ),RE1( 0 ),RE2( 0 ), RE3( 0 ),RE4( 0 ),RE5( 0 ),RE6( 0 ), RE7( 0 ),RE8( 0 ),Wave( 0 ) ; //Classic EMA CC = 1 - AA ; EMA = AA * Close + CC * EMA[1] ; //Compute Reverse EMA RE1 = CC * EMA + EMA[1] ; RE2 = Power( CC, 2 ) * RE1 + RE1[1] ; RE3 = Power( CC, 4 ) * RE2 + RE2[1] ; RE4 = Power( CC, 8 ) * RE3 + RE3[1] ; RE5 = Power( CC, 16 ) * RE4 + RE4[1] ; RE6 = Power( CC, 32 ) * RE5 + RE5[1] ; RE7 = Power( CC, 64 ) * RE6 + RE6[1] ; RE8 = Power( CC, 128 ) * RE7 + RE7[1] ; //Indicator as difference Wave = EMA - AA * RE8 ; _ReverseEMA = Wave ;```

0

From the original paper:

`alpha = 2 / (Length + 1).`https://www.mesasoftware.com/papers/ZeroLag.pdf

0

Some more bits of code

```#Indicator 'frEMA #param "alpha", .1,.1, 1 ' use this to change period #param "PlotBars", 260,0,512 Dim a, b, fr, emaFR as Single Dim r1, r2, r3, r4, r5, r6, r7, r8 as Single Dim warmUp as integer Dim BgnPlot as integer if Bar = 0 then warmup = 99 if Plotbars = 0 or PlotBars>(SymbolData.Numrec-1-2*warmup) then BgnPlot = 2*warmup else BgnPlot = Symboldata.numRec-1-PlotBars end if b = 1-alpha elseif bar>20 and bar <= BgnPlot-warmup then fr = alpha*Close + b*fr[1] elseif bar>BgnPlot-warmUp then 'Forward EMA fr = alpha*Close + b*fr[1] 'means ema(19)? 'fr = ema(19) gives different value 'I think EMA in tradestation code is just a variable 'Truncated infinite series for Reverse EMA r1 = b^(2^0)*fr + fr[1] r2 = b^(2^1)*r1 + r1[1] r3 = b^(2^2)*r2 + r2[1] r4 = b^(2^3)*r3 + r3[1] r5 = b^(2^4)*r4 + r4[1] r6 = b^(2^5)*r5 + r5[1] r7 = b^(2^6)*r6 + r6[1] r8 = b^(2^7)*r7 + r7[1] 'Calculate Forward Reverse EMA oscillator ' alpha is specific to a period ' diff periods require different alphas emaFR = fr - alpha*r8 if bar>BgnPlot then if emaFR>emaFR[1] then Plot("FRema", emaFR, green) else Plot("FRema", emaFR, red) end if Plot("zline", 0, black) End If End If Return emaFR ```

0

Hi Ivan Baev ,

FYI: if there is a clear reference (website, paper, etc), we can open GitHub issues in Lean repo to implement any indicator. We need a third-party calculation for validation too.

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.

0

The material on this website is provided for informational purposes only and does not constitute an offer to sell, a solicitation to buy, or a recommendation or endorsement for any security or strategy, nor does it constitute an offer to provide investment advisory services by QuantConnect. In addition, the material offers no opinion with respect to the suitability of any security or specific investment. QuantConnect makes no guarantees as to the accuracy or completeness of the views expressed in the website. The views are subject to change, and may have become unreliable for various reasons, including changes in market conditions or economic circumstances. All investments involve risk, including loss of principal. You should consult with an investment professional before making any investment decisions.