Part of the Indicator Math series. We start with moving averages because several other indicators in this series, including MACD, RSI, ATR and Bollinger Bands, rely on one.
Three lines that look the same and aren’t
Put a 20-period SMA, a 20-period EMA and a 20-period WMA on the same chart and they look like three versions of one line. Most traders pick one and never think about it again.
Here’s the plain-English question every moving average answers: what has the typical price been recently? The only thing that separates the three is how they define “recently.” Each one is a recipe for how much weight to give each past bar. Once you see the weights, you can predict how each line behaves at a turn and how far behind price it runs.
The formulas
The default lengths you see are charting conventions, not mathematical requirements. StockCharts ChartSchool describes the 200-day as perhaps the most popular long-term average and the 50-day as the popular medium-term one, with 5 to 20 days for short-term trading. TradingView’s built-in EMA indicator defaults to a length of 9 on the close.
Simple moving average (SMA)
SMA = (sum of the last N closes) ÷ N
N is the length, the number of bars in the window. Every bar inside the window counts equally, and a bar that falls out of the window counts for nothing. A 20-bar SMA gives each of the last 20 closes exactly 5% of the vote.
Weighted moving average (WMA)
WMA = (N × newest close + (N − 1) × next newest
+ … + 1 × oldest close) ÷ (N × (N + 1) ÷ 2)
The newest bar gets weight N, the one before it N − 1, down to 1 for the oldest bar in the window. The divider is just the sum of those weights (for N = 5 that is 5 + 4 + 3 + 2 + 1 = 15), as shown in the standard definition and in TradingView’s moving average help page. Like the SMA, it has a hard window: bar N + 1 back counts for zero.
Exponential moving average (EMA)
EMA today = (Close today × k) + (EMA yesterday × (1 − k)) k = 2 ÷ (N + 1)
k is the smoothing constant: the share of today’s value that comes from today’s close. For a 10-period EMA, k = 2 ÷ 11 = 0.1818, and for a 20-period EMA, k = 2 ÷ 21 = 0.0952, the same figures StockCharts uses. The other 1 − k comes from yesterday’s EMA, which itself came partly from the day before, and so on back to the first bar on your chart.
That recursion raises a practical question: what is “EMA yesterday” on the very first bar? This is called seeding. StockCharts seeds with a simple average of the first N closes. Other software starts from the first close itself. The seed’s influence shrinks every bar but never quite reaches zero, which is why StockCharts says you need “far more than 10 days of data” for an accurate 10-day EMA and calculates back at least 250 periods.
A worked example by hand
Twelve made-up daily closes for a stock in a gentle uptrend, with a 5-period SMA, EMA and WMA. For N = 5, the EMA’s k = 2 ÷ 6 = 1/3. The EMA is seeded on day 5 with the SMA of days 1 to 5. Values are rounded to two decimals for display; a spreadsheet should carry full precision forward.
| Day | Close | SMA(5) | EMA(5) | WMA(5) |
|---|---|---|---|---|
| 1 | 100.00 | n/a | n/a | n/a |
| 2 | 101.20 | n/a | n/a | n/a |
| 3 | 100.80 | n/a | n/a | n/a |
| 4 | 102.10 | n/a | n/a | n/a |
| 5 | 103.00 | 101.42 | 101.42 | 101.88 |
| 6 | 102.40 | 101.90 | 101.75 | 102.21 |
| 7 | 103.60 | 102.38 | 102.36 | 102.77 |
| 8 | 104.50 | 103.12 | 103.08 | 103.48 |
| 9 | 103.90 | 103.48 | 103.35 | 103.74 |
| 10 | 105.20 | 103.92 | 103.97 | 104.31 |
| 11 | 106.00 | 104.64 | 104.64 | 105.01 |
| 12 | 104.80 | 104.88 | 104.70 | 105.06 |
Here is day 12 worked out. The last five closes are 104.50, 103.90, 105.20, 106.00 and 104.80.
SMA = (104.50 + 103.90 + 105.20 + 106.00 + 104.80) ÷ 5
= 524.40 ÷ 5 = 104.88
WMA = (1 × 104.50 + 2 × 103.90 + 3 × 105.20
+ 4 × 106.00 + 5 × 104.80) ÷ 15
= (104.50 + 207.80 + 315.60 + 424.00 + 524.00) ÷ 15
= 1,575.90 ÷ 15 = 105.06
EMA day 6 = 102.40 × 1/3 + 101.42 × 2/3 = 101.7467
…carry forward the same way to day 11 = 104.6448
EMA day 12 = 104.80 × 1/3 + 104.6448 × 2/3 = 104.6966
Notice day 12. Price dipped from 106.00 to 104.80. The WMA, which leans hardest on recent bars, is still the highest of the three, because the strong days 10 and 11 carry weights of 3 and 4. The SMA ticked up because the close that left the window (103.60 from day 7) was lower than the close it added (104.80). The EMA barely moved. Same data, three answers, all correct.
What it actually measures
A moving average measures a weighted average of past prices. That is all. The cleanest way to compare the three is to look at the weights directly. For a mature 5-period average (long after the EMA’s seed has faded):
| Bar | SMA(5) | WMA(5) | EMA(5) |
|---|---|---|---|
| Newest | 20.0% | 33.3% | 33.3% |
| 1 bar back | 20.0% | 26.7% | 22.2% |
| 2 bars back | 20.0% | 20.0% | 14.8% |
| 3 bars back | 20.0% | 13.3% | 9.9% |
| 4 bars back | 20.0% | 6.7% | 6.6% |
| Everything older | 0% | 0% | 13.2% |
That last row is the point of the EMA. Each bar’s weight is the previous bar’s weight times (1 − k), so it shrinks by a constant fraction and never hits zero. For a mature 5-period EMA, the last five bars carry about 87% of the weight; for common longer lengths, the last N bars still get only about 86%. The rest is spread across all older history. This is why the EMA never fully forgets old data. The SMA and WMA forget completely, and abruptly, the moment a bar leaves the window.
Lag is a number, not a feeling
“Moving averages lag” is usually said as a vague warning. You can measure it. Take the weighted average age of the bars inside the average, counting the newest bar as age 0:
SMA average age = (N − 1) ÷ 2 WMA average age = (N − 1) ÷ 3 EMA average age = (1 − k) ÷ k = (N − 1) ÷ 2 (steady state, once the seed has faded)
For a 20-period line, the SMA and EMA are each centered about 9.5 bars in the past, and the WMA about 6.3 bars. So the 2 ÷ (N + 1) formula is not arbitrary: it is the k that gives an N-period EMA the same average age as an N-period SMA. The EMA doesn’t have less lag on average. It distributes its weight differently: heavier on the newest bars, plus a long tail.
That difference shows up when price jumps. Imagine a market sitting at 100 that steps to 110 and stays there. A 20-period WMA covers half the move in 6 bars, the EMA in 7, the SMA in 10. By bar 20 the SMA and WMA are fully at 110. The EMA is at 108.65 and still only at 109.50 after 30 bars, because that tail of old 100s is still in the vote. Faster at the start, slower to finish.
The chart below shows a 20-day SMA, EMA and WMA on SPY’s daily closes from January to June 2026. After the late-March low, the EMA and WMA turn up within a day of each other, and the SMA follows a few sessions later.

