π― In 30 seconds: A moving average is the average closing price over the last N days, recalculated every day. It smooths out noise so the trend is easier to see. A simple moving average (SMA) weights every day equally; an exponential moving average (EMA) weights recent days more, so it reacts faster. Traders use the 20, 50 and 200-day averages as trend filters and watch crossovers like the golden cross. Every average lags price, so signals always come late, and in sideways markets crossovers whipsaw.
What a moving average is
Daily prices jump around. A moving average (MA) takes the average of the last N closing prices and plots it as a line. Each day the oldest price drops off and the newest one is added, so the average "moves" along with the chart.
The result is a smoother line that shows direction more clearly than the raw price. The trade-off is lag: because it averages the past, the line always turns after price has already turned.
Simple moving average (SMA)
The SMA is the plain average:
SMA = (sum of the last N closes) / N
Every day in the window counts the same. A 20-day SMA gives the price from 20 days ago exactly as much weight as yesterday's price.
Exponential moving average (EMA)
The EMA gives more weight to recent prices. It uses a smoothing factor k = 2 / (N + 1):
EMA today = (Close today minus EMA yesterday) x k + EMA yesterday
For a 20-day EMA, k = 2 / 21 = 0.0952, so today's close moves the EMA about 9.5% of the way toward itself. Older prices never fully drop out; their weight just shrinks a little every day. To start the calculation, most software uses the SMA of the first N days as the first EMA value.
Worked calculation: a 5-day SMA and EMA
Hypothetical closes for a stock over seven days. We compute a 5-day SMA and 5-day EMA. For N = 5, k = 2 / 6 = 0.3333.
| Day | Close | 5-day SMA | 5-day EMA |
|---|---|---|---|
| 1 | $20.00 | ||
| 2 | $20.50 | ||
| 3 | $21.00 | ||
| 4 | $20.80 | ||
| 5 | $21.20 | $103.50 / 5 = $20.70 | $20.70 (seeded with the SMA) |
| 6 | $21.60 | $105.10 / 5 = $21.02 | ($21.60 minus $20.70) x 0.3333 + $20.70 = $21.00 |
| 7 | $22.00 | $106.60 / 5 = $21.32 | ($22.00 minus $21.00) x 0.3333 + $21.00 = $21.33 |
On day 6 the SMA drops the $20.00 from day 1 and adds $21.60. On day 7 it drops $20.50 and adds $22.00. The EMA only needs yesterday's EMA and today's close.
In this rising stretch, both averages sit below the latest close. That is normal in an uptrend: the average is made of older, lower prices.
Lag: the price of smoothness
An SMA is centered, on average, (N minus 1) / 2 days in the past. A 20-day SMA describes where price was about 9 to 10 days ago. A 200-day SMA describes where it was about 100 trading days ago, roughly five months.
The longer the average, the smoother the line and the later every signal. The EMA reduces the lag but does not remove it, and it is a bit jumpier as a result.
The 20, 50 and 200-day averages
There is nothing magic about these numbers. They are popular, and popularity is part of why they matter: many traders watch the same lines.
- 20-day (about one trading month): short-term trend. Swing traders often use it for pullback entries. See Swing trading.
- 50-day (about ten weeks): the intermediate trend. Strong stocks often pull back to it.
- 200-day (about 40 weeks, close to a year of trading days): the long-term trend. Financial news often reports whether an index is above or below its 200-day average.
On a weekly chart, a 10-week average is close to the 50-day and a 40-week average is close to the 200-day.
Four ways traders use moving averages
1. Trend filter. Only consider buying when price is above a rising 200-day average, and only consider shorting when it is below a falling one. This does not tell you when to trade, only which side to favor. It is the most common and arguably the most defensible use.
2. Slope. A rising average means the average price over the window is going up. A flat average means no trend; that is where most crossover signals fail.
3. Dynamic support and resistance. In an established uptrend, pullbacks often stall near the 20-day or 50-day average. Treat this as a zone, like any support level, not an exact price.
4. Crossovers. A signal when price crosses an average, or when a faster average crosses a slower one.
Golden cross and death cross
A golden cross is when the 50-day SMA crosses above the 200-day SMA. A death cross is when the 50-day crosses below the 200-day. The names are dramatic; the signals are slow.
Look at how late both crosses are in the figure. That is not a flaw in this example. It is how two lagging lines work. A crossover system gets in after the trend is underway and out after it has turned, and hopes the middle of the trend is big enough to pay for both.
In a sideways market, the 50-day and 200-day can cross back and forth several times in a few months. Each cross is a small loss plus costs. These are called whipsaws.
What the evidence says
Moving average rules are among the most tested ideas in technical analysis.
A well-known study tested simple moving average and trading-range rules on the Dow Jones index from 1897 to 1986. It found that days after buy signals had higher returns than days after sell signals, more than standard models of random prices could explain.
A follow-up study then checked nearly 8,000 rule variations to account for the fact that, over decades, people search through many rules and remember the winners. The best rule from 1897 to 1986 still looked real after that adjustment. But in the next ten years, 1987 to 1996, its performance was not statistically significant, and on S&P 500 futures no rule in the set showed significant outperformance.
Trend-following research on diversified baskets of futures is more favorable, and moving averages are a common way to define trend there. See Trend following. For single stocks, the honest summary is: moving averages are a good way to see and filter the trend, and a weak way to predict it. Costs, taxes and whipsaws eat into crossover systems, so test any rule before trusting it. Does technical analysis work? explains how.
Simple rules you can test
Here are three rules written precisely enough to test. They are teaching examples, not recommendations.
- Trend filter: hold an S&P 500 index fund only while the index closes above its 200-day SMA; otherwise hold cash. Check once a month to cut whipsaws.
- Crossover: buy when the 50-day SMA crosses above the 200-day; sell when it crosses below.
- Pullback: when price is above a rising 50-day SMA, buy the first close back above the 20-day EMA after a pullback that touched it; stop below the pullback low.
For each, write down the number of trades, win rate, average win, average loss, worst drawdown and total return compared with simply holding. The Trading journal chapter shows how to compute these.
Try it
- Run rule 2 in the strategy backtester on a broad index or a large, liquid stock over at least ten years. Then run it on a different ten years. Did the result hold?
- Change the averages to 40 and 150 days. If the result changes a lot, the original numbers were probably lucky.
- Count the whipsaws: crosses that reversed within 40 trading days.
- Finally, recompute the 5-day table above with your own made-up prices. Doing it once by hand makes every moving average line on every chart easier to read.
- How is an EMA different from an SMA? Answer: An SMA weights every day in the window equally. An EMA weights recent days more, so it reacts faster with less lag (but is a bit jumpier).
- What is a golden cross? Answer: When the 50-day SMA crosses above the 200-day SMA. A death cross is the 50-day crossing below.
- What is the smoothing factor k for a 20-day EMA? Answer: 0.0952 (2 / 21).
- Five closes are $20.00, $20.50, $21.00, $20.80 and $21.20. What is the 5-day SMA? Answer: $20.70 ($103.50 / 5).
Sources
- RePEc: Brock, Lakonishok and LeBaron, Simple Technical Trading Rules and the Stochastic Properties of Stock Returns (Journal of Finance, 1992)
- LSE Financial Markets Group: Sullivan, Timmermann and White, Data-Snooping, Technical Trading Rule Performance, and the Bootstrap
- Hurst, Ooi and Pedersen: A Century of Evidence on Trend-Following Investing (Journal of Portfolio Management, 2017)