An Error Correcting EMA

This post is about a new MA I recently implemented which is currently available for Sierra Chart and Ninja Trader.

Moving averages, in general have two attributes to them. One is smoothing. The other is a lag.

In a sense, there is a sort of tug of war between these two traits – the more smoothing we put in, the more lag we get. Lag is not always a bad thing btw. In a sense, we sometimes want the lag as it keeps us ambivalent to all the short term movements that price might make along its longer term course. On the other hand, too much ambivalence and we might fall asleep.

So MA’s always lag behind price. In simple terms, the lag is the amount of time it takes for the ma to catch up with price. This is most evident when a market makes a sharp turn. The amount of time it takes the ma to make that turn and the distance by which it follows price is the lag.

The “EC EMA” is short for “Error Correcting Exponential Moving Average”. It is an implementation I picked up from John Ehlers who published an article with ideas on an EMA that reduces the lag by constantly applying what he terms an “error correction”.

As its name implies, the “EC EMA” is based on an EMA. Best to think of it as a standard EMA with an “Error Correcting” functionality. You can see this in the two input parameters. “Period” and “Gain Limit”. Period is the lookback length. Gain is harder to explain and is best understood by playing around and seeing how the ma reacts to different values.

The EC EMA has the following properties:

  1. It is relatively smooth since it takes into account past prices (like an EMA)
  2. You can control the lag so that it stays closer to price but still retains smoothness

With No Error Correction

If you set the GainLimit to zero, you essentially get the EMA. In other words, no error correction. See the image below. Thought its a bit hard to see, there are actually two indicators on that chart. The blue dotted line is a regular EMA of length 20. The second line, the orange one, is the EC EMA with a length of 20 and Gain Limit of zero.


With Error Correction – Less Lag

Now lets see what happens when we put some error correction in place. The image below is the same two ma’s with the same length. Notice that the orange line now hugs price much closer but still retains some of that smoothness. It has the same length as the regular EMA, but makes corrections along the way. In this case I had set the GainLimit to 10. Like all indicators, you need to set parameters based on the context of its usage.