Moving-average crossover: the golden cross, formula and example

On this page

Key takeaways

  • A moving average is the average closing price over a fixed number of past days. It smooths out daily noise and follows the price at a delay, so a short average turns sooner than a long one.
  • The rule is invested while the short average is above the long one and in cash otherwise. The golden cross compares the 50-day and 200-day averages; comparing the price itself with its 200-day average is a faster version of the same idea.
  • Because both averages follow the price at a delay, the rule gets in after a rise is under way and gets out after a fall has started. It sidesteps long, slow bear markets and gives back part of every sharp rebound.
  • On stock indexes its usual effect has been a shallower worst fall rather than faster growth, and how much growth it gave up depends heavily on the years tested and on what cash earned.
  • MarketHeist compares the two averages directly each day: invested while the short one is above the long one, in cash otherwise.

Definition

A moving-average crossover rule compares two simple averages of past closing prices, a short one and a long one, and holds the asset while the short average is above the long one. The most widely watched version, the golden cross, uses the 50-day and 200-day averages; the short average falling back below the long one is called a death cross.

Also known as: golden cross, death cross, SMA crossover, 50/200 crossover, dual moving average crossover, 200-day moving average, price above moving average, simple moving average.

How it works

A simple moving average adds up the last so many closing prices and divides by their number. Each day the oldest price drops out and the newest comes in, so the average drifts with the price but ignores its day-to-day wiggles. The price of that smoothing is delay: an average of n days is centred about half its length in the past, so a 200-day average describes where the price was, on balance, a few months ago.

A crossover rule compares a short average with a long one. When the price has been rising for a while, the short average, which reflects recent prices, sits above the long one; when it has been falling, below. Holding the asset only while the short average is on top is a way of following the trend that ignores short dips. The golden cross is the version with the 50-day and 200-day averages, and its signals are reported in the financial press when they happen; the faster version compares the price itself with its 200-day average.

A moving-average crossover is like judging whether a road climbs by comparing where you were a week ago with where you were a season ago: it gets the long slopes right and notices every bend late.

The delay sets both the benefit and the cost. In a long decline, such as the slide from late 2007 to early 2009, the short average crosses below the long one early enough to miss much of the fall. In a fast crash and rebound the rule exits near the bottom and re-enters after the recovery has begun, and in sideways markets the averages cross back and forth, each round trip selling lower and buying higher. Those false signals are whipsaws.

The two lengths are a trade-off. Shorter averages react sooner and whipsaw more; longer ones whipsaw less and react later. The single-average version, the price against its 200-day average, sits at the fast end and trades several times as often as the golden cross. Neither is tuned to any particular market: the lengths are conventions, which is why MarketHeist's robustness pages test the neighbouring lengths too.

Formula

