Moving Averages
A moving average smooths price by averaging the last N closes and updating that average every bar. It turns a noisy chart into a single line that shows the direction and pace of the trend. The price you pay for that smoothness is lag: an average always reports what has already happened, so crossovers and turns arrive after the move has started.

Computing a 5-period SMA and EMA (hypothetical closes). Five closes: 20, 21, 22, 21, 23.
- SMA(5) = (20 + 21 + 22 + 21 + 23) ÷ 5 = 107 ÷ 5 = 21.40.
The next close is 24.
- New SMA(5) drops the oldest close (20) and adds 24: (21 + 22 + 21 + 23 + 24) ÷ 5 = 111 ÷ 5 = 22.20.
- EMA(5): multiplier k = 2 ÷ (5 + 1) = 0.3333. Starting from 21.40 (it is common to seed the first EMA with the SMA): EMA = previous EMA + k × (close − previous EMA) = 21.40 + 0.3333 × (24 − 21.40) = 21.40 + 0.867 = 22.27.
The EMA moved slightly further toward the new close than the SMA did (22.27 vs 22.20), because a third of its weight sits on the latest bar. On a longer series, and especially after a sharp move, the gap between the two is much larger.
Simple moving average (SMA)
The SMA adds up the last N closes and divides by N. Every close in the window has equal weight, and when a close drops out of the window it vanishes completely. That has a side effect: a big move from N bars ago can make the SMA jump today simply because that old bar left the window, not because anything happened today.
On average, the data in an SMA is (N − 1) ÷ 2 bars old. A 20-day SMA is centred about 9.5 days in the past; a 200-day SMA about 99.5 days. That is the lag in plain numbers.
Exponential moving average (EMA)
The EMA applies the formula from the demo every bar:
- k = 2 ÷ (N + 1)
- EMA today = EMA yesterday + k × (close today − EMA yesterday)
The latest close gets weight k, and older closes fade gradually instead of falling off a cliff. That makes the EMA turn sooner after a change in direction and removes the "drop-off" jump of the SMA.
- 12 — Used in MACD's fast line.
- 26 — Used in MACD's slow line.
Exact arithmetic: k = 2 ÷ (N + 1). A 9-period EMA puts 20% of its weight on the newest bar; a 200-period EMA about 1%.
Because an EMA depends on every previous value, two platforms that started their calculation at different points can show slightly different EMA values for the same bar. The difference shrinks as more data is included.
Choosing a period
There is no correct period, only conventions that many traders watch:
Pick periods that match your holding time and keep them fixed. Constantly changing the period until the average "fits" the chart produces averages that describe the past perfectly and help with nothing.
Four ways traders use moving averages
- Trend filter. Only take longs when price is above a rising 50- or 200-day average, only shorts when below a falling one. This is the most robust use because it requires no precise timing.
- Dynamic support and resistance. In a steady trend, pullbacks often stall near a short or medium average. Treat it as a zone, like any other level.
- Crossovers. A faster average crossing a slower one (for example 9 over 21, or 50 over 200) marks a change in the short-term trend relative to the longer one.
- Distance from the average. When price stretches far above its average, the move may be extended; some mean-reversion traders measure that distance in percentages or standard deviations.
Golden cross and death cross
The golden cross is the 50-day moving average crossing above the 200-day; the death cross is the reverse. Because both averages are slow, the cross usually happens well after the price turn. They are better read as statements about the trend regime than as entry signals. Crossover strategies also suffer in sideways markets, where the averages tangle and cross repeatedly with no follow-through.
Other variants
- Weighted moving average (WMA) — weights decline linearly (N, N−1, …, 1).
- Hull, Kaufman adaptive and similar averages — designed to reduce lag or adapt to volatility. They are refinements, not cures: every average still trades off smoothness against delay.
A trend-filter plan, worked
A stock trades at 86.00. Its 200-day SMA is 78.00 and rising; its 20-day EMA is 84.50. The long-term regime is up, so the trader only looks for longs.
Price pulls back over four days to 84.80, near the 20-day EMA, and prints a higher low above the previous swing low at 83.20. Plan:
- Entry: 85.00 as price turns back up.
- Stop: 83.00, below the swing low — not below the average itself, because the average moves every day while the swing low is a fixed price.
- Risk: 2.00.
- Target: the recent high at 90.00, a reward of 5.00, or 2.5R.
If price closes below the 200-day SMA at some point, the regime filter switches off long setups entirely, regardless of how attractive any individual pullback looks. The average does not tell the trader when to buy; it tells them which side of the market they are allowed to trade.
Common mistakes
- Buying every touch of the average without checking that the trend is intact.
- Treating crossovers as precise timing signals when they are inherently late.
- Optimising the period on past data until it fits perfectly.
- Using averages in a range, where they whipsaw.
- Forgetting that SMAs can move because old data dropped out.
1. Closes: 10, 12, 11, 13, 14. What is the 5-period SMA?
2. What is the multiplier for a 19-period EMA?
3. Previous EMA is 50.00, k = 0.20, and today's close is 55.00. What is today's EMA?
4. Why does a golden cross usually happen well after the market's turn?