Reverse Exponential Moving Average

I am just wondering if someone gives some suggestions regarding the below problem
I wanted the recursive equation for Reverse Exponential
moving average, Let me explain this in detail

1.Normal exponential moving average we define like below


a=2/(N+1),N=no of days ,0<a<1
That means if I want a 20-day exponential moving average
then a=0.95, and it works like we take a 20-day window and
give more weights to newer values and lesser weights to
older values and these weights are assigned exponentially.

  1. I wanted another way round, that is more weight to older samples and lesser weights to newer samples and these weights should be assigned exponentially.
    in short, I want a reverse exponential moving average recursive equation
period = 15;
x = AMA(C, 1 - 2 / (period + 1));

-> Result being (almost) equal to input independent from period.

NOTE: EMA would be this one

period = 15;
x = AMA(C, 2 / (period + 1));
1 Like

Thanks for your reply
I think if I provide more weights to previous values of the closing price and fewer weights to the current closing price then how can the Result being (almost) equal to the input?? it should be more inclined to the previous closing prices, not the current closing price. I think inherent recursive equation will be different than normal EMA

That one is equivalent to this one

period = 15;
a = 2/(period+1);
for ( i = 1, x = 0; i < BarCount; i++ )
    x[ i ] = a * C[ i ] + (1 - a) * x[ i - 1 ];

And this one

is equivalent to this one

period = 15;
a = 2/(period+1);
for ( i = 1, x = 0; i < BarCount; i++ )
    x[ i ] = (1 - a) * C[ i ] + a * x[ i - 1 ];

Latter one is what you were looking for? Yes/No?

All these recursive equations are equivalent to Exponential moving average, Let me explain

  1. In the above equations whether a = 2/(period+1) or 1 - 2 / (period + 1), It always represent the exponential moving average as the inherent recursive equation is for exponential moving average as in both cases 0<a<1
  2. I wanted recursive equation for reverse exponential moving average, Inherent equation would be different,
    I appreciate that you replied and provided a detailed explanation .I am working on this and I will reply when I got the explanation
period = 15;
rev_arr = Reverse(C);
x = Reverse(EMA(rev_arr,period));
Plot( C, "Price", colorDefault, styleBar );
Plot( x, "Reverse EMA", colorOrange, styleline );
Plot( EMA(C,period), "EMA", colorRed, styleline );
1 Like

thanks, I am working on this, you have already given me the clue.

@prabhas - you are mistaken if you think that EMA works with any kind of "window"
and considers only limited number of bars.

Exponential moving average is INFINITE impulse response filter, it is recursive and it takes ALL bars into calculation and normally the influence of past data is diminished as you go. What you are trying to do is not really good idea because reversing the calculation is leading to absurd solution where the more bars you add to calculation the influence of current (most recent) bar goes asymptotically to zero. After few hundreds of bars, you will essentially get flat line, as any significant weight is only given only to past data.


First of all thanks for creating such a wonderful software AMIBROKER, Also it's my honor to get a reply from the owner of amibroker.

Yes you are right Exponential moving average is an INFINITE impulse response filter, it is recursive and it takes ALL bars into the calculation, and normally the influence of past data is diminished as you go. we can represent this with a recursive equation


and it gives correct value without introducing the error when initializing the first estimate

Note that there is no "accepted" value that should be chosen for a, But what we do in N-day exponential moving average is that we Approximating the EMA with a limited number of terms. A commonly used value for a is 2/(N+1), N=no of days This is because the weights of an SMA and EMA have the same "center of mass" For sufficiently large N, the first N datum points in an EMA represent about 86% of the total weight in the calculation when

a=2/(N+1)and if I am Approximating the EMA with a limited number of terms then why can we can not find the reverse EMA whose equation would look like below, REMA(reverse EMA)

Denote by Pt the period t closing price of a stock market index. Furthermore, denote by REMAt(k) the general weighted moving average at period-end t with k lagged prices.

When λ < 1, the exponentially weighted moving average assigns greater weights to the prices.

Contrary to the regular exponential moving average that gives greater weights to the most recent prices, the reverse exponential moving average assigns greater weights to the oldest prices and decreases the importance of the most recent prices. I am researching this and I will get back to you on this.
research paper link

What you are asking is not really exponential moving average anymore or even Infinite Impulse Response (IIR) filter anymore. The terms in both nominator and denominator are FINITE, therefore it is not IIR filter but Finite Impulse Response filter (FIR). FIR filter with user-definable coefficients is available natively:

All you need to to is to supply coefficients you want.

Something like that:

function REMA( array, periods )
   Coefficients = 0;

   factor = 2 / (periods + 1 );

   for( i = 0; i < periods && i < BarCount; i++ )
      Coefficients[ i ] = factor * ( ( 1 - factor ) ^ ( i ) );
      printf("Coeff %g %g\n", i, Coefficients[ i ] );

   return FIR( array, Coefficients, periods );

Plot( REMA( Close, 40 ), "REMA", colorRed );
Plot( EMA( Close, 40 ), "EMA", colorBlue );

Plot( Close, "Price", colorDefault, styleBar );

Thanks, This is what I was looking for, This was my mistake that I have not looked at amibroker functions completely, I really thankful to you for the quick reply, I was really struggling with this for quite a long time.

it would be very helpful if you can provide the raw AFL code for the FIR filter(so that I can modify it according to my need)

Look in the manual (link was already provided), the "raw" code is already in the guide.

1 Like

thanks for your support @fxshrat @Tomasz pray: :relaxed:

1 Like

This topic was automatically closed 100 days after the last reply. New replies are no longer allowed.