OPEN-SOURCE SCRIPT

Craig Cobb Cradle Strategy

37
//version=5
strategy("Craig Cobb Cradle Strategy", overlay=true, margin_long=100, margin_short=100)

// ─────────────────────────────────────────────
// Inputs
// ─────────────────────────────────────────────
emaLenFast = input.int(10, "Fast EMA")
emaLenSlow = input.int(20, "Slow EMA")
smallCandlePct = input.float(0.35, "Small candle max size (% of ATR)")

// MACD Inputs
fastLength = input.int(12)
slowLength = input.int(26)
signalLength = input.int(9)

// ─────────────────────────────────────────────
// EMAs (Cradle Zone)
// ─────────────────────────────────────────────
ema10 = ta.ema(close, emaLenFast)
ema20 = ta.ema(close, emaLenSlow)

plot(ema10, color=color.yellow, title="10 EMA")
plot(ema20, color=color.orange, title="20 EMA")

inCradleZone = low <= ema10 and high >= ema20 or low <= ema20 and high >= ema10

// Trend alignment
bullTrend = ema10 > ema20
bearTrend = ema10 < ema20

// ─────────────────────────────────────────────
// MACD + signal line
// ─────────────────────────────────────────────
macd = ta.ema(close, fastLength) - ta.ema(close, slowLength)
signal = ta.ema(macd, signalLength)
hist = macd - signal

// MACD confluence: Signal line moving in trend direction
macdBull = signal > signal[1] // signal rising
macdBear = signal < signal[1] // signal falling

// ─────────────────────────────────────────────
// Small Cradle Candle (the trigger candle)
// Candle must be small relative to ATR
// ─────────────────────────────────────────────
atr = ta.atr(14)
candleSize = high - low
smallCandle = candleSize <= atr * smallCandlePct

// Bullish small candle
bullishCandle = close > open and smallCandle
// Bearish small candle
bearishCandle = close < open and smallCandle

// ─────────────────────────────────────────────
// Cradle Entry Conditions
// ─────────────────────────────────────────────
longEntry = bullTrend and inCradleZone and bullishCandle and macdBull
shortEntry = bearTrend and inCradleZone and bearishCandle and macdBear

// ─────────────────────────────────────────────
// Plot signals
// ─────────────────────────────────────────────
plotshape(longEntry, title="Long Cradle", style=shape.labelup, color=color.lime, text="Cradle Long")
plotshape(shortEntry, title="Short Cradle", style=shape.labeldown, color=color.red, text="Cradle Short")

// ─────────────────────────────────────────────
// Alerts
// ─────────────────────────────────────────────
alertcondition(longEntry, title="Cradle Long Alert", message="Cradle long setup detected")
alertcondition(shortEntry, title="Cradle Short Alert", message="Cradle short setup detected")

// Strategy entry (optional)
if longEntry
strategy.entry("Long", strategy.long)
if shortEntry
strategy.entry("Short", strategy.short)

Pernyataan Penyangkalan

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.