On the Effectiveness of Moving Averages

Trevor McGuire
12 min readJun 10, 2024

--

In the world of Technical Analysis, moving averages are commonly used for analyzing price. They are employed by traders for various functions, including:

  • Identifying trends
  • Finding support and resistance levels
  • Generating trade signals

Despite their widespread use, their effectiveness remains murky. As such, this post aims to answer the following questions:

  • Can moving averages produce profitable trading signals?
  • Which moving average works best?
  • What is the optimal moving average strategy?

What is a Moving Average?

There are many types of moving averages, and some are more complex than others. However, for our purposes, the most basic type will serve as a good definition. Generally speaking, a moving average is defined as the running mean over some number of previous timesteps. This calculation is often referred to as a Simple Moving Average, or SMA.

Simple Moving Average (SMA)

Not much is known about the origins of the SMA and its relation to finance. This is a testament to how ubiqutous its use has become. However, we do know that the term “moving average” dates back to 1901, and is often credited to English statistician and meteorologist R.H Hooker.

As its name suggests, the calculation for the SMA is easy: at any given timestep, add up the prices from the previous N timesteps and then divide the result by N.

This is done on a “rolling” basis, so all information beyond N periods ago is lost forever (the same is true for all moving averages). For that reason, most people choose to analyze prices by using several different moving averages simultaneously.

Further, the SMA has some issues. Namely, it weighs prices from any number of periods ago equally to the most recent price. This creates a lag between the actual price and the moving average values. This lag is a feature of all moving averages. Likewise, many people have come up with ways to reduce the effect of this lag, with hopes to produce better trading signals.

Exponentially-Weighted Moving Average (EWMA)

Pete Haurlan, who worked for NASA’s Jet Propulsion Labratory (JPL) in the 1960s, is the first known trader to apply exponential smoothing to stock prices. Today, this is commonly referred to as the Exponentially-Weighted Moving Average (EWMA, or sometimes EMA for short).

Prior to employing EWMA’s for trading stocks, Haurlan applied them in rocketry design. Specifically, he used them in the steering mechanism for rockets, in an attempt to smooth out the calculated error between the rocket’s current and desired trajectories. That being said, even though the calculation for the EWMA is more complex than the SMA, it isn’t exactly rocket science.

In a nutshell, the EWMA gives more weight to recent prices. For that reason, its values are always closer to the actual price when compared to an SMA of the same look-back period.

The SMA and EWMA are the two most commen moving averages used to analyze financial markets. Of course, being popular doesn’t mean being useful. Later on in this post, we will determine just how useful they are.

There are a plethora of other moving average calculations out there. For the purposes of this article, however, we will only use the mainstream ones.

Linearly-Weighted Moving Average (LWMA)

The Linearly-Weighted Moving Average is similar to the EWMA in that it weighs recent prices more heavily. However, unlike the EWMA, it does so in a linear fashion. That is, the latest price is multiplied by N (Where N is the look-back window) and the earliest price is multipled by 1. The result is then divided by the sum of all numbers 1 through N.

Because it weighs prices linearly, it lags more than the EWMA, but less than the SMA.

Triangular Moving Average (TMA)

The Triangular Moving Average is unique in that it weighs the middle of the look-back window the heaviest. For this reason, it lags a lot more than its counterparts. It is essentially a doubly-smoothed SMA with two different (but related) window sizes. The calculation can be expressed simply as:

