How do you calculate a simple moving average?
Add the last n prices and divide by n: SMA = (p1 + p2 + ... + pn) / n. Then move the window down one row and repeat. Each new price enters the average and the oldest one leaves it, which is what makes the average move.
A short example with the prices 10, 11, 12, 13 and 14 and a 3-period average:
| Row | Price | 3-period SMA | 3-period WMA | 3-period EMA (SMA seed) |
|---|---|---|---|---|
| 1 | 10 | not yet | not yet | not yet |
| 2 | 11 | not yet | not yet | not yet |
| 3 | 12 | 11.00 | 11.33 | 11.00 |
| 4 | 13 | 12.00 | 12.33 | 12.00 |
| 5 | 14 | 13.00 | 13.33 | 13.00 |
No average exists until n prices have been entered, so a 3-period average starts on row 3. The default inputs hold 20 prices from 100.00 to 112.00 with a 5-period window: the latest SMA is (108.50 + 110.10 + 109.60 + 111.30 + 112.00) / 5 = 110.30.
Exponential moving average formula: the 2 / (n + 1) smoothing
The EMA blends each new price with the previous EMA: EMA today = a x price today + (1 - a) x EMA yesterday, with the smoothing factor a = 2 / (n + 1). For a 5-period EMA, a = 2 / 6 = 0.3333, so the newest price carries a third of the weight; for 10 periods, a = 0.1818; for 20 periods, 0.0952.
The formula needs a starting value, and the calculator offers two:
- Seed with the SMA (the default here): the EMA starts on row n, equal to the simple average of the first n prices, and the formula runs from the next row.
- Seed with the first price: the EMA starts on row 1 at that price.
In the 10 to 14 example, the SMA seed gives 11 on row 3, then 0.5 x 13 + 0.5 x 11 = 12 and 0.5 x 14 + 0.5 x 12 = 13. Seeded with the first price instead, the EMA runs 10, 10.5, 11.25, 12.125 and 13.0625. On the default 20 prices the two seeds end at 110.4768 and 110.4775, a gap that only shows at the fourth decimal. If an EMA here does not match a chart to the last decimal, the seed and the number of prices before it are the first things to check.
Weighted moving average formula
A weighted moving average gives the newest price a weight of n, the one before it n - 1, and so on down to 1 for the oldest in the window, then divides by the sum of the weights, n(n + 1) / 2. WMA = (1 x oldest + 2 x next + ... + n x newest) / (n(n + 1) / 2).
For a 5-period WMA the weights are 1, 2, 3, 4 and 5 and they sum to 15. On the default prices the latest WMA is (1 x 108.50 + 2 x 110.10 + 3 x 109.60 + 4 x 111.30 + 5 x 112.00) / 15 = 1,662.70 / 15 = 110.85. Unlike the EMA, a WMA forgets a price completely once it leaves the window.
SMA vs EMA vs WMA: how far behind each one sits
A useful way to compare them is the average age of the prices inside each one, measured in rows behind the latest price:
- SMA: the weights are equal, so the average age is (n - 1) / 2. For n = 5 that is 2 rows.
- EMA: seeded with the SMA, as the default here, the average age is exactly (n - 1) / 2, the same as the SMA, however many prices follow the seed. That holds because a = 2 / (n + 1) is the smoothing that makes (1 - a) / a equal (n - 1) / 2. Seeded with the first price, it is a little lower, (n - 1) / 2 x (1 - (1 - a)^(N - 1)) over N prices: 1.9991 rows for n = 5 on the default 20 prices.
- WMA: the linear weights pull the average age down to (n - 1) / 3, or 1.33 rows for n = 5.
On the default prices, which mostly rise, that ordering shows up in the latest values:
| Period | SMA | EMA | WMA | Latest price |
|---|---|---|---|---|
| 5 | 110.30 | 110.48 | 110.85 | 112.00 |
| 10 | 108.80 | 108.90 | 109.77 | 112.00 |
The WMA sits closest to the latest price in both rows. With the SMA seed the EMA and SMA share the same average age, but the EMA puts more weight on the newest prices and some on every earlier one, so the two values still differ.
Worked examples on shares in pounds and euros
- A UK share in pounds, 4-period averages. Eight closes: £4.10, £4.15, £4.08, £4.20, £4.26, £4.31, £4.28 and £4.35. The latest SMA is (4.26 + 4.31 + 4.28 + 4.35) / 4 = £4.30, and the last close is 1.16% above it. The EMA, with a = 2 / 5 = 0.4 and seeded at £4.1325, the average of the first four closes, ends at £4.2915. The WMA is £4.312.
- A share in euros, falling, 3-period averages. Six closes: €52.00, €51.40, €50.80, €51.60, €50.20 and €49.60. The latest SMA is €50.4667, the EMA €50.225 and the WMA €50.1333. The last close is 1.72% below the SMA.
In the falling series the order flips: the WMA, which leans on the newest prices, is now the lowest of the three. Prices are typed as the chart quotes them and are never converted, so a share quoted in pence works the same way and the page has no currency selector.
How the period changes the average
A longer period puts more prices into the window, so each new price moves the average less. Change the default from 5 to 10 periods and the latest SMA falls from 110.30 to 108.80, further below the latest price of 112.00, because the 10-row window reaches back to closes of 105.80 and 106.40. The EMA smoothing falls from 0.3333 to 0.1818 and the EMA from 110.48 to 108.90.
The period also sets how many prices you need before any average appears: a 20-period average needs 20 rows. Long settings such as 50 and 200 periods need that many closes, so this page, which takes up to 60 rows, covers a 50-period average but not a 200-period one; a spreadsheet handles the longer series with the formulas below.
How to calculate a moving average in Excel or Google Sheets
Put the prices in B2 to B21, oldest at the top. For a 5-period average:
- SMA in C6: =AVERAGE(B2:B6), then fill down. C21 returns 110.3 on the default prices.
- WMA in D6: =SUMPRODUCT(B2:B6,{1;2;3;4;5})/15, then fill down. D21 returns about 110.85.
- EMA with the SMA seed: in E6 enter =C6, and in E7 enter =2/(5+1)*B7+(1-2/(5+1))*E6, then fill down from E7. E21 returns about 110.48.
For the first-price seed, enter =B2 in E2 and fill the E7 style formula down from E3. Keep the period in its own cell if you want to change it in one place; the WMA weights then need rebuilding for each period.
What moving averages can and cannot tell you
Every moving average is built only from prices that already exist, so it trails the latest price by design. It can summarize where prices have been on average; it cannot say where the next price will be, and a cross of price and average says nothing certain either. This page reports the arithmetic on the rows you entered.
- Rows in the wrong order. The newest price belongs at the bottom. Reversed rows give a different answer.
- Gaps and zeros. A zero is not a price, so an empty or zero row is skipped and the note under the result says how many were skipped. The average then runs straight across the gap.
- Different seeds. An EMA seeded differently, or started from fewer prices, will not match to the last decimal.
- Mixing closes with other prices. An average of closes and an average of highs are different series.
- Comparing periods across timeframes. A 20-period average on hourly candles and on daily candles covers very different spans of time.
Glossary
Period (n): the number of prices in each average. SMA: the simple moving average, an equal-weight mean of the last n prices. EMA: the exponential moving average, which weights recent prices more and never fully drops older ones. Smoothing factor (a): the EMA's weight on the newest price, 2 / (n + 1). Seed: the value the EMA starts from. WMA: the linearly weighted moving average. Lag: how far an average trails the latest price.
Frequently asked questions
How do you calculate a simple moving average?
Add the last n prices and divide by n, then repeat one row later. For the prices 12, 13 and 14, the 3-period SMA is 39 / 3 = 13.
What is the EMA formula?
EMA today = a x price today + (1 - a) x EMA yesterday, with a = 2 / (n + 1). A 5-period EMA puts a weight of 0.3333 on the newest price and 0.6667 on the previous EMA.
How is the first EMA value calculated?
It needs a seed. One convention starts the EMA at the simple average of the first n prices; another starts it at the very first price. The calculator offers both, and the gap between them shrinks as more rows are added.
What is the difference between SMA and EMA?
The SMA weights the last n prices equally and drops each one completely when it leaves the window. The EMA weights recent prices more and keeps a shrinking weight on every earlier price. With a = 2 / (n + 1) and the SMA seed, both have the same average age of (n - 1) / 2 rows; a first-price seed makes the EMA's slightly lower.
How do you calculate a weighted moving average?
Multiply the newest price by n, the one before by n - 1, and so on down to 1, then divide by n(n + 1) / 2. For 12, 13 and 14 over 3 periods, that is (12 + 26 + 42) / 6 = 13.33.
Why does my EMA not match my chart?
The usual reasons are a different seed, a different number of prices before the latest one, or a different price type such as highs instead of closes. Enter the same closes your chart uses, choose the matching seed, and compare at the same decimals.
How many prices do I need for a 50-day moving average?
At least 50 daily closes. The calculator takes up to 60 rows, so a 50-period average fits, while a 200-period average needs a spreadsheet.
Which reacts faster, EMA or WMA?
Measured by the average age of the prices inside it, the WMA, at (n - 1) / 3 rows, sits closer to the latest price than an SMA or an SMA-seeded EMA of the same period, both at (n - 1) / 2. On the default rising prices the 5-period WMA is 110.85 against an EMA of 110.48.
How do I calculate a moving average in Excel?
With prices in B2 down, enter =AVERAGE(B2:B6) beside the fifth price and fill down for a 5-period SMA. For an EMA, seed the first cell and use =2/(5+1)*B7+(1-2/(5+1))*E6 in the next row.
Does price crossing a moving average mean anything?
It means the latest price has moved from one side of a past average to the other. The arithmetic says nothing about what happens next, and the calculator does not treat a cross as a signal.
Courses behind chart indicators
Technical Analysis Crash Course
Introductory technical analysis course explaining market psychology, price action, volume, chart patterns, and indicators such as MACD for new traders.
See what the course coversAdvance Technical Analysis Course
Advanced technical analysis course led by Mr Vinod Gaur, covering professional chart, pattern, indicator, and trend analysis for intermediate traders.
See what the course coversData Analysis for Trading in Stock Market
Course on using economic indicators and market data to understand trends, volatility, and sentiment for data-driven stock trading decisions.
See what the course coversSources and review
Last reviewed 14 November 2026 by the NIFM Academy editorial team. Next review by 14 May 2027.
- Simple and weighted moving average formulas, SMA = sum of the last n prices / n; WMA weights 1 to n with the newest at n, divided by n(n + 1) / 2; worked in the tables and the working under every result. Checked 14 November 2026.
- Exponential moving average recursion and lag, EMA = a x price + (1 - a) x previous EMA with a = 2 / (n + 1), seeded with the first n-period SMA or with the first price; average age (n - 1) / 2 for the SMA and for an SMA-seeded EMA, and (n - 1) / 2 x (1 - (1 - a)^(N - 1)) for a first-price seed over N prices; WMA average age (n - 1) / 3; derived from the weights and checked numerically. Checked 14 November 2026.