Indicators · condition block
Golden cross and death cross
The golden cross block compares two simple moving averages. A golden cross is the fast average crossing above the slow one; a death cross is the fast average crossing below it.
How the engine evaluates it
Both averages are simple moving averages of closes. A golden cross fires when the fast SMA was at or below the slow SMA on the previous candle and is above it now. A death cross is the reverse.
The fast length must be shorter than the slow length; the Lab and the engine reject anything else.
The block needs enough candles for the slow average. Before your start date the engine loads extra history (at least 50 candles, up to 5,000, scaled to the longest indicator in the bot) so the indicator has settled by the first candle of the run.
golden: SMA_fast[t−1] ≤ SMA_slow[t−1] and SMA_fast[t] > SMA_slow[t]
death: SMA_fast[t−1] ≥ SMA_slow[t−1] and SMA_fast[t] < SMA_slow[t]
Botscript syntax
In the Lab you pick this block from the Indicators group and fill in its fields. In the code view the same condition is written like this:
sma(50) crosses above sma(200)
sma(20) crosses below sma(100)
Settings
| Setting | Values | Default | Notes |
|---|---|---|---|
| Direction | golden, death | golden | Fast crossing above (golden) or below (death). |
| Fast length | 1 – 5,000 | 20 | Must be shorter than the slow length. |
| Slow length | 2 – 5,000 | 100 | The classic daily pair is 50 and 200. |
| Timeframe | the run's candles, or 15m, 30m, 1h, 2h, 4h, 6h, 12h, 1d, 1w | the run's candles | Optional. At least the run's candle size and a whole multiple of it. |
On a higher timeframe
Add a timeframe at the end to read Golden cross from bigger candles than the run uses, for example sma(50) crosses above sma(200) on 1d. The engine builds those candles from the run's own candles (UTC, weeks start on Monday) and evaluates the block only on candles that have closed, so there is no look-ahead. Lengths and lookbacks count the bigger candles.
Golden cross is an event on a higher timeframe: it fires once, on the run candle that closes the bigger candle where it happened, and is false on the other run candles.
The timeframe must be at least the run's candle size and a whole multiple of it; otherwise the run stops with an error and is not charged. Multi-timeframe conditions covers the details, including warm-up.
How traders use it
- Long-term regime:
sma(50) crosses above sma(200)on daily candles. - Faster swings: 20 and 100 on 4-hour candles.
- Pair a golden-cross entry with a death-cross exit for a simple always-in-trend system.
Example bot
bot "Golden Cross"
when sma(50) crosses above sma(200)
then buy 100%
when sma(50) crosses below sma(200)
then sell 100%
- Buys on the 50/200 golden cross.
- Sells on the death cross.
Pitfalls
- Crosses of long averages arrive late, often after much of the move.
- Very few signals means very few trades: one good or bad trade can dominate the result.
Golden cross: frequently asked questions
Does it use simple or exponential averages?
Simple moving averages of closes for both lines.
What are the classic settings?
50 and 200 on daily candles. Our default is 20 and 100, which gives more signals on shorter candle sizes.
Can the fast length be longer than the slow one?
No. The fast length must be shorter than the slow length, otherwise the bot will not compile.
Is it true for as long as the fast average stays above?
No. It fires on the crossing candle only. To require the state, compare price with an average or use a trend block such as Supertrend.
Related blocks
Simulated results are hypothetical. They include only the fee and slippage you set on the bot, not every real-world cost or market condition, and past performance does not guarantee future results. Nothing here is financial advice.