Understanding the moving average (SMA and EMA) — concept and principle
A moving average smooths a series of numbers by averaging over a sliding window, so short-term noise fades and the underlying trend becomes visible. It is used for sales and website traffic, temperature records, production data and price charts. This calculator gives the simple moving average (SMA) series for your window, the last SMA value and the last exponential moving average (EMA).
How it is calculated
- SMA: the average of the last w values, SMAₜ = (xₜ + xₜ₋₁ + … + xₜ₋w₊₁) ÷ w. The first SMA appears at the w-th value, so a series of n values gives n − w + 1 SMA values.
- EMA: EMAₜ = α × xₜ + (1 − α) × EMAₜ₋₁ with α = 2 ÷ (w + 1). This calculator starts the EMA at the first data value.
The result has the same unit as the data.
The principle
The SMA gives equal weight to the last w observations and none to older ones, so random ups and downs partly cancel. The cost is lag: the SMA reflects the centre of its window, about (w − 1) ÷ 2 periods behind the latest value. The EMA instead weights every past value, with weights shrinking by the factor (1 − α) each period, so recent data count most and the average reacts faster to change. The choice α = 2 ÷ (w + 1) makes the average age of the EMA weights equal to that of a w-period SMA.
Worked example
- Data: 12, 15, 11, 19, 22, 15, 18, 25, 14, 16; window w = 3.
- First SMA: (12 + 15 + 11) ÷ 3 ≈ 12.6667; then 15, 17.3333, 18.6667, 18.3333, 19.3333, 19 and finally (25 + 14 + 16) ÷ 3 ≈ 18.3333.
- EMA: α = 2 ÷ 4 = 0.5, start at 12.
- Successive EMA values: 13.5, 12.25, 15.625, 18.8125, 16.90625, 17.453125, 21.2265625, 17.61328125.
- Last step: 0.5 × 16 + 0.5 × 17.61328125 ≈ 16.8066.
How to read the result
The last EMA (16.81) sits below the last SMA (18.33) because the EMA reacts more strongly to the two latest, lower values (14 and 16). A rising moving average signals an upward trend; when the raw data cross their moving average, the short-term direction may be changing. A longer window gives a smoother line but more delay. Common windows match a natural cycle, such as 7 days for daily data with weekly patterns or 12 months for seasonal monthly data.
Common mistakes
- Treating the smoothed value as a forecast; it describes the past.
- Comparing EMAs started from different seed values over short series.
- Choosing a window that does not match the data's cycle, which leaves seasonal waves in the curve.
Frequently asked questions
What is the difference between a trailing and a centred moving average?
A trailing average, as here, uses only current and past values. A centred average uses values on both sides of each point, which removes lag but needs future data.
How do I choose the window?
Match it to the noise period you want to remove; with no clear cycle, try several and compare.
Sources: Hyndman, R. J. & Athanasopoulos, G. Forecasting: Principles and Practice (OTexts).