What a moving average does not measure: it does not predict anything, it does not know where support is, and it carries no information that isn’t already in the closes. A “bounce off the 20 EMA” is price returning to its own recent average. That can be useful context, but the line itself has no memory of orders, volume or intent.
How traders use it
These are rules you can test, not signals.
- Trend filter. Only take long setups when price is above a rising 50- or 200-day average, and only shorts when below a falling one. Condition: you need a separate entry setup; the filter decides direction only. It pairs naturally with the idea in Combining Setups With a Filter.
- Pullback entry zone. In an established trend, wait for price to pull back to a 20-period EMA, then enter when a bar closes back in the trend direction. Condition: the trend must already be defined by something else (higher highs, a rising longer average). See Pullback-to-Value Entries for the full setup.
- Regime marker. A crossover of a shorter average above a longer one, the 50/200 “golden cross” StockCharts describes, used to label the market as trending up rather than to time an entry. Condition: a long holding horizon, since these crosses arrive late by design.
- Trailing exit. Hold a trend trade until a bar closes on the other side of a 10- or 20-period EMA. Condition: decide the length before entry and write it into your exit rules; a shorter length tends to exit sooner, but gets shaken out more often.
- Intraday bias on ES or MES. On a 5-minute chart, use the slope of a 20-period EMA as the session bias: longs only while it rises. Condition: know what history your EMA contains. On a chart showing the full overnight session, the opening EMA is built partly from overnight bars; on a regular-hours-only chart it carries yesterday afternoon. The futures trading hours post covers why those sessions trade differently.
Where it fails
Sideways markets. In a range, price crosses its own average constantly, and crossover rules can whipsaw, especially without a separate filter. The average is doing its job. It just has little to say when there is no trend.
The lag trade-off can’t be escaped. A shorter length or a WMA reacts faster but flips on noise. A longer length is smoother but late. No setting is both smooth and early.
Parameter sensitivity. If your results change a lot between a 20 and a 21 EMA, treat it as a warning sign and check out of sample. Test neighboring lengths as part of your backtesting.
The live bar moves. Until a bar closes, its moving average value moves with every tick. A cross you saw mid-bar can disappear by the close. A higher-timeframe average displayed on a lower-timeframe chart has the same problem for the whole higher-timeframe bar. Decide whether your rules act on closed bars only.
Different history, different EMA. Because of seeding and the infinite tail, an EMA on a chart with 300 bars loaded can differ from one with 5,000 bars loaded. For long lengths on short histories, that difference is not cosmetic.
Takeaway: A moving average is a weighted average of past closes, and the SMA, EMA and WMA differ only in their weights. The SMA weighs its window equally, the WMA leans linearly toward the newest bar, and the EMA shrinks every older bar by a constant fraction without ever reaching zero. Lag is measurable: about (N − 1) ÷ 2 bars for an SMA or EMA. Use averages to describe trend and define rules you can test, and expect them to fail in ranges.
Next up: VWAP: The Math Behind the Volume-Weighted Average Price
One thought on “Moving Averages: The Math Behind the SMA, EMA, and WMA”