How does a simple moving average actually work?
The simple moving average is the oldest indicator in common use and still the most informative one per unit of complexity. Its formula fits on one line:
SMA(n) = (sum of the last n closes) ÷ n
Each new bar, the newest close enters the window and the oldest one drops out. That "rolling" behaviour is the entire mechanism — and it produces one effect that surprises almost everybody.
A worked example, including the surprise
Five closes: 100, 102, 101, 105, 107. Sum 515, so SMA(5) = 103.
Tomorrow closes at 104 — a fall from 107. The 100 leaves the window, the 104 enters: 515 − 100 + 104 = 519, so the new SMA(5) = 103.8.
The price went down and the average went up. Nothing is broken. A moving average moves whenever the entering close differs from the leaving one, so a stale bar rolling off the back can shift the line as much as today's action. Traders call it the drop-off effect, and it is the first thing to check when an average moves "for no reason".
What the line is for
Two readings, both descriptive:
- Slope — which way the middle of the recent price cloud is moving. It answers "which way has this been leaning?" without you having to squint at candles.
- Distance — how far today's price sits from its own recent average. A price far above its 50-day average has moved quickly relative to the last quarter's typical level. That is a statement about stretch, not about what comes next.
Choosing n
Common windows map onto calendar intuitions: 20 ≈ a trading month, 50 ≈ ten trading weeks, 200 ≈ ten months. Note that 50 is not a quarter — a quarter is nearer 63 trading days — which is worth knowing before you repeat the shorthand. There is nothing sacred in them (see the parameter lesson) — but because so many participants use them, the popular ones describe what a lot of people are looking at, which is itself a fact about the market.
Honest limits
- It is an average of history, not a floor or a ceiling. The next unit lesson takes that claim apart properly.
- It doesn't exist for the first n − 1 bars, so a 200-day average tells you nothing about a stock that listed six months ago.
- It weights a close from 50 sessions ago exactly as heavily as yesterday's. That specific complaint is what the exponential moving average answers — next lesson.
In the data
The same number turns up under another name. The chart below draws Apple's 20-day simple average and its 20-day Bollinger bands as separate lines, and the average lies exactly on the middle band all the way along: the middle band is the 20-day average.
Both are computed on the adjusted close, as the legend says, so every historical value on them drifts slightly lower each time Apple goes ex-dividend.
Try it now
- On the schematic above, compute both marked windows by hand and confirm the drop-off for yourself: the close falls, the average rises, and the bar responsible left the back of the window rather than arriving at the front.
- Now prove the formula against numbers you did not choose. Apple's last five closes are the first table below, and they are the right-hand end of the month on the chart; average them by hand, and compare with the published 5-day average in the second table. If the two differ, check which closes you averaged: the published average uses closes adjusted for dividends, and the two series part company for every session before an ex-dividend date.
- Look at the 20-day average over the last quarter (the right-hand three months of the year below) and describe the slope in one neutral sentence — "the 20-day average has been rising for six weeks." Description only; no forecast attached.