TMA = SMA(SMA(price, N), N // 2)

Above, N is the look-back period. Note that the // operator is performing floor division.

Kaufman Adaptive Moving Average (KAMA)

The Kaufman Adaptive Moving Average, developed by Perry Kaufman, aims to account for volatility. Later on, we will talk about why this is important. The details of this calculation would take a few paragraphs to write about, and I don’t want to bore you anymore than I already have. Instead, I will provide this handy link which lays it out pretty well.

Wilder Moving Average

Developed by Welles Wilder in 1978, this variation also weighs recent prices more heavily, and is therefore faster than an SMA. Like the Kaufman Adaptive Moving Average, the calculation isn’t worth talking about for our purposes.

However, what you should know is this: Welles Wilder is the person responsible for developing several popular technical indicators; the most popular being the Relative Strength Index (RSI). Naturally, he decided to use his own moving average in those calculations. This is often forgotten by people who write Technical Analysis software.

Moving Averages In Practice

As mentioned earlier, moving averages can be used in a lot of different ways — from identifying trends to generating trading signals. But, when it comes to generating signals, which moving average works best?

This question was my motive for writing this article. And to answer it, we must start from the ground up.

So, to start, we’ll briefly compare the different moving averages just described. To do that, I plotted each of the aforementioned moving averages using $SPY and a window of 50 days.

Demonstration of Different Moving Average Types

One takeaway from this chart is that the type of moving average you use is important. To demonstrate this, let’s look at an example.

Shortly after the October 2023 low, we can see that most of the moving averages began to turn upwards — beginning with the KAMA, and followed by the rest. At the time, this should have indicated that the bearish move was losing momentum, thus increasing the risk of a reversal.

However, as you can see, the Triangular Moving Average (TMA) took nearly two months to reverse its direction. This means that if you were solely depending on the TMA as an indicator of market strength, you would have been very late to the party.

When it comes to identifying trends, a single moving average might be all we need. For trading signals, however, it is better to use multiple.

The Moving Average Crossover Strategy

Broadly speaking, a crossover strategy consists of two different moving averages: one faster and one slower. A bullish signal is generated when the faster average crosses above the slower one. A bearish signal, on the other hand, occurs when the when the faster average crosses beneath the slower.

The idea behind this is simple:

  • The faster average represents the shorter-term trend, while the slower average represents the longer-term trend
  • When the faster average crosses beneath the slower, it signals a loss of momentum to the upside, which may lead to a short-term reversal
  • Likewise, when the faster average crosses above the slower, it can be interpreted as a loss of momentum to the downside, which could make it easier for the bulls to regain control

Notice the hesitance in my use of words like could or may. These words reflect the fact that conventional crossover strategies, although tried and tested, aren’t always reliable. We will touch upon a few reasons for this shortly.

The most common types of crossover strategies usually require a 20, 30, or 50 period window for the faster average, and a 50, 100, or 200 period window for the longer average. However, some people want a more frequent trading signal. Among this group, it is common for a 9 or 10 period window to be used.

In terms of which moving average to utilize, the SMA and EWMA are the two most common.

To demonstrate the effectiveness of a moving average crossover strategy, I ran a few tests using the technical-analysis library in python. This is an open-source library I’ve been working on that aims to provide useful utilities for analyzing stock prices. If you’d like to install or contribute, more info can be found here: https://pypi.org/project/technical-analysis/.

Below are the returns of an EMA 20/50 strategy (with 20 being the period for the faster average, and 50 being the period for the slower).

This choice of moving average and period is particularly common. As we can see above, it yielded over 175% over ~170 trades.

However, as previously mentioned, there are many types of moving averages. So, which one works best?

Finding the Optimal Moving Average Crossover Strategy

The optimal crossover strategy really depends on three things:

  1. The size of the window
  2. The type of moving average
  3. The asset in question

The “asset in question” is important for several reasons. First, while some assets are highly volatile, others are not. And because prices can undergo heavy swings in volatile environments, it wouldn’t make sense to rely on the same moving average used in calm, stable ones.

To make matters worse, the volatility of a singular asset, or even the entire market, can rapidly change over time. So, the optimal moving average used for $TSLA 7 or 8 years ago most likely wouldn’t be optimal today. The same can be said for the SPY, BTCUSD, and even the dollar.

To say this differently, volatility itself is volatile. Benoit Mandelbrot, the famed mathematician, related this concept to market time — which is a phrase he used to describe how trading activity isn’t evenly distributed throughout time. To quote directly from his book, The Misbehavior of Markets:

“On occasion, trading is fast. Scores of news items are flitting across the electronic “crawl” on the bottom of the screen. Phones are ringing. Customers are zapping electronic orders. The volume of trades is climbing, and prices are flying by. On such days are fortunes won or lost. Time flies. Then there are the slow times. No news, only tired reports from the in-house financial analysts to chew over. The customers seem to be on holiday. Trading is thin. Prices are quiet. No big money to be made here; might as well go for a long lunch. Time hangs heavy.”

To find out which moving average type performs best, I performed a search over different combinations of moving average types and window sizes. The results of this experiment can be visualized below:

This chart shows the results of the backtests. The data used was historical $SPY daily data ranging from January 1993 until June 2024. The benchmark for this experiment was the buy-and-hold strategy, which yielded 2,057%.

From looking at the chart, we can conclude that the best results occured when using longer look-back periods. Logically, this makes sense, as using a shorter window will increase the frequency of trade signals. The increased number of signals is a product of increased noise, so it decreases the trustworthiness of the signal.

The best performing crossover strategy was the Triangular Moving Average (TMA), which yielded 432% using a 150 day window for the faster average, and a 200 day window for the slower.

It is important to note that even the top-performing strategy couldn’t beat the buy-and-hold benchmark.

Of course, some would argue that maybe “beating the market” isn’t the best metric of success. Depending on your risk appetite, there are other things you may want to consider, too. For instance: how long were you exposed in the market? How much money did you risk losing? Ultimately, how “safe” was your money?

For those who care about risk (which you should), another stat we can interpret is Maximum Drawdown (MDD) — which we can define as the performance of the worst losing trade. There are definitely better, more complicated metrics we could look at. But for our purposes, MDD can act as a cheap proxy for how much downside risk we exposed ourselves to.

Let’s take a look:

As you can see above, the MDD of crossover strategies generally isn’t great. If you’ve ever lost 15–20% on a trade before, you know how that feels. Yet, there were a few exceptions to this, namely the EWMA and TMA strategies with longer look-back windows.

The best performing strategy in terms of MDD was the EWMA 100/150. This strategy’s max-drawdown was +24.4%. I should note that this strategy also yielded the second highest return, at 403%. Given this, one could argue that the EWMA 100/150 is a better stratetgy than the TMA 150/200, as your historical risk-of-loss is lesser.

So, why is it that the best performing strategies (from both a risk-motivated and profit-motivated standpoint) were the ones that utilized longer look-back horizons?

Well, one reason for this is the fact that a longer lookback yields less frequent trading signals. Likewise, less frequent trading signals could mean more time in the market. And, since $SPY has historically had heavy bias to the upside, spending more time in the market has meant a convergence towards the buy-and-hold benchmark strategy (which yielded over 2,000%).

From this we can derive a general truth about moving average crossover strategies: the less we trade, the more we’ll profit. Of course, this assumes a bias to the upside, as we see in $SPY.

We can visualize this below by plotting the the number of trades vs the total return for each EWMA strategy.

In the above, you can see I included the line of best fit, which clearly trends downwards. So, as the number of trades increased, the total return decreased.

To get an overall sense of how the look-back window will affect the number of trades for each moving average type, you can take a look at the below:

To recap:

  • The best performing strategy in terms of both MDD and total return was one that used a longer horizon to produce fewer trades.
  • Despite the positive max-drawdown associated with the best strategy, its total return was substantially lower than our buy-and-hold baseline.

So, can we do any better?

Multiflavored Moving Average Strategies

As previously mentioned, the basic moving average strategy involved two moving averages, one fast and one slow. But who says these two moving averages have to be of the same type?

To test the effectiveness of strategies consisting of multiple types of moving averages, I performed a grid-search across different periods, moving averages, and combinations thereof. In total, there were 1,128 combinations searched. The results can be seen below:

Note that this chart shows only the top ranked strategies.

The best performing strategy utilized a 150-day Simple Moving Average for the faster average, and a 200-day Triangular Moving Average for the slower. This strategy yielded a 466% return with a +20% max drawdown. Notably, it also yielded the highest average return, at 93% per trade. Bear in mind though, that only 5 trades were executed.

Conclusion

Moving averages can be effective tools for risk management. Strategies that employ moving averages can help risk-adverse traders shield themselves from downturns, while still providing sizable upside profits.

However, the profit returned will be substantially smaller (to put it mildly) than the profit returned from a basic buy-and-hold strategy. Of course, this is assuming that the prices of the underlying asset have upward bias over time, as most major stocks do.

It is important to note that the volatility of the stock will also affect how well a moving average strategy works. If a stock is bouncing around, range-bound, then shorter-term moving averages will produce a larger number of faulty signals. Longer-term moving averages, however, are more resiliant to noise, and so the number of faulty signals will remain low. This is another reason why the longer term strategies outperformed the shorter-term ones in the results provided here.

What I’ve shared here only scratches the surface. There are many things we can do improve the moving average crossover strategy; the most important being the underlying moving average used.

All moving averages are lagged indicators. This is inherent in the math behind them, as we need to use the previous N values to calculate the current value. Ideally, we want to reduce this lag in order to create more signals to profit from. However, there is a trade off between the lag used and the resulting noise of the signal. So, in order to improve this strategy, you need to find ways to optimize the balance between lag and noise.

In the future, I plan to share some custom moving averages I’ve created that produce significantly better results than the traditional ones decribed here.

The notebook for this post can be found here, if you’d like to replicate these results. In the code, you will notice that the technical-analysis library did all the heavy lifting, including the backtesting and strategy creation! If you’d like to install this library, or if you’d like to contribute, check out the links the below:

Jupyter Notebook for this post:

Thanks for reading.

--

--