Moving average Slope – Trading Strategy Backtest (Does it work?)
Last Updated on May 21, 2022 by Quantified Trading
Moving average slope strategy backtest
Finding good signals in the random chaos called the financial market is not an easy job and as such, one has to seek out every possible way to analyze the markets. In the search for an edge in the market, people create more indicators from existing ones. One of such derivative indicators is the moving average slope. And now, you may be wondering what that is. You might also wonder how you can make profitable moving average slope strategies in the markets?
Yes, moving average slope strategies do work. Our backtests show that a moving average slope can be used profitably for both mean-reversion and trend-following strategies on stocks.
The moving average slope is an indicator created by subtracting the moving average level n-periods ago from the current moving average level and dividing by the time interval. For instance, you can get a 5-day slope of a 50-day simple moving average of the daily closing price by subtracting the value of the 50-day moving average 5 days ago from today’s value of the same 50-day moving average and dividing the difference by 5 days. The indicator is a great attempt at spotting when the price might be about to change direction by studying the strength (momentum) of the moving average.
Table of contents:
Does a moving average slope strategy work? We backtest different strategies
Before we go on to explain what a moving average slope 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 moving average slope strategy work? Can you make money by using moving average slope 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 N-day moving average slop crosses BELOW zero, we buy SPY at the close. We sell when the N-day moving average slope closes ABOVE zero. We use CAGR as the performance metric.
- Strategy 2: Opposite, when the N-day moving average slop crosses ABOVE zero, we buy SPY at the close. We sell when the N-day moving average slope closes BELOW zero. We use CAGR as the performance metric.
- Strategy 3: When the N-day moving average slop crosses BELOW zero we buy the close, and we sell after N-days. We use average gain per trade in percent to evaluate performance, not CAGR.
- Strategy 4: When the N-day moving average slop crosses ABOVE zero we buy the close, we sell after N-days. We use average gain per trade in percent to evaluate performance, not CAGR.
The results of the first two strategies look like this:
Strategy 1
MA Days |
5 |
10 |
25 |
50 |
100 |
200 |
CAR |
11.14 |
4.63 |
4.96 |
1.92 |
0.95 |
-0.64 |
MDD |
-36.62 |
-47.12 |
-45.81 |
-54.05 |
-55.39 |
-59.74 |
Strategy 2
MA Days |
5 |
10 |
25 |
50 |
100 |
200 |
CAR |
-1.19 |
4.85 |
4.57 |
7.52 |
8.43 |
6.4 |
MDD |
-65 |
-33.71 |
-37.83 |
-34.22 |
-33.72 |
-33.72 |
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. The crossover system in strategy 1 using a 5-day moving average, has one of the best CAGRs of all the moving averages we have tested (see further below for a full list).
Why do we reach that conclusion?
Because if we use a short moving average, the best strategy is to buy when the moving average slop drop below zero and sell when it turns around and closes above zero (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 11.14%, which is better than 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 100-day moving average returns 8.43%, which is pretty decent.
The results from strategies 3 and 4 looks like this (the results are not CAGR, but average gains per trade):
Strategy 3
MA \ Bars |
5 |
10 |
25 |
50 |
100 |
200 |
5 |
0.49 |
0.77 |
1.5 |
2.39 |
4.32 |
8.49 |
10 |
0.41 |
0.27 |
0.72 |
2.09 |
3.88 |
7.55 |
25 |
0.83 |
0.19 |
1.24 |
2.3 |
3.73 |
7.24 |
50 |
0.63 |
1.19 |
1.6 |
3.53 |
6.02 |
12.22 |
100 |
1.06 |
1.2 |
1.87 |
4.52 |
6.15 |
6.15 |
200 |
-0.45 |
-0.71 |
0.95 |
0.14 |
-6.37 |
-12.67 |
Strategy 4
MA \ Bars |
5 |
10 |
25 |
50 |
100 |
200 |
5 |
0.01 |
0.1 |
0.82 |
2.02 |
4.27 |
8.04 |
10 |
0.03 |
0.29 |
0.67 |
1.01 |
3.37 |
7.41 |
25 |
0.1 |
0.12 |
0.41 |
1.17 |
4.14 |
6.53 |
50 |
0.12 |
0.27 |
1.89 |
2.58 |
5.7 |
13.59 |
100 |
0.59 |
0.55 |
1.8 |
2.11 |
3.99 |
9.55 |
200 |
0.34 |
-0.64 |
-0.03 |
3.13 |
1.18 |
7.08 |
The 50-day average is the best – by far. Of all the moving averages we have tested, this has returned the most. Strategy 4, which buys when the moving average slope breaks above zero, has an average return of 13.59% over the next 200 days – much better than buy and hold.
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 the moving average slope (MA Slope)?
The moving average slope is an indicator you can create from a moving average indicator or moving average indicators you are already using. For any given moving average, you can get the slope by subtracting the moving average level n-periods ago from the current moving average level and dividing by the time interval.
For example, you can get a 5-day slope of a 50-day simple moving average of the daily closing price by subtracting the value of the 50-day moving average 5 days ago from today’s value of the same 50-day moving average and dividing by the time interval. It is an attempt at using insights from geometry to study the momentum of the moving average.
The indicator can help to monitor the strength of the trend and spot when the price might be about to change direction by showing the strength (momentum) of the moving average. In other words, the MA Slope is a measure of the momentum of the moving average indicator, and as such, can tell the strength of the prevailing trend.
Whether the indicator is more useful than combining two MAs, n-periods apart, and using the crossover strategy depends on the trader’s preference. But as with the crossover method, the moving average slope can tell you if the trend is going up, down, or staying flat, and better still if the trend is losing momentum in its current direction.
How to calculate the slope of a moving average
In time series, the slope of two successive points in time is gotten by just subtracting the last value from the one preceding it. But when there is a wider interval, say 5 points in time, we have to use the below formula:
Slope = change in price / change in time
Bringing this to a moving average slope, the formula can be written as:
MA Slope = change in moving average value / time interval
Or
MA Slope = [MA_{c} – MA_{n}]/n
Where:
MA_{c} = current value of the moving average
MA_{n} = the value of the moving average n-periods ago
n = number of periods ago
Why use moving average slope?
The moving average slope can tell you the momentum of the moving average relative to some time in the past. That is, when the moving average is increasing in value, staying flat, or decreasing. This, in turn, tells you the strength of the trend.
Also, when using two MAs of different periods to indicate the short-term and long-term trends, their slopes can show you when both the short-term and long-term trends are in the same direction, which presents a better and less-risky time to enter a trade in that direction.
How to use the moving average slope
Ordinarily, when using a moving average indicator, you can visually gauge the slope of the moving average — at least, you can see whether the slope is upward (uptrend), flat (sideways), or downward (downtrend). In fact, if you are observant, you can see when the slope is getting steeper (stronger trend) or less steep (declining trend).
However, you can code or pay someone to code a custom indicator that measures slope and displays it as an indicator line on the chart. This can make the use of moving average slope easier for you.
How can you use the slope of a moving average in trading?
There are many ways you can use the slope of a moving average in guiding your trading decisions. The simplest one is to find the direction of the trend when using a single moving average. In this case, if the slope is upward, the market is likely in an uptrend, and if it is downward, the market is likely in a downtrend. When the slope is flat, the market is probably range-bound.
You can also employ the strategy of the relative slope by using two moving averages of different periods to show the long-term and short-term trends. In this case, when the slope of both moving averages is upward, it means that both the short-term and long-term trends are in the same direction: upward. So, it is safe to go long. If the long-term MA Slope is upward, but the short-term one is downward, it may be best to wait for both to align before you make a trade.
Similarly, if both long-term and short-term MA slopes are downward, it may be safe to take a short position in the market.
Drawbacks of using the moving average slope
As with any moving average-based indicator, the MA Slope is also plagued by the lag factor. As a result, the signal may come too late after the price has progressed in the new trend direction.
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)
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
Moving average slope – takeaways
Our takeaway from the backtests is that moving average slope strategies work well if you buy on weakness (when the average turns negative) and sell on strength (when the average turns positive) when you use a short number of days. Opposite, it’s best to buy on strength (a close above the moving average) when you use a longer moving average.