Trading & crypto

Moving average formula in Excel (SMA & EMA)

A simple moving average averages the last N closes. An EMA weights recent prices more using a smoothing factor of 2/(N+1).

All Excel versions and Google Sheets

The formula

3-period SMA (start in row 4, fill down) (fill down)ExcelGoogle Sheets
=AVERAGE(B2:B4)
In C4 → 101.00
3-period EMA (seed with the SMA, fill down) (fill down)ExcelGoogle Sheets
=B5*(2/(3+1))+D4*(1-2/(3+1))
In D5 → 103.00
Average of the last 3 valuesExcelGoogle Sheets
=AVERAGE(OFFSET(B2,COUNT(B2:B100)-3,0,3))
In F2 → 107.33
✓ Tested. All 12 Excel results in this example were recalculated in LibreOffice Calc 25.2 and matched the values shown.

Worked example

Paste the data below into a blank sheet starting at cell A1 (or download the cheat sheet, where every example is set up). Highlighted cells hold the formulas and show the expected results.

ABCDEF
1DayClose
21100107.33
32102
43101101.00101.00
54105102.67103.00
65107104.33105.00
76104105.33104.50
87108106.33106.25
98110107.33108.12

How it works

AVERAGE(B2:B4)
Relative range: moves down one row as you fill.
2/(3+1)
EMA smoothing factor for N = 3. For a 20-period EMA use 2/21.
D4
EMA seed: the first SMA value.
OFFSET(B2,COUNT(…)-3,0,3)
A 3-row range ending at the last number in the column.

Common errors and fixes

EMA differs from your charting platform?

Platforms seed the EMA differently; values converge after a few dozen periods.

OFFSET returns #REF!?

Fewer than N values in the column.

Does this work in Google Sheets?

Yes. The formulas on this page work the same way in Google Sheets.