Exponential Moving Average Strategy – Trading Backtest (Does it work?)
Last Updated on May 24, 2023
Exponential moving average strategy and backtest
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?
Backtests indicate that exponential moving averages do work: They can be useful for mean-reversion strategies if you use a short number of days in the moving average, and useful for long-term trend following if you use a high number of days in the moving average.
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.
Exponential moving average strategy backtest and best settings
Right off the bat, we backtest four different exponential moving average strategies. If you want to understand what an exponential moving average is, you can read more about that after our backtests.
What are we trying to find out?
We want to know if an exponential moving average crossover system can be used profitably in trading systems. Can you make money using exponential moving averages?
We do our backtest on 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 from the two first backtest are summarized in these two tables:
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 |
What are the main takeaways from the two tables?
The first is that in the short run, it’s better to buy when the close crosses below a short-term moving average and sell when it closes above. This can be seen in table one: as the number of days in the exponential moving average increases, the CAGR (CAR) goes down. Such strategies that buy on weakness and sell on strength are called mean-reversion. The best strategy in table 1 is to use a 5-day moving average and that strategy yields a CAGR of 7.41%, which is pretty good while max drawdown is “only” 30.54%, much lower than for buy and hold. Please keep in mind that the results don’t include reinvested dividends.
The second takeaway is that the opposite strategy is more useful in the long run: The higher the number of days in the moving average the more profitable it is to buy when the close crosses above the moving average and sell when it closes below. This is called trend-following strategies. 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%).
Let’s move on to backtest 3 and 4. The results are summarized in these two tables:
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 |
The entry into a trade is the same as in strategies 1 and 2, but we exit after N-days. Thus, this is not a crossover system. We already know that profitability increases the longer you are invested in stocks, and the tables show that. The best strategy is to buy when the close crosses below the 50-day moving average and sell after 200 days. This produces 10.17% per trade.
These four strategies are, of course, not the only way to trade moving averages. There are potentially unlimited methods and ways to use an exponential moving average, and only your imagination limits you. 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.
For your convenience, we made a screenshot in Amibroker to show you the difference between a simple and an exponential moving average:
The blue line is the exponential moving average and it clearly deviates toward the right end. That is because it puts more emphasis on the last prices and is not equal-weighted as the simple moving average is.
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 price 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. But as the chart above shows, the exponential moving average reacts more strongly to the latest records. Thus, you can only find out what is best via backtests.
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. We have given you some ideas in this article with our four backtests above, but there are plenty of other ways to use an exponential moving average.
But as a rule of thumb, mean reversion works best in the stock market in the short term, while trend-following works best in the long run.
How can you use an EMA?
We believe it’s most useful as a crossover strategy, as we showed in the four backtests above.
However, 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.
More articles about moving averages strategies that include backtests
Moving averages are popular trading tools and for good reason. They can be used on their own but also as one of several parameters in a trading strategy.
Moving averages were probably more useful earlier than they are now. They have been around for a long time and were used when the first computers were used to develop trading strategies in the 1970s, for example by Ed Seykota. We suspect the most low-hanging fruit is already “arbed” away.
This is our list of all relevant articles to moving averages:
- Moving average trading strategies
- 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
FAQ exponential moving average (EMA)
We end the article with some frequently asked questions:
Q: What is an exponential moving average (EMA)?
A: An exponential moving average (EMA) is a type of moving average that places a greater weight on recent prices in an effort to make it more responsive to new information.
Q: How is an EMA different from a simple moving average (SMA)?
A: An EMA gives more weight to recent prices than a SMA, which gives equal weight to all prices in the time period. This makes an EMA more sensitive to recent price changes than a SMA.
Q: What is the formula for calculating an EMA?
A: The formula for calculating an EMA is: EMA = (Price x (2/(Time Period + 1))) + (EMA of Prior Period x (1 – (2/(Time Period + 1))))
Q: What is the time period used for calculating an EMA?
A: The time period used for calculating an EMA is typically set by the trader and can range from a few days to several months.
Q: How is an EMA used?
A: An EMA is often used by traders to identify trends or to confirm the strength of a trend. It is also used to identify support and resistance levels.
Q: Are there any drawbacks to using an EMA?
A: One potential drawback to using an EMA is that it can be too responsive to recent price changes and may lead to false signals. It is important to use other indicators in combination with an EMA to confirm signals.
Q: What is a good exponential moving average?
A: There is no good or bad exponential moving average. If you backtest yoiu’ll find out what is the best moving average for your asset class.
Q: Which exponential moving average is best for swing trading?
A: See answer above. Only a backtest can give you an answer.
Q: Is EMA a good indicator?
A: Yes, but our experience indicates itâ€™s best as one of more parameters. For example, a simple moving average can be used as a trend filter. Please check out our pullback trading strategy.
Q: Do most traders use EMA or SMA?
A: We believe most traders use SMA. However, we believe SMA and EMA are not that different.
Exponential moving average – takeaways and conclusions
We would say that the main conclusion from this article is that exponential moving average strategies work best for either a low or high number of days in the moving average. Mean reversion is best for a short number of days, and trend following for a high number of days.