The Test Bench › Moving averages

Moving Average Trading Strategy: Crossovers, the 200-Day Average, and What Our Tests Found

How SMAs, EMAs and crossover rules work, and what our historical tests found on S&P 500 stocks.

A moving average smooths the price and follows it with a delay. Traders use it to judge the trend, and to build rules that buy as the price strengthens and sell as it weakens. Trading rules compare two lines: the price against an average, or a fast average against a slow one. In a common crossover rule, the strategy buys when the faster line crosses above the slower one and sells when it crosses back below. The length of the averages decides how early, and how often, that happens; in a market moving sideways, the lines can cross back and forth within days.

This page covers:

A moving average shows the trend, a little lateEach day it averages the last n closes, so it follows the price with a delay: a 9-day average closely, a 200-day one slowly.Traders often read a price above a rising average as an uptrend, and a price below a falling one as a downtrend.Every moving-average rule compares two lines: the price and an average, or a fast average and a slow one.
Crossover rules follow trends, with a delayThey buy after a rise has started and sell after a fall has started.They give up the first part of each move; in return they can step aside for part of a long decline.They can struggle in sideways markets, where the lines cross back and forth.
Longer averages usually signal later and less oftenA long average crosses the price rarely; a short one crosses often.Fast signals catch moves earlier and reverse more often; those reversals, called whipsaws, are each a trade with its cost.The length of the averages sets the trade-off between speed and noise.

How is a moving average calculated?

A simple moving average (SMA) adds the last n closes and divides by n. An exponential moving average (EMA) starts from yesterday’s EMA and moves it towards today’s close by a fixed share, 2 ÷ (n + 1). Six invented closes show both, with n = 5:

ValueHow
Closes20, 21, 22, 21, 23, 25Six days, oldest first
5-day SMA on day 521.40(20 + 21 + 22 + 21 + 23) ÷ 5
5-day SMA on day 622.40(21 + 22 + 21 + 23 + 25) ÷ 5
5-day EMA on day 622.6021.40 + 0.33 × (25 − 21.40), starting from the day-5 SMA

On the jump to 25, the EMA moved 1.20 and the SMA 1.00: the new close gets a third of the weight in this update (k = 2 ÷ 6 ≈ 0.33), against a fifth in the SMA. This example starts the EMA from the day-5 SMA; platforms start it in different ways (GU Analyser starts it from the first close of the history); the starting value’s influence decays with each new close, and how long the early values differ depends on the platform and the period.

Simple and exponential averagesinvented pricesClose20-day SMA20-day EMA
Invented prices. The EMA gives the newest closes more weight, so it turns sooner than the SMA of the same length.

Moving average crossover rules

Three common crossover rules on daily charts:

SignalFast lineSlow lineCommon use
Golden cross / death cross50-day SMA200-day SMALong-term trend, months to years
The 200-day averageThe close200-day SMALong-term trend filter; Faber’s timing rule
9/21 EMA crossover9-day EMA21-day EMAShort-term swings, weeks
Golden cross and death crossinvented pricesClose50-day average200-day averageDEATH CROSSGOLDEN CROSS
Invented prices. In this example each cross follows the turn by several weeks; the delay varies with the price path.

Each signal can be read two ways. As an event, it asks what usually followed the day it fired. As a rule, it holds the stock while the fast line is above the slow one and sells when it drops below, which is how a backtest uses it.

Trend following vs mean reversion

Moving-average rules are trend following: they buy after a rise has started and expect it to continue. Mean reversion does the opposite and buys after a fall. Breakouts to new highs, as in our Donchian study, are another trend-following family.

Trend following (moving averages)Mean reversion
Typical entryAfter a rise has startedAfter a fall
Typical holdOften weeks to yearsOften days
Common return patternCan rely on a few large gainsCan rely on frequent smaller gains
Main riskRepeated losses in choppy marketsA fall that keeps going instead of rebounding
Main attractionStaying in long trends and stepping aside for part of long declinesCatching rebounds after sharp falls

The risks of moving average strategies

The signals, explained

Our moving average tests

How to read these results. An event study compares the days after a signal with ordinary days of the same stocks; a backtest runs one complete rule with costs and reports a median total return per stock over the whole period; the two answer different questions. “Clear” is our own rule: the 95% interval excluded zero under every test setting we ran, which is not proof that a gap will last. All tests use today’s S&P 500 members projected back, which can flatter strategies that hold through deep falls, such as buying and holding (see survivorship bias in backtesting), and price returns without dividends.

For the opposite approach, see our mean reversion backtest.

Common questions

What is a moving average in trading?

The average of the last n closing prices, recalculated every day, so it moves with the price. It smooths out day-to-day noise and shows the direction of the trend. The 20-, 50- and 200-day averages are among the most commonly used on daily charts.

What is the difference between an SMA and an EMA?

A simple moving average (SMA) gives each of the last n closes the same weight. An exponential moving average (EMA) gives the newest closes more weight, so it turns sooner after the price changes direction.

What is a moving average crossover strategy?

A rule that buys when a faster moving average crosses above a slower one and sells when it crosses back below. The same idea is used with the price itself as the fast line, as in a close above the 200-day average.

Which moving average is best for trading?

There is no single best length. Longer averages give fewer, later signals and suit long-term trends; shorter ones react faster and give more signals that reverse soon after. The 50/200 pair, the 200-day line and the 9/21 EMA pair are common examples.

Do moving average crossovers work?

In our event studies, none of the three signals was followed by a clear difference from ordinary days. That does not prove every moving-average rule fails: these signals, horizons and stocks showed no clear difference under our rule. In our backtest of the three rules, buying and holding had the higher median total return per stock (+361%, against +137% for the best rule), and the rules’ deepest falls were somewhat smaller; on SPY the 200-day rule cut the deepest fall to −22% against −56%.

What is trend following?

Buying what is rising and selling what is falling, on the expectation that a move continues for a while. Moving-average rules, breakouts to new highs and momentum ranking are the common forms.

What is a whipsaw?

A signal that reverses soon after it fires: the price crosses above its average, then back below within days. Whipsaws are a major problem for fast moving-average rules: each one can be a losing round trip, and each pays trading costs.

Why do moving average rules lag?

An average of past prices can only change after the prices have changed, so a crossover always comes after the move has started. The longer the average, the longer the delay.

Can you backtest a moving average strategy without code?

Yes. In GU Analyser you add the averages, set the crossover as the buy and sell rule on a visual canvas and run a backtest or an event study on daily bars.

Want to test your own moving average rule?

Choose the averages and the crossover, then measure what followed the signal across your stocks, or backtest the rule with a cost on each trade.

Create a free account and build your own strategies → or read how to backtest a strategy without code →

The methods: how a backtest is built · how an event study works

These are historical analyses. They are neither advice nor forecasts. They describe what happened on past data under stated, simplified assumptions. Past results do not prove what will happen next, and nothing in the Test Bench is a recommendation to buy or sell an investment. GU Analyser is an analytical and educational tool — no money is ever traded here.