Moving Average
calculator.
A rolling average smooths the noise in a series so its direction shows.
| # | Value |
|---|---|
| 1 | |
| 2 | |
| 3 | |
| 4 | |
| 5 | |
| 6 | |
| 7 | |
| 8 | |
| 9 | |
| 10 | |
| 11 | |
| 12 |
- Weighted
- 35.667
- Exponential
- 35.197
- Latest value
- 37
The latest value, 37, sits 1.667 above the simple average. The middle of this window is 1 period back, so a turn in the data reaches the average late.
Your values and their averages
Your 12 values with the 3-period simple, weighted and exponential averages and a 6-period simple average. The two simple averages never cross here.
Long window and smoothing
- Crossovers
- None
The same values at other windows
| Window | Latest SMA | SMA error | EMA error |
|---|---|---|---|
| 2Latest SMA 35.5 | 35.5 | 5.65 | 6.179 |
| 3Latest SMA 35.333 | 35.333 | 8.852 | 9.059 |
| 4Latest SMA 34.25 | 34.25 | 12.906 | 12.959 |
| 5Latest SMA 33.8 | 33.8 | 16.749 | 17.15 |
| 6Latest SMA 33.167 | 33.167 | 24.454 | 23.862 |
| 7Latest SMA 32.286 | 32.286 | 30.914 | 30.576 |
Window 2 has the smallest one-step error of the simple average here, 5.65. Error is the mean squared miss when each average predicts the next value.
Working
- 1Average the first 3 values22 + 24 + 233= 23
- 2Slide the window to the newest valueSMA =1063= 35.333
- 3Weight the window 1 to 3, newest heaviestWMA =2146= 35.667
- 4Blend each new value into the last exponential averageα =23 + 1= 0.5Started from 23, latest EMA = 35.197
- 5Check: the average times the window gives the sum back35.3333 × 3 = 10635 + 34 + 37 = 106
Values and averages by period
| Period | Value | SMA 3 | WMA 3 | EMA | SMA 6 |
|---|---|---|---|---|---|
| 1 | 22 | –WMA – | – | –Long – | – |
| 2 | 24 | –WMA – | – | –Long – | – |
| 3 | 23 | 23WMA 23.167 | 23.167 | 23Long – | – |
| 4 | 26 | 24.333WMA 24.667 | 24.667 | 24.5Long – | – |
| 5 | 28 | 25.667WMA 26.5 | 26.5 | 26.25Long – | – |
| 6 | 27 | 27WMA 27.167 | 27.167 | 26.625Long 25 | 25 |
| 7 | 30 | 28.333WMA 28.667 | 28.667 | 28.313Long 26.333 | 26.333 |
| 8 | 32 | 29.667WMA 30.5 | 30.5 | 30.156Long 27.667 | 27.667 |
| 9 | 31 | 31WMA 31.167 | 31.167 | 30.578Long 29 | 29 |
| 10 | 35 | 32.667WMA 33.167 | 33.167 | 32.789Long 30.5 | 30.5 |
| 11 | 34 | 33.333WMA 33.833 | 33.833 | 33.395Long 31.5 | 31.5 |
| 12 | 37 | 35.333WMA 35.667 | 35.667 | 35.197Long 33.167 | 33.167 |
How it's worked out
A moving average replaces each value with the average of a window of recent values, so short-term noise cancels out. NIST describes it as taking the mean of a small set of past data, then moving on one period: add the newest value and drop the oldest. This tool works out three kinds side by side. It suits any evenly spaced series, such as weekly sales, daily temperatures or closing prices.
Here n is the window and is the value at period t. The simple average weights each value in the window equally. A window of 1 is the data itself, and a longer window gives a smoother line.
The weighted average gives the newest value a weight of n and the oldest a weight of 1. The bottom of the fraction is the triangle number of n, so the weights still come to 1 in total, and the line reacts faster.
The exponential average uses every past value, with weights that shrink by the factor \(1 - \alpha\) at each step back. The usual choice of α comes from the window: 18.18% for 10 periods and 9.52% for 20. With that α, the average age of the data, , equals , the same as the simple window. Here the first EMA is the first full simple average, as StockCharts does it. NIST lists other starts, such as the first value, and a different start gives different early figures.
Worked examples
Six weeks of values and a window of 3
Take the values 20, 22, 21, 25, 27, 26, a window of 3 and α = 0.5. The first simple average uses the first three values.
The simple averages are 21, 22.67, 24.33, 26. The first weighted average gives the newest value a weight of 3, and the weighted averages are 21.17, 23.17, 25.33, 26.17.
The exponential series is 21, 23, 25, 25.5. At the end, the simple average is 26, the weighted 26.17 and the exponential 25.5. The weighted one sits highest because it counts the 27 in the middle of the last window more than the 25 before it.
No average exists for the first two periods, because a 3-period window needs three values. Every simple series is shorter than the data by one less than the window.
A price that rises and then falls
This price peaks at period 5 and then slides. With windows of 3 and 5, the short average crosses below the long one at period 8, marking the change of direction 3 periods after the peak.
That delay cannot be avoided, because any average of past values reacts late. The latest simple average is 47.33, and the one-step error is 12.37 for the simple average and 10.5 for the exponential one.
Two weeks of daily temperatures
A 7-day window suits daily data with a weekly pattern. The latest 7-day average here is 20.7°, against 21° for the exponential average. The newest day counts for 14.3% of the simple average and 25% of the exponential one, which is why the exponential line moves more on each new reading.
The middle of the 7-day window is 3 days back. Comparing windows on these 14 days, window 6 has the smallest one-step error of the simple average, 9.5. That is a choice for prediction; a 7-day window can still be the right one for removing the weekly pattern.
Reading your result
Crossovers. A crossover happens when a short average moves above or below a long one. StockCharts calls the signal relatively late and warns that it is prone to whipsaws, where the lines cross back and forth without a strong trend.
One-step error. Each average predicts the next value, and the tool reports the mean squared miss. A lower number means the method tracks the series more closely, which helps when you choose a window or α. On the sales preset, a window of 2 gives 5.65 and a window of 3 gives 8.85. On a steadily rising series, the shortest window usually wins, since it lags least.
Choosing a window. A larger window means a smoother curve, and it lags more. To remove a seasonal pattern, match the cycle: 7 for daily data with a weekly pattern. For an even cycle such as 12 months, Hyndman and Athanasopoulos use a 2 by 12 centered average, because a plain even window is not symmetric. This tool's windows trail the data and are not centered, so their line sits behind the series.
Common mistakes
- Treating it as a forecast of turns. Moving averages describe the past. They do not predict turning points, and crossover rules in trading carry no guarantee of profit.
- Using unevenly spaced data. The method assumes evenly spaced values, so fill or note any missing periods first.
- Extending a flat forecast through a trend. The next-period forecast from simple exponential smoothing is flat, which suits a series with no trend or season. Series with both are better handled by methods such as Holt-Winters.
- Comparing EMAs from different tools. They can start from different values. The effect of the start fades as the series grows, but it matters more with a small α or a short series.
Questions people ask
Sources
- NIST/SEMATECH e-Handbook, section 6.4.2.1, Single moving average
- NIST/SEMATECH e-Handbook, section 6.4.3.1, Single exponential smoothing
- Hyndman and Athanasopoulos, Forecasting: Principles and Practice, 3rd ed., Moving averages
- Hyndman and Athanasopoulos, Forecasting: Principles and Practice, 3rd ed., Simple exponential smoothing
- StockCharts ChartSchool, Moving averages: simple and exponential
- Wikipedia, Moving average