Golden Cross & Death Cross in Pine Script
The 50 day simple moving average crossing above the 200 day is the golden cross and crossing below it is the death cross: the slowest, most watched regime marker on a daily chart.
Definition
The golden cross is the 50 day simple moving average crossing above the 200 day simple moving average on a daily chart. The death cross is the same pair crossing the other way. It is a moving average crossover with the longest conventional pair, which turns it from an entry trigger into a regime marker: the average price of the last quarter has moved above or below the average price of the last year. It belongs to the moving averages family and is the version of the crossover that financial news reports.
The cross works as a regime label rather than as timing. By the time a 50 day average lifts through a 200 day average, the market has typically rallied for months and the low is far behind; what the cross confirms is that the rally has lasted long enough to change the yearly average. Markets that reach that state tend to stay in it for a long time, so the cross sorts the chart into bull and bear regimes with few flips. The price of that stability is lag measured in months.
The settings are fixed by convention: 50 and 200, simple averages, closes, daily bars. On an index the pair crosses only a few times a decade, which makes the events memorable and widely watched. The library's implementation draws both averages with a green fill between them while the 50 is above the 200 and a red fill while it is below. It marks Long on a confirmed golden cross and Short on a confirmed death cross, and the optional alerts name the event.
On the chart the two lines spend most of their life far apart. A golden cross arrives well into a recovery, with the 200 still flat or falling; the healthiest ones are followed by the 200 turning up within weeks. A death cross arrives after a decline of several months. The failure mode is a sideways year in which the lines cross 2 or 3 times in quick succession, each cross reversing the last. That cluster is itself information: the market has no yearly trend.
Reading the chart
The event is unmistakable, so reading it is about the state of the lines around it rather than spotting the cross.
- Use a daily chart with the 50 and 200 day simple averages on the close. The conventional settings matter here more than anywhere, because the value of the signal is that everyone sees the same cross.
- Note the slope of the 200 day at the cross. A golden cross with the 200 flattening or turning up is a regime change; a golden cross with the 200 still falling steeply often fails.
- Measure where price is relative to both lines. Price far above the 50 at the cross means the easy part of the rally is done; a pullback towards the 50 after the cross is the entry most traders want.
- Check the last 2 years for recent crosses. If the lines crossed twice already in the last year, the market is ranging and this cross deserves the same suspicion as the last one.
- Confirm on the bar close. The library's script marks the cross only on a confirmed bar, so a mid-day cross that reverses before the close never prints.
- Look at breadth or related markets. A golden cross on an index with most of its constituents still below their own 200 day averages is thinner than it looks.
The maths
Both lines are simple averages of the close; the signal is the day their order changes.
A 200 day average needs 200 bars of history before it exists, so on a newly listed name the cross cannot be read for most of the first year.
Some traders use exponential averages for the pair. The crosses come a little earlier and a little more often, and they stop matching the cross the rest of the market is watching.
The same script on a weekly chart uses 50 and 200 weeks, which is a 4 year average and crosses once a decade; on intraday charts the pair behaves like any other crossover and loses its regime meaning.
The library's script evaluates the cross on confirmed bars and fires one alert per event, named golden cross or death cross with the ticker.
Inputs that matter
| Input | Typical | What changing it does |
|---|---|---|
| Fast length | 50 | A shorter fast line crosses earlier and more often; it stops being the golden cross other traders watch and becomes an ordinary crossover. |
| Slow length | 200 | The 200 fixes the regime horizon at about a year; a shorter slow line makes more crosses and shorter regimes. |
| Source and type | close, simple average | Exponential averages or typical price move the cross by a few days and break the shared reference; keep the convention unless you have a reason. |
In practice
- As a regime label: a chart in a golden cross state gets the bull playbook, long pullback entries and held winners; a chart in a death cross state gets the bear playbook or no long trades at all.
- As a screening filter: scan a universe for names whose 50 day is above a rising 200 day and keep only those, which removes the weakest charts before any entry logic runs.
- As a late confirmation: a golden cross after a base breakout confirms that the recovery has changed the yearly average, which is the point where longer-term money tends to arrive.
- As a position-trade exit: a death cross is the exit condition a position rule uses to close long-term positions or stop adding, because it says the yearly trend has turned down.
- As an alert on a watchlist: the library's script fires once on each cross, so a list of 50 charts can report its regime changes without daily inspection.
- As a contrarian tell: a cluster of 3 crosses in a year marks a range, and range rules there fade the extremes rather than follow the latest cross.
Where it goes wrong
- Treating the cross as a timing entry. It arrives months after the turn, so a pullback entry after the cross fits better than the cross bar itself.
- Ignoring the slope of the 200. A golden cross under a steeply falling 200 is a bear-market rally most of the time; wait for the 200 to flatten.
- Reading it on intraday charts. On a 5 minute chart the 50/200 pair is a fast crossover with no regime meaning; keep the name for the daily and weekly.
- Shorting a death cross into support. A death cross often lands near the low of the decline; treat it as a reason not to be long, not as a short entry on its own.
Compared with
Moving Average Crossover. The general crossover uses fast pairs such as 9 and 21 and fires weekly as an entry signal. The golden cross is the same logic with a 50/200 pair, which fires a few times a decade and describes the regime rather than timing a trade.
Moving Average. Price crossing the 200 day average is the faster regime test and happens many times a year. The golden cross waits until the 50 day average crosses it, which takes longer and produces far fewer signals with fewer false ones.
Multi-Timeframe Trend Filter. A higher-timeframe filter reads a daily or weekly average on a lower chart and updates every bar. The golden cross is a single event on the daily chart itself; it is the slowest filter in the family and the most widely reported.
Ichimoku Cloud. The cloud also labels the regime, with price above or below a projected band, and it turns weeks earlier than a 50/200 cross. The golden cross is simpler, has one event per regime change and is watched by traders who never use Ichimoku.
Build it in Quant
Type one of these in the Quant desk, or click it. A request that fits a checked template is assembled on the spot without a credit; anything beyond the blanks goes to the copilot, which edits on top of the checked script.
Questions
Is the golden cross a long entry?
It is a regime marker that says the market has spent long enough rising to change its yearly average. As a same-day entry it is late, because the low is usually months behind. Most traders use it to switch playbooks and then enter long on the first pullback into the 50 day average, with a stop below it.
How reliable is the death cross?
It labels the regime well and times it badly. A death cross confirms that the last quarter has been weaker than the last year, and markets in that state tend to stay weak. But the cross itself often prints near a short-term low, so shorting it directly is a poor trade; it reads as a reason to stop adding longs.
Why 50 and 200 and not other lengths?
Convention. 50 days is about a quarter of trading and 200 about a year, and the pair has been watched for decades. Its value is shared attention: a cross that everyone sees moves positioning in a way a 47/190 cross never will. Other pairs are fine crossovers but they are not the golden cross.
Can I use EMAs instead of SMAs?
You can, and the crosses arrive a little earlier and more often. What you lose is the reference everyone else uses, because the reported event is the simple average cross. For an earlier read, traders keep the SMA cross as the regime label and time entries with a faster tool such as an EMA cross or a pullback.
What does it mean when the lines cross 3 times in a year?
That the market has no yearly trend. Each cross undoes the last, and a trader who follows all of them loses on each. The cluster marks a range: range rules fade the extremes and exit early, and wait for a cross that is followed by the lines separating.
Does the golden cross work on stocks and crypto as well as indices?
Yes, with more noise. Single stocks and crypto pairs trend harder and crash faster than an index, so the crosses are more frequent and the death cross arrives after larger losses. The regime logic is the same; expect more whipsaw, and position sizes that allow for it.