Simple Moving Average – Trading Strategy Backtest (Does It Work?)
Last Updated on May 21, 2022 by Quantified Trading
Simple moving average strategy backtest
Moving averages are one of the most commonly used indicators in technical analysis, and the simple moving average is the easiest one to construct. Do you know what it is? Can you make profitable simple moving average strategies in the markets?
Yes, simple moving average strategies do work. Our backtests show that a simple moving average can be used profitably for both mean-reversion and trend-following strategies in the stock market.
A simple moving average (SMA) is a basic average of the price of an asset over a specified period calculated continuously for any new price data that forms in the time series. Since the price data keeps changing for each session and the average is calculated for each new data, the average changes constantly, which is why it is called a moving average.
Table of contents:
Does a simple moving average strategy work? We backtest different strategies
Before we go on to explain what a simple moving average is and how you can calculate it, we go straight to the essence of what this website is all about: quantified backtests.
Our hypothesis is simple:
Does a simple moving average strategy work? Can you make money by using simple moving averages strategies?
We look at the most traded instrument in the world: the S&P 500. We test on SPDR S&P 500 Trust ETF which has the ticker code SPY.
All in all, we do four different backtests:
- Strategy 1: When the close of SPY crosses BELOW the N-day moving average, we buy SPY at the close. We sell when SPY’s closes ABOVE the same average. We use CAGR as the performance metric.
- Strategy 2: Opposite, when the close of SPY crosses ABOVE the N-day moving average, we buy SPY at the close. We sell when SPY’s closes BELOW the same average. We use CAGR as the performance metric.
- Strategy 3: When the close of SPY crosses BELOW the N-day moving average, we sell after N-days. We use average gain per trade in percent to evaluate performance, not CAGR.
- Strategy 4: When the close of SPY crosses ABOVE the N-day moving average, we sell after N-days. We use average gain per trade in percent to evaluate performance, not CAGR.
The results of the first two backtests look like this:
Strategy 1
MA Days |
5 |
10 |
25 |
50 |
100 |
200 |
CAR |
8.34 |
7.53 |
5.72 |
5.19 |
3.47 |
1.55 |
MDD |
-32.61 |
-38.01 |
-39.89 |
-39.82 |
-50.96 |
-52.18 |
Strategy 2
MA Days |
5 |
10 |
25 |
50 |
100 |
200 |
CAR |
1.27 |
2.07 |
3.8 |
4.29 |
5.98 |
7.89 |
MDD |
-66.05 |
-56.27 |
-48.42 |
-41.68 |
-50.82 |
-28 |
The results from the backtests are pretty revealing: in the short run, the stock market shows tendencies to mean-reversion. In the long run, it is better to use trend-following strategies.
Why do we reach that conclusion?
Because if we use a short moving average, the best strategy is to buy when stocks drop below the average and sell when it turns around and closes above the moving average (buy on weakness and sell on strength). This can clearly be seen in the first test above for the 5-day moving average. The 5-day moving average returns a CAGR of 8.34%, which is almost as good as buy and hold even though the time spent in the market is substantially lower.
When we buy on strength and sell on weakness, in the second test in the table above, the best strategy is to use many days in the average. The longer the average is, the better. The 200-day moving average returns 7.89%, which is pretty decent. Worth noting is that the max drawdown is just half of buy and hold (28 vs 56%).
The results from backtests 3 and 4 look like this (the results are not CAGR, but average gains per trade in per cent):
Strategy 3
MA \ Bars |
5 |
10 |
25 |
50 |
100 |
200 |
5 |
0.28 |
0.39 |
1.08 |
2.11 |
4 |
8.62 |
10 |
0.28 |
0.55 |
1.21 |
2.49 |
4.48 |
8.87 |
25 |
0.25 |
0.57 |
1.02 |
2.19 |
4.02 |
8.23 |
50 |
0.3 |
0.62 |
1.16 |
2.24 |
5.7 |
9.64 |
100 |
0.59 |
1.2 |
1.8 |
3.37 |
5.49 |
9.07 |
200 |
0.29 |
0.38 |
1.07 |
3.24 |
6.61 |
8.06 |
Strategy 4
MA \ Bars |
5 |
10 |
25 |
50 |
100 |
200 |
5 |
0.22 |
0.23 |
0.86 |
2.26 |
3.75 |
8.92 |
10 |
0.23 |
0.44 |
0.92 |
1.96 |
4.09 |
9.3 |
25 |
0.26 |
0.37 |
1.01 |
1.42 |
4.01 |
7.62 |
50 |
0.06 |
0.15 |
0.46 |
1.35 |
4.36 |
9.14 |
100 |
0.3 |
0.43 |
1.36 |
2.47 |
5.35 |
7.3 |
200 |
0.24 |
-0.22 |
0.38 |
2.81 |
5.87 |
10.93 |
As expected, the longer you are in the stock market, the better returns you get. This is because of the tailwind in the form of inflation and productivity gains. The best result is from buying a close that crossed above the 200-day moving average and hold for 200 days. This has returned an average of 10.93% per trade (dividend reinvested is not included thus understating the result).
However, be aware that we have tested just four strategies of the moving average. There are basically unlimited ways you can use a moving average and your imagination is probably the most restricting factor!
What is a simple moving average (SMA)?
A simple moving average (SMA) is a simple average of the price of an asset over a specified period. The average is called “moving” because it is calculated continuously for any new price data recorded in each new trading session and plotted on the chart bar by bar, forming a line that moves along the chart as the average value changes.
The SMA is one of the primary indicators in technical analysis and is usually the easiest moving average to construct, which is why it is referred to as the “simple” moving average. The indicator is present on all trading platforms.
How to calculate a simple moving average
The formula for calculating the SMA is quite simple.
SMA = (P_{1 }+ P_{2} + P_{3}… + P_{n})/n
So, it is just the average closing price of an asset over the last “n” periods. To calculate it, you sum the closing prices of the asset over the chosen number of periods and then divide the sum by the number of periods.
For instance, let’s assume that Apple closed at $10, $11, $12, $11, $14 over the last five days. The simple moving average of Apple stock (AAPL) would be calculated as $10 + $11 + $12 + $11 + $14 divided by 5, which is equal to $11.6.
As time moves on, the first observation is taken away and replaced with a new one. For example, on the sixth day we have these observations:
$10 + $11 + $12 + $11 + $14 + $15
To calculate a new 5-day moving average we will have to exclude the first observation ($10) and replace it with $15:
$11 + $12 + $11 + $14 + $15
Thus, the new 5-day moving average is $12.6
Why use a simple moving average?
All moving averages aim to show the direction of the trend, and the SMA does that easily. It shows the direction the price of a security is moving based on previous prices. If the simple moving average points up, this means that the security’s price is increasing. If it is pointing down, it means that the security’s price is decreasing.
Also, it smooths out volatility better than most other moving average indicators. When the averaging period is long enough, say 100-day MA or 200-day MA, the indicator line can serve as a potential support or resistance level.
How to use a simple moving average
Every trading platform has a built-in simple moving average indicator. To use the indicator, you have to attach the indicator to the chart and adjust the settings to what you want. If you want the SMA to show a longer-term trend, you make the averaging period long, say 100 or 200. But if you want the indicator to follow the price more closely and show the short-term trend, you reduce the period to say 10 or 20.
How can you use a simple moving average?
You can use a simple moving average indicator to identify the price trend. If the SMA indicator line is pointing upward, with the price bars lying mostly above it, there is an upward trend, but if it is pointing downward, with the price bars lying mostly below it, there is a downward trend. When the SMA is flat, with the price swinging above and below it, the trend is sideways. The point is that you use the moving average purely mechanically by writing rules in your trading software.
Another thing you can do with the SMA indicator, especially a long-period (200-day SMA, for example) is to identify potential support and resistance levels. When the trend is upward, with the price bars lying above the SMA, the indicator line can serve as a potential support level. Likewise, when the trend is downward, with the price bars lying below the SMA, the indicator line can serve as a potential resistance level.
We have covered this in a separate article about moving averages.
Drawbacks with a simple moving average
The SMA is a lagging indicator. The reason is that the SMA is constructed using past closing prices. Thus, it simply displays a previous trend, which may not be predictive of future prices. You can reduce the lag by reducing the period setting, but that can also lead to many false signals. As always, there are only trade-offs in trading, no guarantees!
Relevant articles about moving averages strategies and backtests
Moving averages have been around in the trading markets for a long time. Most likely, moving average strategies were the start of the systematic and automated trading strategies developed in the 1970s, for example by Ed Seykota. We believe it’s safe to assume moving averages were a much better trading indicator before the 1990s due to the rise of the personal computer. The most low-hanging fruit has been “arbed away”.
That said, our backtests clearly show that you can develop profitable trading strategies based on moving averages but mainly based on short-term mean-reversion and longer trend-following. Furthermore, there exist many different moving averages and you can use a moving average differently/creatively, or you can combine moving averages with other parameters.
For your convenience, we have covered all moving averages with both detailed descriptions and backtests. This is our list:
- Are moving averages good or bad?
- Exponential moving average (backtest strategy)
- Hull moving average (backtest strategy)
- Linear-weighted moving average (backtest strategy)
- Adaptive moving average (backtest strategy)
- Smoothed moving average (backtest strategy)
- Variable moving average (backtest strategy)
- Weighted moving average (backtest strategy)
- Zero lag exponential moving average (backtest strategy)
- Volume weighted moving average (backtest strategy)
- Triple exponential moving average TEMA (backtest strategy)
- Variable Index Dynamic Average (backtest strategy)
- Triangular moving average (backtest strategy)
- Guppy multiple moving average (backtest strategy)
- McGinley Dynamic (backtest strategy)
- Geometric moving average GMA (backtest strategy)
- Fractal adaptive moving average FRAMA (backtest strategy)
- Fibonacci moving averages (backtest strategy)
- Double exponential moving average (backtest strategy)
- Moving average slope (backtest strategy)
We have also published relevant trading moving average strategies:
- The 200-day moving average strategy
- Trend-following system/strategy in gold (12-month moving average)
- Trend following strategies Treasuries
- Is Meb Faber’s momentum/trend-following strategy in gold, stocks, and bonds still working?
- Trend following strategies and systems explained (including strategies)
- Does trend following work? Why does it work?
- A simple trend-following system/strategy on the S&P 500 (By Meb Faber and Paul Tudor Jones)
- Conclusions about trend-following the S&P 500
- Why arithmetic and geometric averages differ in trading and investing
Simple moving average – takeaways
Our takeaway from the backtests is that simple moving average strategies work well if you buy on weakness (a close below the moving average) and sell on strength (a close above the moving average) when you use a short number of days (5-10 days). Opposite, it’s best to buy on strength (a close above the moving average) when you use a longer moving average of at least 100 days.