Exponential Moving Average Strategy – Trading Backtest (Does it work?)

Last Updated on September 19, 2022 by Quantified Trading

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:

  1. 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.
  2. 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.
  3. 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.
  4. 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:

Exponential moving average(blue line) vs a simple 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:

We have also published relevant trading moving average strategies:

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.

Similar Posts