strategy · on price · open source
Golden cross strategy: 50/200 SMA crossover
Golden cross / death cross strategy with 50 and 200 SMAs: rules in plain English, copyable code and a backtest with next-bar fills and costs. Free to run. Deepwick Script runs a subset of Pine Script.
What the Golden Cross (50/200 SMA) strategy does
The textbook golden/death cross strategy: long when a fast SMA crosses above a slow SMA, exit on the reverse. Slow equal-weight averages smooth through noise better than EMAs but lag more.
- 50/200 is the iconic daily pair; 20/50 for shorter timeframes.
- Higher
Slowmeans bigger swings and fewer trades. - Combine with a volume filter for cleaner breakouts.
Entry and exit rules
Language reference: Deepwick Script.
Default inputs
| Input | Default | Min | Max |
|---|---|---|---|
Fast SMA | 50 | 5 | 100 |
Slow SMA | 200 | 20 | 400 |
Stop Loss % | 2 | 0.5 | 10 |
Take Profit % | 6 | 0 | 20 |
How Deepwick fills this strategy
- Market orders fill at the next bar's open.
- Stops and limits follow the bar's path: open → nearer extreme → farther extreme → close.
- Gaps fill at the open.
- Commission is charged on every fill, and slippage applies to market and stop fills, as set in
strategy().
Source code
Deepwick Script, a subset of Pine Script · read-only
//@version=6
strategy("SMA Crossover", overlay=true, initial_capital=10000, default_qty_type=strategy.percent_of_equity, default_qty_value=10, commission_type=strategy.commission.percent, commission_value=0.05)
fast = input.int(50, "Fast SMA", minval=5, maxval=100, step=1)
slow = input.int(200, "Slow SMA", minval=20, maxval=400, step=1)
stopPct = input.float(2, "Stop Loss %", minval=0.5, maxval=10, step=0.1)
tpPct = input.float(6, "Take Profit %", minval=0, maxval=20, step=0.1)
colorMid2 = input.color("color.teal", "Color Mid2")
colorDim = input.color("color.navy", "Color Dim")
colorUp = input.color("color.green", "Color Up")
colorDown = input.color("color.red", "Color Down")
fastS = ta.sma(close, fast)
slowS = ta.sma(close, slow)
longSignal = strategy.position_size == 0 and ta.crossover(fastS, slowS)
exitSignal = strategy.position_size > 0 and ta.crossunder(fastS, slowS)
if longSignal
strategy.entry("Long", strategy.long)
if strategy.position_size > 0
strategy.exit("Risk", stop=stopPct > 0 ? strategy.position_avg_price * (1 - stopPct / 100) : na, limit=tpPct > 0 ? strategy.position_avg_price * (1 + tpPct / 100) : na)
if exitSignal
strategy.close("Long", comment="SMA cross down")
p_Fast_SMA = plot(fastS, "Fast SMA", color=colorMid2, linewidth=2)
p_Slow_SMA = plot(slowS, "Slow SMA", color=colorDim, linewidth=2)
plotshape(longSignal, "Long", style=shape.triangleup, location=location.belowbar, color=colorUp, text="L")
plotshape(exitSignal, "Exit", style=shape.triangledown, location=location.abovebar, color=colorDown, text="X")
alertcondition(longSignal, "SMA long entry", "Fast SMA crossed above slow SMA")
alertcondition(exitSignal, "SMA exit", "Fast SMA crossed below slow SMA")
Run it in Deepwick
- Open a chart of any crypto pair or CFD.
- Click “Scripts” and add this strategy.
- Press Run and read the trades in the Strategy Tester.
FAQ
Does the golden cross strategy work?
It depends on the market, period and costs, which is why this page publishes the run with its symbol, timeframe, period and fees. It trades rarely, so check the number of trades before trusting any statistic.
Golden cross with SMA or EMA?
The textbook version uses simple moving averages (50/200). EMAs react faster and cross earlier. The EMA crossover page tests a faster 9/21 pair.
Which timeframe is the golden cross for?
It is usually read on the daily chart. You can run it on intraday bars too, but 200 bars of history are needed before the first signal.
No comments yet.
Sign in to comment.