How are the SMA and EMA calculated?

The SMA adds the last N closes and divides by N. Hypothetical, as in the drawing below: five daily closes of $20, $21, $22, $23 and $24 give a 5-day SMA of $22.00. On day 6 the stock closes at $28. The $20 close drops out of the window and the $28 enters: ($21 + $22 + $23 + $24 + $28) ÷ 5 = $23.60.

The EMA blends today’s close with yesterday’s EMA using a weight k = 2 ÷ (N + 1), which is 1/3 for 5 days: EMA = close × k + yesterday’s EMA × (1 − k). EMAs are usually started from an SMA, so say yesterday’s EMA was $22.00. Today: $28 × 1/3 + $22 × 2/3 = $24.00. The same jump moved the EMA $2.00 and the SMA $1.60.

One quirk of the SMA: it also moves when an old close leaves the window, so a big day from four weeks ago can shift a 20-day SMA today even if today is quiet. The EMA never drops a close; old ones just fade.

Turn your phone sideways to read the drawing. Tap to close.

A hand-drawn bar chart of six daily closes, $20, $21, $22, $23, $24 and $28 (D1 to D6), with the D1 bar greyed and crossed out (drops out) and a bracket over the last five closes. Two cards on the right: SMA = (21+22+23+24+28) ÷ 5 = 23.60 (+1.60), and EMA, with yesterday’s EMA at 22: k = 2 ÷ (5+1) = 1/3, 28 × 1/3 + 22 × 2/3 = 24.00 (+2.00).

SMA vs EMA: which one reacts faster?

The EMA, because the newest close carries the most weight. In the drawing below, both lines use 20 periods on the same prices. Price drifts lower, then jumps: the EMA turns up at once, while the SMA stays almost flat for several bars, because the closes leaving its window are still the higher ones from earlier in the decline.

Speed cuts both ways. The EMA shows a turn earlier and also reacts to more noise, so it flips more often in a sideways market; the SMA is steadier and later. Many short-term traders use EMAs such as the 9 and 20 intraday, and many investors watch the 50- and 200-day SMAs. Neither is better in general. The EMA trading strategy guide covers EMA tactics.

Turn your phone sideways to read the drawing. Tap to close.

A hand-drawn grey price line drifting lower, then jumping at a dashed vertical line (jump), with two 20-period averages computed from it: the orange EMA 20 turns up right after the jump (EMA turns up at once), while the blue SMA 20 stays almost flat for several bars before rising (SMA still flat).

What are the 9, 20, 50 and 200 moving averages used for?

No length is magic. The popular ones are conventions, and part of the reason price reacts near them is that many traders watch the same lines. The length counts bars, not days: a 20-period average covers 100 minutes on a 5-minute chart and about a month on a daily chart.

  • 9: a fast line for short-term momentum, mostly on intraday charts.
  • 20 (some use 21): the short-term trend and a common pullback line for day and swing traders.
  • 50-day: the medium-term trend on daily charts, widely followed by swing traders and growth investors.
  • 200-day: the long-term trend. Price above a rising 200-day is the classic sign of a long-term uptrend.

How to read the trend with a moving average: slope and price

Two things tell you most of what a moving average can: its slope and which side of it price is on. The drawing below shows the three cases. A rising average with price above it says uptrend; a falling one with price below it says downtrend. A flat average that price keeps crossing says range, and there the average has little to tell you.

With several averages, look at their order too. In a strong uptrend the shorter averages sit above the longer ones, for example the 20 above the 50 and the 50 above the 200, all rising. When they flatten and tangle, the trend has paused or ended.

Turn your phone sideways to read the drawing. Tap to close.

Three hand-drawn panels, each with an orange moving average and a black price line. Uptrend: price zigzags above a rising average (price above a rising MA). Range: price swings back and forth across a flat average (flat MA, price crisscrosses). Downtrend: price zigzags below a falling average (price below a falling MA).

Moving averages as dynamic support and resistance

In a trend, a rising average often acts as support that climbs with price, and a falling one as resistance that falls with it. The drawing at the top of this page shows pullbacks pausing twice at a rising 50-day SMA. Treat the line as a zone, as you would support and resistance: price often pokes through a little before turning, so wait for a close back in the trend’s direction.

Hypothetical: a stock in an uptrend pulls back to its 50-day SMA at $95, trades down to $94.60, then closes the next day at $97 with the average still rising. A trader buying at $97 might place the stop under the pullback low at $93.90, risking $3.10 a share, and size from that. If price instead closes well below the average and the average starts to flatten, the support has failed, and the 200-day is often the next line traders watch. The pullback trading strategy covers this setup in detail.

Lag, crossovers and VWAP: what moving averages cannot do

Every moving average lags, because it is built from past closes. The longer the length, the smoother the line and the later it turns. That lag is the price of filtering noise: an average confirms a trend after it has started, and it does not predict one.

A crossover, a faster average crossing a slower one, is the best-known signal built on them; the 50-day crossing above or below the 200-day is called a golden cross or a death cross. Crossovers lag even more and whipsaw in ranges; the moving average crossover guide covers them properly. Averages also sit inside other indicators: the middle line of the Bollinger Bands is a 20-period SMA, and the MACD is built from EMAs.

VWAP looks like a moving average but is not one. It weights each price by the volume traded there and restarts every session, instead of averaging the last N closes. Day traders use it as the day’s fair price; see the VWAP trading strategy.