Moving Average CrossoverOctober 19, 202613 min read

Moving Average Crossover Backtest: What the Data Shows

How to backtest a moving average crossover or golden cross honestly: rules, costs, look-ahead bias, out-of-sample checks and what a real result looks like.

Moving Average Crossover Backtest: What the Data Shows

A moving average crossover backtest answers one question: if you had bought when a faster average crossed above a slower one and sold when it crossed back, would you have beaten simply holding? Often the answer is no. The crossover can work in long, clean trends. It tends to lose to costs and whipsaws when the market chops sideways. This guide shows how to run the test so the answer is believable, including the golden cross (50-day over 200-day) that most people search for.

TL;DR

  • A crossover buys when a short average moves above a long one and exits on the reverse. It is a lagging, trend-following rule, so it needs trends to pay.
  • The two most common errors are trading on the same bar that generates the signal (look-ahead bias) and ignoring fees and slippage. Both flatter the result.
  • Testing many fast/slow pairs and keeping the winner is data snooping. Hold back 30% of your data, or use walk-forward testing, before you trust any pair.
  • Judge the result against buy-and-hold, with drawdown and trade count beside the return, not return alone.
  • The golden cross fires rarely, so a single index often gives too few trades to prove anything.

Table of Contents

What you are actually testing

A crossover rule has three parts: the type of average (simple or exponential), the two lookback lengths, and the action on each cross. The classic versions are 10/50 for shorter-term swings and 50/200 for the golden cross (long entry) and death cross (exit). Another form uses price crossing a single average.

Write the rules down before you touch any data. For example: "Go long at the next open after the 50-day simple average closes above the 200-day. Exit at the next open after it closes below. Long only, one position, no leverage." If the rule can be read two ways, the backtest will quietly pick the flattering one.

Three choices decide a lot of the outcome:

  • Market and period. A test on an index that trended for years looks nothing like one on a flat commodity. Pick the market you would actually trade.
  • Bar size. Daily bars give few signals. Hourly bars give many, and costs grow with them.
  • Long only or long and short. Shorting adds borrow costs and different risk, so test it separately.

Step by step: running the backtest

  1. Get clean data. Use adjusted prices for splits and dividends if you test stocks or ETFs. Include delisted names if you test a basket, or you will inherit survivorship bias.
  2. Compute both averages from closing prices up to and including the signal bar only.
  3. Generate the signal on the close, trade on the next open. This one rule matters more than any parameter choice. More on it below.
  4. Charge costs on every trade: commission, spread and slippage.
  5. Record every trade, not only the equity curve: entry, exit, return, days held.
  6. Compare with buy-and-hold over the same dates, and report max drawdown, profit factor, win rate and trade count.
  7. Validate on data you did not use to choose the settings.

If you want the long version of this workflow for any strategy, our step-by-step guide to backtesting a trading strategy covers the whole process.

The look-ahead trap in crossover tests

Crossovers are especially prone to a quiet mistake. The signal is only known after the bar closes. If your code buys at that same close, you have used information you did not have when the order would have been placed. One public write-up of a 10/50 crossover on SPY describes that shifting the signal one day forward usually shows the earlier backtest was 2 to 3 times too optimistic. Treat that as one author's finding, not a universal constant, but the direction is reliable.

A simple self-check: delay every entry and exit by one bar. If performance collapses, the edge was the timing leak. We list four fast tests in our piece on exposing look-ahead bias in quant backtests.

Costs: the quiet killer of frequent crossovers

A slow golden cross trades a few times a decade, so costs barely register. A 10/50 or an intraday 9/21 trades often, and each round trip pays the spread, commission and slippage. One practitioner guide suggests assuming fills 0.1% to 0.5% worse than your signal price as a starting assumption, and another suggests modeling costs at 1.5 times the level you expect to test whether the strategy survives being wrong about them.

There is a concrete public example. An open-source Python test of a 20/50-day crossover on SPY from 2015 to 2024, with a 0.1% cost per trade, reported about +77.5% for the strategy against +172% for buy-and-hold, with 43 trades. Its max drawdown was smaller (-29.6% against -33.7%), which is the usual trade: a little less pain, a lot less return. It is a hobbyist project, so read it as an illustration of the shape of results, not as a benchmark.

SPY crossover returns and drawdowns compared

Why the best fast/slow pair is probably an illusion

Say you test every fast length from 5 to 50 and every slow length from 20 to 250. Some pair will look wonderful. That does not mean it has an edge. One overfitting explainer puts it plainly: you try 20 days, then 19, then 21, and at some length you get a 28% annual return by luck of the draw. Every extra pair you try is another chance to find noise.

One parameter pair stands out from many

The academic record on this exact rule family is a good lesson. The early study by Brock, Lakonishok and LeBaron in 1992 gave strong support to moving average rules. When Sullivan, Timmermann and White corrected for data snooping and re-ran the tests over longer periods, the performance did not carry into later decades. Their own framing of the earlier work is that some moving average rules will work by design of the search, but the dangers of data snooping are immense.

