Variable Moving Average Trading Strategy: Backtest and Evaluation
Variable moving average strategy backtest
Traders have always looked for ways to improve the performance of the exponential moving average, and using a volatility index (VI) to adjust the smoothing period as market conditions change has given rise to the variable moving average. But do you know what it is? And do you know if a variable moving average strategy works?
Yes, variable moving average strategies do work. Our backtests show that a variable moving average can be used profitably for both mean-reversion and trend-following strategies on stocks.
A variable moving average (VMA) is an exponential moving average (EMA) that can automatically regulate its smoothing percentage based on market volatility. The idea behind the VMA is to dynamically adapt a moving average to a trend’s volatility. Its sensitivity improves by assigning more weight to the ongoing data, thereby generating a better signal for short and long-term markets.
Variable moving average strategy backtest and best settings
Before we go on to explain what a variable 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 variable moving average strategy work? Can you make money by using variable 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.
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 close above the moving average (buy on weakness and sell on strength). It’s a classical mean reversion strategy. 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.
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.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 variable moving average (VMA)?
Also known as the volatility index dynamic average (VIDyA), the variable moving average (VMA) is an exponential moving average with a volatility index factored into the smoothing formula. Strictly speaking, the VMA is a modified version of the VIDyA: while the VIDyA uses standard deviation as the volatility index, the VMA uses the Chande Momentum Oscillator to measure volatility.
Both were introduced by Tushar S. Chande in 1992 and 1995 respectively. The main idea behind a variable moving average is to dynamically adapt an exponential moving average to a trend’s volatility.
Traditional moving averages cannot compensate for sideways moving prices versus trending markets and often generate a lot of false signals. For example, longer-term moving averages are slow to react to reversals in trend when prices move up and down over a long period. But the VMA regulates its sensitivity and lets it function better in any market conditions by using automatic regulation of the smoothing constant
The VMA belongs to the group of Adaptive Moving Averages which are also known as Intelligent Moving Averages. Its sensitivity improves by assigning more weight to the ongoing data as it generates a better signal indicator for short and long-term markets.
How to calculate VMA
The formula for VMA is a bit different from that of the VIDyA. Here is the formula for the VMA:
VMA = [P + (a*b)P_{1} + (a*b)^{2}P_{2} + … + (a*b)^{(n-1)}P_{(n-1)}]/ [1 + (a*b) + (a*b)^{2} + … + (a*b)^{(n-1)}]
Where:
P = current price
P1 = price 1 period ago
P2 = price 2 periods ago
a = smoothing constant 2/(n+1)
b = absolute value (F(P)/100)
n = user-defined number of periods for the average
The formula for calculating the VIDyA is similar to that of the VMA. The formula can be written as follows:
VIDyA = [P + (a*bv)P_{1} + (a*bv)^{2}P_{2} + … + (a*bv)^{(n-1)}P_{(n-1)}]/ [1 + (a*bv) + (a*bv)^{2} + … + (a*bv)^{(n-1)}]
Where:
P = current price
P1 = price 1 period ago
P2 = price 2 periods ago
a = smoothing constant 2/(n+1)
n = user-defined number of periods for the average
bv = 5 period std dev / 20 period std dev
The VIDyA formula can also be reduced to this:
VIDyA = 2 / (BP +1) * VI * (Close – Previous VIDYA) + Previous VIDYA
Where:
BP = the user bar period for the MA
VI = Volatility Index which is used dynamically to adapt the bar period to a trend.
While VI could be any indicator, Efficiency Ratio is the most used for this purpose
VI = ER = Change / Sum of absolute changes
“Change” is calculated as the change over selected by a user bar period (BP), while “sum of absolute changes” is calculated as the sum of absolute changes of each bar in the selected period.
Why use a VMA?
The VMA or VIDyA automatically regulates its smoothing percentage in accordance with the current market volatility. It doesn’t only help to reduce noise so one can clearly see what the price is doing but also adapts to the prevailing market condition.
The indicator can be used to monitor price trends and individual price swings. Generally, when the price is above the VMA and the LWMA is rising, there is likely an uptrend, and when the price is below the LWMA and the LWMA is pointed down, there is likely a downtrend.
How to use a VMA
Not many trading platforms have a built-in VMA indicator, so you may have to code one yourself or pay someone to do it for you. Once you have your custom VMA indicator, attach it to the chart. You will see the indicator line follow the price trend and swings.
Note that the longer the period you set it, the smoother it is, and the more slowly it reacts to price. So, if you want it to show the long-term trend only, set a high number, say 100 or 200, for the period.
How can you use a VMA?
One of the ways to use the VMA is to identify the direction of the trend. Apart from just identifying the trend, it can also serve as a support level during an uptrend or a resistance level during a downtrend. So, with the help of a reversal candlestick pattern or an oscillator, you can spot when a pullback is about to end for the trend to continue, which could be a good trading signal.
Alternatively, you can use two VMA indicators or combine a VMA with another moving average. In this case, you use a crossover of one moving average over the other as a signal to go long or short as the case may be.
Drawbacks with a VMA
As with any other moving average type, the VMA has its limitations. Some of them are as follows:
- The lag factor: Despite being adaptable, the indicator still lags because it uses past price data in its calculation.
- False signals: The VMA or its other type, the VIDyA, can give multiple false signals. This can be very common when the price is moving randomly without trending in any direction. While the indicator is an improvement on the traditional exponential moving average, you can still have multiple false signals before a significant trend develops.
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:
- Moving average trading strategies
- 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)
- Linear-weighted 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 Variable moving average
We end the article with a few frequently asked questions about the variable moving average:
What is a variable moving average?
A variable moving average (VMA) is a technical analysis tool used to smooth out price data by creating a constantly updated average price. It works by varying the weight assigned to the most recent data points, allowing for more sensitivity to recent price movements than a standard moving average.
A variable moving average is just one of many averages a market technician can use.
How is a variable moving average calculated?
A VMA is calculated by taking the average of the most recent price data, with an emphasis on the most recent price data. The weight assigned to each price data point is determined by a user-defined parameter, which can be adjusted depending on the desired sensitivity. Most trading platforms let you put in data when you attach the variable moving average to your price data.
What are the benefits of using a variable moving average?
Using a VMA can help traders identify potential buying and selling opportunities, as well as identify potential trends. It can also be used to set stop-loss points or identify potential entry or exit points for trades.
Most traders use some form of a moving average crossover system, though.
What are the drawbacks of using a variable moving average?
The main drawback of using a VMA is that it can be overly sensitive to recent price movements, causing traders to enter or exit trades too early or too late – you get whipsawed – something that is pretty common for all moving averages.
Additionally, it can be difficult to set the correct parameters for the VMA, as it is highly dependent on the individual trader’s risk tolerance and trading style. A backtest can determine which average is the best one to use. Keep in mind that the best settings might vary from asset to asset.
Is a variable moving average the same as a weighted moving average?
No, a VMA is not the same as a weighted moving average. A weighted moving average assigns a fixed weight to each data point, while a VMA assigns a variable weight depending on the user-defined parameters.
Variable moving average – takeaways
Our takeaway from the backtests is that variable 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.
FAQ:
How does a Variable Moving Average (VMA) work?
A VMA is an exponential moving average that dynamically adjusts its smoothing percentage based on market volatility, offering improved sensitivity to both short and long-term market conditions. The VMA automatically regulates its smoothing percentage according to market volatility, assigning more weight to ongoing data. This dynamic adaptation helps generate better signals for different market conditions.
What are the key backtest strategies for Variable Moving Average (VMA)?
We conducted four different backtests on the S&P 500, including strategies for buying and selling based on the close of SPY crossing above or below the N-day moving average. The results revealed tendencies for mean-reversion in the short run and trend-following in the long run.
How can I use a Variable Moving Average (VMA) in my trading strategy?
The VMA adjusts to prevailing market volatility, reducing noise and providing a clearer picture of price movements. The VMA can be used to identify trend directions, act as support/resistance levels, and signal potential entry or exit points. Combining it with reversal candlestick patterns or oscillators can enhance its effectiveness.