Moving Averages


This post was contributed by a guest author, and does not necessarily reflect the views of Richard or MovetheMarkets.com


If I was as smart as Prospectus or Richard, I may or may not participate in this ET thread. I found it interesting, and hopefully, one of these rocket scientist or level 3 programmers, can glean something from it to make us all rich.

To construct a 20 day exponential moving average you must first construct a 20 day simple moving average. This simple moving average is the starting point for the exponential moving average. Assume that the simple moving average value for day 20 is 42; the simple moving average value for day 21 is 43; and the simple moving average value for day 21 is 44. We then subtract the day 20 moving average value from day 21 simple moving average value and get a difference of 1.00. This value (1.00) is multiplied by an exponent. In this case, the exponent is .1. We then add .1 to the simple moving average value of day 20. The exponential moving average value of day 20 now becomes 42.100. And this goes on indefinitely. To calculate the exponent, divide 2 by the time period. In our case, we divided 2 by 20 to arrive at .1.

I think a psychologist would have a field day, observing some of the ridiculous comments here from people who are probably compensating for their poor performance in the stock market by trying to impress their fellow traders by bluffing that they have some scientific understanding of what they do. Unless you have a math/scientific background, please do not comment on this thread.

A moving average of length n of say a time series (like prices of a stock etc.) is computed as xbar = (Sum of n consecutive elements)/n. That means you take only into account n elements, no more, no less. The elements are all equally weighted with weight 1, it is possible to give each element a different weight.

The purpose of a moving average is to smooth a time series, ie. to replace each member by a moving average of its neighbours. Say you take a length of 5 for the ma, then an element xn is replaced by ((xn-2) + (xn-1) + xn + (xn+1) + (xn+2))/5. That is you need to know members xn+1 and xn+2 before you may replace xn by its ma. And that is the lag of the ma. Smoothness is achieved in two ways: by the choice of length and by the choice of the weights for each x. Giving far out members, like the xn+2 in the above example, less weigth, say you multiply them by 0.5 only instead of 1, will make the ma more responsive, using a longer length or a smaller multiplier for the recent members will make it smoother.

The use of a ma in Technical analysis is less to smooth a time series, but to implement a trading method, you do not replace a member xn by its ma in the way described above, but you replace xn by ((xn-4)+(xn-3)+(xn-2)+(xn-1)+xn)/5. That is you shift the ma to the right. A TA program, like Metastock, does have an option to left-shift the ma, that is to plot it correctly. Do this and you will graphically understand lag.

The exponential ma is computed as Close*percentage + (previous EMA) * (1-percentage), percentage ranging from 0.01 to 1. Starting value is Close (or whatever value you use). That is an EMA always uses *all* previous data, weighted, while a simple ma only uses data as described by its length. So there really is no equivalence between percentage used in an EMA and length (or number of periods) used in a SMA.

That said, for practical purposes the equivalence may be computed as already quoted in previous posts. Prices are not quoted infinitesimal, that is you do not pay 78.234598122…. $ for a stock but 78.23 $ so prices are “quantized” and that is the reason the formula makes sense. The farther you get away from a certain value the less its contribution to the current value of an EMA will be till it drops below the threshold.

An SMA is a Fininte Impulse Response (FIR) filter. The lag, or delay, of any end-to-end symmetric (or anti-symmetric) FIR is approximately one half the filter length. In the case of a time series SMA, the lag of an SMA is exactly (N-1)/2. So a 7-bar SMA has a lag of exactly 3 bars. This lag is referred to as the “group delay” in engineering terms. [Group delay is defined as the rate of change of phase with respect to angular frequency.]

Regarding the 2/(N+1) for the period in the alpha calculation of an EMA, while I don’t know the origin of the formula, the reason the MA is called “exponential” (to answer one of your original questions) is the way an EMA’s transfer response decays is in amplitude over N bars. [e.g. The most recent value of the time series is weighted by alpha, the next most recent value is weighted by alpha*(1-alpha), the next value by alpha*(1-alpha)^2 .... the Nth value is weighted by alpha*(1-alpha)^N.]

Note that for any given period N, the weight of alpha*(1-alpha)^M where M>N, the weighting affect on the MA approaches zero as M increases, hence for practical purposes, the formula of alpha=2/(N+1) generally describes the affect of the EMA weight N periods back.

The concept of “period” in an EMA is approximate, unlike an SMA or WMA where it is exact. MA’s get more interesting when you starting looking at Digital Signal Processing, when you start looking at phase changes. SMA’s and WMA’s have linear phase lag defined by the fixed period, but EMA’s, due to the recursive nature of its calculation, has a nonlinear phase lag.


This post was contributed by a guest author, and does not necessarily reflect the views of Richard or MovetheMarkets.com


5 Responses

  1. LP Says:

    No Comment

  2. Prospectus Says:

    They are focusing on all the wrong things, IMO.

  3. jay Says:

    This guy, from the same thread, has it right:

    “The beauty of this forum is that I can selectively steer clear of threads which don’t interest me - the thread title being the main indicator. What did you expect to find in a thread entitled “Exponential Moving Average”? Be warned that once we have exhausted the simple, weighted and exponential moving averages, we intend to focus our attention on the properties of the Wilder Moving Average, Least Square Moving Average, Adaptive Moving Average, Endpoint Moving Average, Triangular Moving Average, Sine Weighted Moving Average, Modified Moving Average, MESA Adaptive Moving Average, Elastic Volume Weighted Moving Average, Indicator Adjusted Average and Indicator Weighted Average, not necessarily in that order.”

  4. Mr. White Folks Says:

    it was actually something i saw about half cycle moving averages that had me do a search on sine weighted moving averages which led to this thread

    i’m just not smart enough to understand most of it…i haven’t heard someone mention “N” that much since the guys on the radio realized they couldn’t say the whole word!

  5. Mr. White Folks Says:

    pro: what r the right things?

Leave a Comment

Please note: Comment moderation is enabled and may delay your comment. There is no need to resubmit your comment.