How to protect yourself

Golden cross: how to read the result

The golden cross is the 50-day average crossing above the 200-day. Its appeal is simplicity and a long history, and it is often discussed as a sign of a new uptrend. Backtesting it raises two practical problems.

Few trades. On daily bars of one index, a 50/200 system might fire a handful of times per decade. Ten trades cannot separate skill from luck. One guideline suggests at least 5 years of daily history or around 500 completed trades for daily strategies. A golden cross on one market will rarely reach 500 trades, so widen the test across many markets and periods, and be honest in your write-up that confidence is limited.

Lag. By the time the 50 crosses the 200, much of the move is behind you. That is the structural weakness of the rule. It tends to do well when an asset enters a strong, sustained trend and badly in sideways or sharply reversing markets, where whipsaws generate costs. Its value is often in avoiding the worst of big bear markets, not in beating the index on raw return. So measure drawdown and time in market, not just total return.

What to put in your results table

Return alone hides the story. For each version you test, record this:

MetricWhy it matters for a crossover
Net return vs buy-and-holdThe only fair benchmark for a long-only trend rule
Max drawdownThe reason most people use a crossover at all
Profit factorGross wins divided by gross losses; shows whether a few big trends carry the system
Win rateTrend systems often win under half their trades and rely on a few large winners
Number of tradesTells you whether the other numbers mean anything
Average trade after costsShows whether costs eat the edge
Out-of-sample vs in-sampleThe overfitting check

A low win rate is not a flaw in a trend rule. A low profit factor combined with a high trade count usually is: it signals a whipsaw machine.

Our perspective

We built Backtestify because most trading claims are never checked against real history. The crossover is the perfect case study. It is easy to code, easy to believe in, and easy to overfit, so people usually see its best version on a chart and never the average one.

What we have learned from reading hundreds of strategy tests is this. First, the signal bar and the fill bar must be different, or nothing else matters. Second, a rule should be judged against the boring alternative, holding the asset, on the same dates and with costs charged. Third, a result is only worth sharing if the losing versions are shared next to the winning ones. That is why we publish results for strategies that fail as well as those that pass, and why we compare an original rule against an improved version on recent data rather than quietly replacing one with the other.

Our view on the crossover itself: treat it as a risk-management tool first and a return engine second. If it passes out-of-sample, with realistic costs, across more than one market, it earns a place. If it only wins on one pair on one chart, it is a story, not a strategy.

— WAJDI

Running this test on Backtestify

You can describe a crossover in plain English, such as "buy when the 50-day SMA crosses above the 200-day SMA, exit on the reverse", and get a trade-by-trade report with win rate, profit factor and max drawdown. Our methodology page explains how we simulate fills, and the published strategy library shows how reports look for well-known setups, including a moving-average pullback and the Turtle System 1 trend rules.

The Free plan lets you start. Pro, which unlocks unlimited backtesting, improvement and forecasting, costs $29 per month or $190 per year, and you can see both on the Backtestify home page.

Common mistakes checklist

  • Trading at the same close that created the signal.
  • Zero fees and zero slippage. A conservative reference for liquid assets is 20 to 50 basis points per round trip, and 100 or more for small caps.
  • Choosing the best pair from a grid and reporting only that one.
  • Reporting a test with fewer than 30 trades as proof.
  • Ignoring survivorship bias when testing a basket of stocks. This is the kind of data bias that quietly ruins equity research.
  • Skipping forward testing. After a backtest passes, forward test it in real time with small size.

If your crossover will run on options or forex, the same hygiene applies, and these guides cover instrument-specific safeguards: a practical guide to backtesting options strategies and a forex backtesting workflow from charting platform to demo account.

FAQ

Does a moving average crossover beat buy-and-hold?

Usually not on raw return, especially in markets that rise for long periods, because the rule sits in cash during parts of the rally and pays costs on every switch. The public SPY example above shows that pattern. Where crossovers can help is in cutting drawdown during prolonged declines, so judge both numbers.

What is the best moving average pair for a crossover?

There is no pair that works everywhere, and the one that looks best on past data is the one most likely to be overfit. Pick a small set with a reason, such as 20/50 or 50/200, and validate on data held out from development. If only one pair works and its neighbors fail, treat it as noise.

Is the golden cross a reliable buy signal?

Treat it as a trend filter, not a prediction. It fires rarely and late, so one market often yields too few trades to prove anything. Test it across several markets and decades, charge costs, and look at drawdown as well as return.

Should I use simple or exponential averages?

Test both with the same rules and costs. Exponential averages react faster, which means earlier entries and more whipsaws. If the results differ only slightly, choose the simpler one, since fewer moving parts leave less room to overfit.

Sources