The 50/200 moving-average crossovers behind endless headlines — precisely defined, easy to code, and lagging by design.
A golden cross occurs when a shorter-term moving average — by convention the 50-period simple moving average — crosses above a longer-term one, conventionally the 200-period SMA. A death cross is the mirror event: the 50 crossing below the 200. Despite the dramatic names, both are nothing more than a statement about two averages of past prices: the mean of the last 50 closes has overtaken (or fallen below) the mean of the last 200. Because the 200 SMA moves slowly, these crosses are rare on daily charts and tend to occur only after a large, sustained move has already happened — which is exactly why they attract headlines and exactly why they arrive late. Does it 'actually work'? Honestly: a cross confirms that a major shift in average price has occurred; it does not predict what happens next, and by the time it prints, a substantial part of the move that caused it is already in the past. Historical studies show mixed results that depend heavily on the market and era sampled. This is educational content only, not financial advice, and all trading carries risk of loss.
Compute two simple moving averages of closing price: SMA(50), the average of the last 50 closes, and SMA(200), the average of the last 200. Each new bar, the oldest close drops out of each window and the newest enters. A golden cross is the bar on which SMA(50) moves from below SMA(200) to above it; a death cross is the reverse. The lag is arithmetic, not opinion: the 200 SMA's value is centered on price from roughly 100 bars ago, and the 50 SMA on price from roughly 25 bars ago. For the faster average to drag itself across the slower one, price must first spend weeks or months pulling the 50-bar mean through the 200-bar mean — so the cross certifies a move that is already mature. On a daily chart that regularly means the cross prints well after a significant portion of the rally or decline has occurred. The same mechanism produces whipsaws in sideways markets: when price oscillates around its long-run mean, the two averages flatten, converge, and can cross repeatedly in both directions, each cross carrying the same dramatic name and very little information.
The convention is SMA(50) and SMA(200) on daily closing prices — this pairing is what news coverage means by golden/death cross. Variants substitute EMAs (which cross earlier but whipsaw more) or other pairs like 20/100. Changing lengths, average type, source, or timeframe changes every historical cross, so any claim about crosses is meaningful only with the exact settings attached.
//@version=6
indicator("Golden Cross / Death Cross (50/200 SMA)", overlay = true)
fastLen = input.int(50, "Fast SMA Length", minval = 1)
slowLen = input.int(200, "Slow SMA Length", minval = 1)
src = input.source(close, "Source")
fastMa = ta.sma(src, fastLen)
slowMa = ta.sma(src, slowLen)
// Gated with barstate.isconfirmed so marks and alerts only fire on
// closed bars — an intrabar cross can un-cross before the bar closes.
goldenCross = ta.crossover(fastMa, slowMa) and barstate.isconfirmed
deathCross = ta.crossunder(fastMa, slowMa) and barstate.isconfirmed
plot(fastMa, "Fast SMA", color = color.orange)
plot(slowMa, "Slow SMA", color = color.blue)
plotshape(goldenCross, "Golden Cross", style = shape.triangleup, location = location.belowbar, color = color.green, size = size.small)
plotshape(deathCross, "Death Cross", style = shape.triangledown, location = location.abovebar, color = color.red, size = size.small)
alertcondition(goldenCross, "Golden Cross", "50 SMA crossed above 200 SMA (confirmed bar).")
alertcondition(deathCross, "Death Cross", "50 SMA crossed below 200 SMA (confirmed bar).")Pro tip: Before drawing conclusions from any cross, measure its lag on your own instrument: for each historical golden cross, record how far price had already risen from the preceding swing low when the cross printed. That one number — usually uncomfortably large — is the honest context the headlines omit. Also gate live cross alerts on confirmed bars, because an intrabar cross can reverse before the close. Educational information only, not financial advice; all trading involves risk of loss.
Educational only — not financial advice, not a recommendation to trade. No indicator is predictive; trading involves substantial risk of loss.