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

Canonical URL: https://marketheist.io/portfolio/learn/moving-average-crossover
By Jeffrey Lin · Published 2026-11-18 · Updated 2026-11-18 · Data through Sep 2026
Category: Indicators

## 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**

```
SMA_n (t) = \frac{1}{n} \sum_{k = 0}^{n - 1} P_{t - k}, s_t = \frac{SMA_a (t)}{SMA_b (t)}, p_t = {\begin{pmatrix} 1 & s_t > 1 \\ 0 & otherwise \end{pmatrix}
```

where:

- 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**

```
EMA_n (t) = \frac{\sum_{i = 0}^t (1 - \alpha)^{t - i} P_i}{\sum_{i = 0}^t (1 - \alpha)^{t - i}}, \alpha = \frac{2}{n + 1}
```

where:

- α: 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).

## How MarketHeist computes it

- **Data**: Daily 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.
- **Window**: The 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.
- **Backtest**: The 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 volatility**: A 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 statistics**: The 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 hold**: The 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.
- **Signal**: Short 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. (`compute` in packages/shared/engine/indicators/ma_crossover.ts)
- **Simple average**: Mean of the last n closes, today's included; defined only when all n are present (as pandas rolling mean with min_periods = n). (`sma` in packages/shared/engine/utils.ts)
- **Exponential option**: With 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. (`ema` in packages/shared/engine/utils.ts)
- **Rule**: Threshold 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. (`generatePosition` in packages/shared/engine/positions.ts)
- **Backtester defaults**: 10 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). (`SPEC` in packages/shared/engine/indicators/ma_crossover.ts)
- **Engine functions**: `computePosition` (packages/shared/engine/run_basic.ts), `generatePosition` (packages/shared/engine/positions.ts), `applyRegimeFilter` (packages/shared/engine/regime_filter.ts), `generateTriggeredPosition` (packages/shared/engine/triggered_position.ts), `runBacktest` (packages/shared/engine/backtest.ts), `getIndicator` (packages/shared/engine/indicators/registry.ts)

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

Moving-average trend rules compared

| Rule | Compares | Speed | Whipsaws |
| --- | --- | --- | --- |
| Price vs 200-day average | Daily close with its 200-day simple average | Fast exits, fast re-entries | Many, around every test of the average |
| Golden cross (50/200) | 50-day with 200-day simple average | Slow | Few |
| EMA crossover 12/26 (MACD line) | 12-day with 26-day exponential average | Fast | Many |
| 10-month trend filter | Month-end value with its 10-month average | Checked once a month | Few, but each costs a month |
| Time-series momentum | Price with its level a year earlier | Slow | Few |

## 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 <https://papers.ssrn.com/sol3/papers.cfm?abstract_id=962461>. 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

App: https://marketheist.io/backtest/?c=eyJ0aWNrZXIiOiJTUFkiLCJmcmVxdWVuY3kiOiIxZCIsImluZGljYXRvcl9pZCI6Im1hX2Nyb3Nzb3ZlciIsImluZGljYXRvcl9wYXJhbXMiOnsic2hvcnRfd2luZG93Ijo1MCwibG9uZ193aW5kb3ciOjIwMCwibWFfdHlwZSI6IlNNQSJ9LCJwb3NpdGlvbl9ydWxlIjp7InR5cGUiOiJ0aHJlc2hvbGQiLCJ0aHJlc2hvbGQiOjEsImRpcmVjdGlvbiI6ImFib3ZlIn0sImV4ZWN1dGlvbl9kZWxheSI6MSwidHJhbnNhY3Rpb25fY29zdHNfYnBzIjowLCJsZXZlcmFnZSI6eyJtb2RlIjoibm9uZSJ9fQ

MCP prompt (MarketHeist MCP server, https://marketheist.io/mcp):

```
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.
```

Historical simulation, not advice.