Simple moving average and the crossover signal
SMAn(t)=1n∑k=0n−1Pt−k,st=SMAa(t)SMAb(t),pt={1st>10otherwise
Pₜ
adjusted closing price on day t
n
the average's length in days, day t included
a, b
the short and long lengths (50 and 200 for the golden cross; a = 1 uses the price itself)
sₜ
the signal: short average divided by long average
pₜ
the position decided at day t's close, held from the next bar by the execution delay

sₜ > 1 exactly when the short average is above the long one, so the ratio and the difference of the averages give the same decisions. A golden cross is the day sₜ rises through 1; a death cross the day it falls through 1.

The exponential option
EMAn(t)=∑i=0t(1−α)t−iPi∑i=0t(1−α)t−i,α=2n+1
α
the weight on the newest price
i
day index from the first day of data (i = 0)

With the moving-average type set to EMA, both averages are exponential; see the EMA crossover guide.

Worked example

SPY's daily bars from Oct 2006 to Sep 2026, about 20 years, with the golden cross: hold SPY while its 50-day simple moving average is above its 200-day one, otherwise cash, acted on with the standard one-bar delay, no trading costs and no interest on cash.

The golden cross was invested on 78.5% of days and completed 9 round trips, about 0.5 a year. Its worst decline from a peak was -33.7%, much shallower than the -55.2% of holding SPY, and its volatility was lower too: 14.0% against 19.4%.

The price of that protection was growth: 9.3% a year against 11.1%, so $10,000 became $58,998 instead of $82,292. Both averages follow the price at a delay, so the rule left late in each decline and came back late in each recovery, after part of the rebound had already happened.

The faster version, the price against its 200-day average, reacted sooner and paid for it in whipsaws: 56 round trips against 9, with 25.0% of trades ending in a gain against 77.8% for the golden cross. With exponential averages of 50 and 200 days, the rule made 10 round trips and grew 7.9% a year.

These figures cover one window with no costs and cash at zero. The golden cross robustness page runs the rule on SPY since 1993 with trading costs and interest on cash and tests every nearby pair of lengths; the 200-day moving average page does the same for the single-average rule.

Data through Sep 2026. Reproduce id fcd7d9e21f3bb124 (this guide, its lab setup and the data month).

Interactive lab

SPY's price with its 50-day and 200-day averages, the days invested shaded and every cross marked, and the results table for the golden cross, the price against its 200-day average and the exponential version beside buy-and-hold. Change the lengths, the average type, the cost, the delay or the fund.

SPY price with the days the base rule held itS&P 500, adjusted daily close, Oct 2006 to Sep 2026, log scale. Shaded: the 10 stretches the base rule held the fund (79% of 5030 days). Also drawn: 50-day simple average, 200-day simple average.$50$100$200$50020062011201620212026SPY adjusted close50-day simple average200-day simple averageHeld by the base ruleEntryExit
SPY on a log scale. Shaded: the days the base rule held the fund. Oct 2006 to Sep 2026.
Short / long average ratio with the base rule's lineShort / long average ratio on SPY, Oct 2006 to Sep 2026. The rule compares it with the fixed line 1.0.80.850.90.9511.051.11.15200620112016202120261Short / long average ratio
Short / long average ratio and the line the base rule compares it with. Oct 2006 to Sep 2026.
Growth of $10,000: the setups against buy and holdS&P 500, Oct 2006 to Sep 2026, log scale. $10,000 grows to $58,998 (base), $56,592 (Price above its 200-day average), $45,424 (Exponential 50/200), $82,292 (buy and hold).$10k$20k$50k20062011201620212026Base rulePrice above its 200-day averageExponential 50/200Buy and hold
Growth of $10,000 on a log scale, same days for every line. Oct 2006 to Sep 2026.
MeasureBasePrice above its 200-day averageExponential 50/200Buy and hold
CAGR9.3%9.1%7.9%11.1%
Volatility (annualized)14.0%11.7%14.1%19.4%
Maximum drawdown-33.7%-20.7%-33.9%-55.2%
Sharpe ratio0.710.800.610.64
Sortino ratio0.981.090.83n/a
Growth of $10,000$58,998$56,592$45,424$82,292
Time in the market78.5%79.3%82.2%100.0%
Round trips95610n/a
Round trips per year0.52.80.5n/a
Win rate77.8%25.0%70.0%n/a
Average win28.6%18.2%25.7%n/a
Average loss-7.2%-1.5%-8.4%n/a
Payoff ratio3.9612.433.05n/a
Average days held403.769.1379.0n/a
Expectancy per trade20.6%3.5%15.5%n/a
Profit factor, per day1.161.171.131.13
Profit factor, per trade13.874.147.12n/a
Indicator, last day1.0631.0651.055n/a
Indicator, 10th / 50th / 90th percentile0.959 / 1.045 / 1.090.944 / 1.063 / 1.1210.975 / 1.042 / 1.071n/a
Days the rule alone is long78.5%79.3%82.2%n/a

S&P 500, Oct 2006 to Sep 2026, 5030 trading days. Every setup is measured over the same days, with the indicator warmed up on earlier ones; cash earns 0. Base: MA Crossover (short window 50, long window 200, ma type SMA); long while the Short / long average ratio is above 1; execution delay 1; cost 0 bps one way. Price above its 200-day average: MA Crossover (short window 1, long window 200, ma type SMA); long while the Short / long average ratio is above 1; execution delay 1; cost 0 bps one way. Exponential 50/200: MA Crossover (short window 50, long window 200, ma type EMA); long while the Short / long average ratio is above 1; execution delay 1; cost 0 bps one way.

Buy and hold, same daysValue
Largest one-day gain14.5% on 13 Oct 2008
Largest one-day loss-10.9% on 16 Mar 2020
CAGR without the 10 largest gains6.6%
CAGR without the 30 largest gains1.8%
CAGR without the 10 largest losses16.0%
CAGR without the 30 largest losses22.1%

The days replaced by 0 are the largest daily gains (or losses) of the window.

How MarketHeist computes it

Every choice an implementation has to make, as the code makes it today. The page is checked against the code each time it is built.

ChoiceHow it is computedIn the code
DataDaily bars (open, high, low, close, volume) of the fund as the MarketHeist data service serves them to the backtester: prices adjusted for splits and dividends, so a dividend counts as reinvested. They come from a snapshot taken each month and cut at the data month of this page, and are not rounded. The fund's own history, not an extension: a fund younger than the window is measured over the years it has.
WindowThe worked example and the lab measure the last 20 years of trading days, Oct 2006 to Sep 2026 (5030 days), ending at the data month of this page. Every setup, and buy and hold, is measured over exactly these days; an indicator is warmed up on the days before them, so changing a setting never moves the window, and a setting that needs more history than exists before the window is refused rather than measured over fewer days.
BacktestThe backtester's own engine, in the order it runs it: the indicator, the position rule (or entry and exit triggers) and the optional regime filter produce a position for every day of the fund's whole history; the position is then shifted forward by the execution delay and applied to each day's return over the window. Cash earns 0, there is no leverage, and a one-way cost in basis points is charged on the size of every change of position. Round trips are the closed entries of the trade log (a trade still open on the last day is not counted); the win rate is the share of them with a gain; the payoff ratio is the average win over the size of the average loss; expectancy is the average return per trade; the per-trade profit factor is the sum of the winning trades' returns over the size of the sum of the losing ones, while the per-day profit factor sums days.
Years and volatilityA year is 252 trading days, the engine's convention: trades per year is round trips over days divided by 252, the CAGR is the growth multiple to the power 252 over the days, and volatility is the sample standard deviation of the daily returns times the square root of 252.
Indicator statisticsThe indicator's main output over the window: its last value, its 10th, 50th and 90th percentile (linear interpolation between ranks), and the share of days the rule alone says long, before the delay and any regime filter. Every output of the indicator is also summarized by its median and the share of days below 0.
Buy and holdThe fund held every day of the window with dividends reinvested. The largest one-day gain and loss are the highest and lowest daily returns; the CAGR without the 10 or 30 largest gains (or losses) replaces those days' returns with 0 and recompounds.
SignalShort moving average ÷ long moving average of the adjusted close. Undefined until the long window is full; the backtest starts with that warm-up already behind it.computepackages/shared/engine/indicators/ma_crossover.ts
Simple averageMean of the last n closes, today's included; defined only when all n are present (as pandas rolling mean with min_periods = n).smapackages/shared/engine/utils.ts
Exponential optionWith ma_type EMA, pandas ewm(span = n).mean() with adjust = True: weights (1 − α)ᵏ, α = 2 ÷ (n + 1), normalised over all data so far, with no simple-average seed. A short length of 1 uses the raw price.emapackages/shared/engine/utils.ts
RuleThreshold 1, direction above: invested when the ratio is strictly above 1. The position is applied with the execution delay (1 bar by default), so a cross at today's close earns from that close onward.generatePositionpackages/shared/engine/positions.ts
Backtester defaults10 and 52 bars with simple averages, which on the backtester's default weekly bars mean ten weeks and a year. On daily bars the golden cross is 50 and 200; the lengths range from 1 to 200 (short) and 4 to 400 (long).SPECpackages/shared/engine/indicators/ma_crossover.ts
Engine functionsThe functions the portfolio app and the MarketHeist MCP tools run, called here on the same monthly returns.computePositionpackages/shared/engine/run_basic.tsgeneratePositionpackages/shared/engine/positions.tsapplyRegimeFilterpackages/shared/engine/regime_filter.tsgenerateTriggeredPositionpackages/shared/engine/triggered_position.tsrunBacktestpackages/shared/engine/backtest.tsgetIndicatorpackages/shared/engine/indicators/registry.ts

Moving-average crossover (golden cross) compared with its neighbours

Moving-average trend rules compared
RuleComparesSpeedWhipsaws
Price vs 200-day averageDaily close with its 200-day simple averageFast exits, fast re-entriesMany, around every test of the average
Golden cross (50/200)50-day with 200-day simple averageSlowFew
EMA crossover 12/26 (MACD line)12-day with 26-day exponential averageFastMany
10-month trend filterMonth-end value with its 10-month averageChecked once a monthFew, but each costs a month
Time-series momentumPrice with its level a year earlierSlowFew

Limitations

  • The rule's record rests on a few large declines. Over two decades only a handful of trends decide the result, so one window is one draw from a small sample.
  • Fast crashes defeat it. When a market falls and recovers within weeks, the long average reacts after the fall and the rule re-enters after the rebound.
  • The example charges no trading costs and pays nothing on cash. The robustness pages add both; in years of high interest rates, cash makes the months out of the market less costly.
  • Taxes are ignored. In a taxable account every exit can realise a gain.
  • The lengths are conventions, and choosing them after looking at a backtest is overfitting; check that nearby lengths behave alike before trusting any one pair.

Frequently asked questions

What is a golden cross and a death cross?
A golden cross is the day a short moving average, usually the 50-day, rises above a long one, usually the 200-day. A death cross is the opposite, the short average falling below the long one. As a rule, holding the asset from a golden cross to the next death cross is the 50/200 crossover strategy.
Is the golden cross the same as the 200-day moving average rule?
No. The 200-day rule compares the price itself with its 200-day average, so it reacts within days and whipsaws more. The golden cross compares two averages, which smooths the price first, so it trades far less and reacts later.
Does the golden cross beat buy-and-hold?
On stock indexes it has mostly reduced the worst drawdowns and given up some growth, with the outcome depending on the period and on the interest earned on cash. The golden cross robustness page gives the verdict on SPY with costs, cash and nearby lengths, and pages for QQQ, TLT, GLD and EFA do the same.
Why does MarketHeist use the ratio of the averages instead of their difference?
The ratio is above 1 exactly when the difference is above 0, so the trades are the same. The ratio has the advantage of being scale-free: it reads the same for a fund priced at ten or at five hundred, so one threshold works for every asset.
Simple or exponential moving averages for a crossover?
Exponential averages give more weight to recent prices, so for the same lengths they turn sooner and trade a little more. Neither type is better in general; the choice is part of the rule, and both are available in the backtester.

References

  1. Brock, W., Lakonishok, J. and LeBaron, B. (1992) Simple Technical Trading Rules and the Stochastic Properties of Stock Returns. Journal of Finance 47(5). Moving-average rules, including 50/200 and price against the 200-day average, on the Dow Jones index.
  2. Siegel, J. J. (1994) Stocks for the Long Run. McGraw-Hill. The 200-day moving-average rule with and without transaction costs.
  3. Faber, M. T. (2007) A Quantitative Approach to Tactical Asset Allocation. Journal of Wealth Management 9(4). The monthly 10-month moving-average version.
  4. Murphy, J. J. (1999) Technical Analysis of the Financial Markets. New York Institute of Finance. Moving averages and crossover systems.

Try it on your own holdings

Open the golden cross on SPY in the backtester →

Or ask an assistant connected to the MarketHeist MCP server (https://marketheist.io/mcp), which computes the same figures:

Using MarketHeist.io, backtest the golden cross on SPY daily bars (ma_crossover, short window 50, long window 200, simple averages, threshold 1.0, execution delay 1) and compare CAGR, max drawdown, volatility and number of trades with buy-and-hold and with the price-above-200-day-average rule.

Ask an AI assistant

The prompt opens in a new tab, already filled in. An assistant without the MarketHeist connector answers from its own knowledge, not from the figures on this page.

Historical simulation, not advice. Computed by the MarketHeist portfolio engine from monthly total returns, data through Sep 2026. Markdown version of this page: moving-average-crossover.md.