Exponential Moving Average – Trading Strategy Backtest (Does it work?)
Last Updated on May 21, 2022 by Quantified Trading
Exponential moving average strategy backtest
There are different kinds of moving average indicators, and the exponential moving average is one of the most commonly used among traders. But do you know what it is? And do you know if an exponential average strategy can be used profitably in the stock market?
Yes, exponential moving average strategies do work. Our backtests show that an exponential moving average strategy can be used profitably for both mean-reversion and trend-following strategies on stocks. Mean-reversion works in the short term, while long-term works better for trend-following.
Also referred to as the exponentially weighted moving average, the exponential moving average (EMA) is a type of moving average indicator that places a greater weight and significance on the most recent data points. Thus, it follows the price more closely than the simple moving average.
Table of contents:
Does an exponential moving average strategy work? We backtest different strategies
Before we go on to explain what an exponential 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 an exponential moving average work? Can you make money using exponential moving averages?
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
Period |
5 |
10 |
25 |
50 |
100 |
200 |
CAR |
7.41 |
6.83 |
5.51 |
3.55 |
2.8 |
1.6 |
MDD |
-30.54 |
-34.68 |
-37.13 |
-45.67 |
-50.71 |
-51.35 |
Strategy 2
Period |
5 |
10 |
25 |
50 |
100 |
200 |
CAR |
2.15 |
2.73 |
4.02 |
5.94 |
6.72 |
7.84 |
MDD |
-64.88 |
-52.42 |
-51.12 |
-33.11 |
-42.74 |
-25.94 |
The backtests reveal the following: in the short run, the stock market shows tendencies to mean-reversion. But in the long run, it is better to use trend-following strategies.
What makes us draw this conclusion?
When we use a short moving average, the optimal strategy is to buy when stocks crosses below the exponential average and sell when it turns around and crosses above the exponential 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 7.41%, which is almost as good as buy and hold even though the time spent in the market is substantially lower and we are not including dividends reinvested. The max drawdown is also much lower than simply buying and holding.
In the second test in the table above, when we buy on strength and sell on weakness,Â 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.84%, which is pretty decent. Worth noting is that the max drawdown is just half of buy and hold (26 vs 56%).
The results from backtests 3 and 4 look like this (the results are not CAGR, but average gains per trade):
Strategy 3
Period |
5 |
10 |
25 |
50 |
100 |
200 |
5 |
0.26 |
0.53 |
1 |
2.11 |
3.79 |
8.54 |
10 |
0.15 |
0.42 |
1.21 |
2.18 |
4.45 |
8.85 |
25 |
0.17 |
0.53 |
0.96 |
2.3 |
3.92 |
9.17 |
50 |
0.42 |
0.53 |
1.13 |
2.59 |
4.96 |
10.17 |
100 |
0.42 |
0.84 |
1.96 |
3.16 |
5.58 |
9.27 |
200 |
0.51 |
0.39 |
0.93 |
3.65 |
4.83 |
7.66 |
Strategy 4
Period |
5 |
10 |
25 |
50 |
100 |
200 |
5 |
0.23 |
0.28 |
0.89 |
2.52 |
3.95 |
8.95 |
10 |
0.14 |
0.19 |
1.02 |
1.72 |
3.88 |
9.12 |
25 |
0.19 |
0.31 |
0.82 |
1.67 |
3.65 |
8.24 |
50 |
0.26 |
0.35 |
0.79 |
1.21 |
3.61 |
8.62 |
100 |
0.41 |
0.34 |
1.54 |
2.21 |
4.96 |
8.65 |
200 |
0.33 |
0.01 |
0.15 |
2.59 |
5.49 |
7.43 |
As expected, the longer you are in the stock market, the better returns you get, as can be seen when we increase the length of the exponential averages. This is because of the tailwind in the form of inflation and productivity gains. However, it doesn’t matter much if you buy on a break above or below the exponential average. It matters for 5 and 20-day moving averages, but after that, the differences vanish.
However, be aware that this is just one method of testing an exponential moving average. There are basically unlimited ways you can use a moving average and your imagination is probably the most restricting factor! We have mentioned many other methods and techniques in our article called are moving averages good or bad.
What is an exponential moving average (EMA)?
The exponential moving average, also referred to as the exponentially weighted moving average, is a type of moving average indicator that places a greater weight and significance on the most recent data points. It is similar to Simple Moving Average (SMA) in measuring trend direction over a period.
However, while the SMA simply calculates an average of price data, the EMA applies more weight to data that is more current. As a result of this method of calculating the average, the EMA will follow prices more closely than a corresponding SMA.
As with all other moving average indicators, the EMA aims to use past prices to establish the direction the price of an asset is moving. Therefore, exponential moving averages are lag indicators. They are not predictive of future prices; they simply highlight the trend that is being followed by the stock price.
How to calculate EMA
The EMA calculation is a bit more complex than that of the SMA. Recent price data are given greater weight than old price data. Thus, the newest price data has the most impact on the moving average, while the oldest prices data has the least impact. The calculation also makes use of the previous value of the EMA, and as such, the EMA includes all the price data within its current value.
The formula is given as:
EMA = (K x (C – P)) + P
Where:
C = Current Price
P = Previous periods EMA (A SMA is used for the first period’s calculations)
K = Exponential smoothing constant
Note that the smoothing constant, K, applies appropriate weight to the most recent price, and it uses the number of periods specified in the moving average. K is often calculated as follows:
K â€“ 2/(n + 1))
Where:
N = the selected period
Why use an EMA?
As with other moving average types, the EMA smooths the price data, reducing the noise, so that traders can make a better sense of what the price is doing. It can help a trader to spot the direction of the trend, as well as identify when the trend is changing direction.
The EMA, especially a long-period one, can show traders potential levels of support and resistance. At such levels, traders can look for trading opportunities. Also, the EMA is generally faster than the SMA for any chosen period, so one can use it to monitor price swings.
How to use an EMA
About any trading platform out there has a built-in EMA indicator. So, all a trader needs to do is just attach the indicator to the chart and adjust the settings to what they want.
To use the EMA to show a longer-term trend, the traders would have to set the averaging period long enough, say 100 or 200. To have the indicator follow the price more closely and show the price swings, it makes sense to set the period to a lower number, say 20 or even 10.
How can you use an EMA?
You can use the EMA to determine the trend direction so that you trade in that direction. Thus, when the EMA is rising, you may want to look for only buying opportunities. On the other hand, when the EMA is declining, you may have to look for short-selling strategies and opportunities.
Since moving averages can also indicate support and resistance areas. The EMA can serve as a support in an uptrend and as a resistance in a downtrend. This reinforces the strategy of buying when the price is around a rising EMA and selling when the price is around a falling EMA.
But as always in trading, creatively pays off. We use moving averages in our own trading but only as part of other parameters.
Drawbacks with an EMA
Although the EMA is faster than the SMA, it still lags and thus, cannot be used to identify a trade at the exact price turning points. There would always be a delay at the entry and exit points. If you reduce the period to make it move closer to the price, it gives more false signals.
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?
- Simple 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
Exponential moving average – takeaways
Our takeaway from the backtests is that exponential moving average strategies work well if you buy on weakness (a close below 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 long moving average (50 days and more).