Weighted Moving Average – Trading Strategy Backtest (Does it work?)
Last Updated on May 21, 2022 by Quantified Trading
Weighted moving average strategy backtest
Some simply call it weighted moving average, while others call it linearly weighted moving average. They are referring to the same indicator, which is one of the most popular and widely used MA indicators on most trading platforms. But what is it? And do you know if a weighted moving average strategy works?
Yes, weighted moving average strategies do work. Our backtests show that weighted moving average can be used profitably for both mean-reversion and trend-following strategies on stocks.
As the name implies, the weighted moving average puts more weight on recent data and less on past data. This is done by multiplying each period’s price by a weighting factor that decreases linearly you move from recent to old data. Given this unique calculation, the WMA will follow prices more closely than a corresponding simple moving average.
Table of contents:
Does a weighted moving average strategy work? We backtest strategies
Before we go on to explain what a weighted 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 weighted moving average strategy work? Can you make money by using weighted moving average 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
Period |
5 |
10 |
25 |
50 |
100 |
200 |
CAR |
8.53 |
8.05 |
5.99 |
5.17 |
5 |
3.28 |
MDD |
-23.82 |
-33.9 |
-42.66 |
-40.24 |
-49.38 |
-49.2 |
Strategy 2
Period |
5 |
10 |
25 |
50 |
100 |
200 |
CAR |
1.09 |
1.54 |
3.5 |
4.31 |
4.48 |
6.21 |
MDD |
-75.45 |
-65.93 |
-39.08 |
-41.21 |
-44.53 |
-42.69 |
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. This is pretty typical in the stock market because any oversold or overbought conditions don’t stay like that for long periods of time.
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.53%, 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 6.21%, which is pretty decent. However, even though the above data is without reinvested dividends, it’s below buy and hold.
The results from backtests 3 and 4 looks like this (the results are not CAGR, but average gains per trade):
Strategy 3
Period |
5 |
10 |
25 |
50 |
100 |
200 |
5 |
0.22 |
0.33 |
1.2 |
1.85 |
4.07 |
9.2 |
10 |
0.22 |
0.51 |
1.15 |
2.41 |
3.85 |
9.85 |
25 |
0.16 |
0.52 |
1.14 |
2.09 |
4.54 |
8.78 |
50 |
0.22 |
0.61 |
1.24 |
2.47 |
4.34 |
8.94 |
100 |
0.67 |
0.76 |
1.32 |
1.96 |
4.31 |
8.79 |
200 |
0.53 |
0.66 |
1.87 |
3.19 |
4.71 |
7.72 |
Strategy 4
Period |
5 |
10 |
25 |
50 |
100 |
200 |
5 |
0.22 |
0.26 |
0.93 |
2.16 |
4.3 |
8.58 |
10 |
0.2 |
0.27 |
0.93 |
2.52 |
4.24 |
8.82 |
25 |
0.23 |
0.31 |
0.78 |
2.16 |
3.63 |
7.47 |
50 |
0.17 |
0.19 |
0.76 |
1.2 |
3.78 |
8.63 |
100 |
0.1 |
0.26 |
1 |
1.25 |
4.1 |
8.11 |
200 |
0.27 |
0.01 |
0.78 |
2.42 |
3.87 |
6.75 |
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.
However, be aware that this is just one method of testing a 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 weighted moving average (WMA)?
A weighted moving average indicator is one that sets different weights for the price data of different trading periods. The idea behind its calculation is to give more weight to recent data and less weight to older data. This way, it shows the prevailing trend at the moment, not the previous one.
So, while it smooths out sharp price deviations, it also determines more accurately the direction of the trend at that moment since recent data is given greater specific weight. Due to giving more weight to the recent price data, the indicator reacts faster to price changes.
How to calculate WMA
When calculating the WMA, the most recent data is more heavily weighted so it contributes more to the final WMA value. You use the number of periods chosen for the indicator to determine the weighting factor to use in the calculation.
For instance, if you want to calculate a 5-period WMA, you may do it as follows:
WMA = [(P1 * 5) + (P2 * 4) + (P3 * 3) + (P4 * 2) + (P5 * 1)] / (5 + 4+ 3 + 2 + 1)
Where:
P1 = current price
P2 = price one bar ago
P3 = price two bars ago, and so on.
Note that you don’t have to do the calculation manually, as your trading platform does the calculation and plots the indicator line once you attach the indicator to the chart.
Why use a WMA?
The WMA helps to smooth the price data and reduce noise so you can make a better sense of what the price is doing. It can help you to identify the direction of the trend and when the trend is changing direction.
A long-period WMA can show potential levels of support and resistance, where you can look for trading opportunities. Short-period WMAs move closely with price swings and can help you identify when to buy or sell a security.
How to use a WMA
Most trading platforms have a built-in weighted moving average indicator, although some call it linear-weighted moving average (LWMA). To use the indicator, you have to attach the indicator to the chart and adjust the settings to what you want.
If you want to use the WMA to identify the trend, you make the averaging period long, say 100 or 200. But if you want it to show short-term price swings, set the period to a small number, say 20 or 30.
How can you use a WMA?
You can use long-period WMA to determine the direction of the trend: when the WMA is rising, the trend is upward, so you look for only buying opportunities, and when the WMA is declining, the trend is downward, so you may have to look for short-selling opportunities.
A long-period WMA can also serve as ascending support levels in an uptrend and descending resistance levels in a downtrend. You look for trading opportunities when the price pulls back to such levels.
Another option is to use two WMA indicators: a long-period WMA and a short-period WMA. In this case, when short-period WMA crosses above the long-period WMA (what chartists call the golden cross), you may have a buy signal, and when the short-period WMA crosses below the long-period WMA (a dead cross), it could mean a sell signal.
Drawbacks with a WMA
Usually, the WMA is faster than the SMA, it still lags and cannot identify the exact price turning 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)
- Exponential moving average (backtest strategy)
- Hull moving average (backtest strategy)
- Adaptive moving average (backtest strategy)
- Smoothed moving average (backtest strategy)
- Variable moving average (backtest strategy)
- Linear-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
Weighted moving average – takeaways
Our takeaway from the backtests is that weighted moving average strategies work well if you buy on weakness (a close below the moving average) 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.