OPEN-SOURCE SCRIPT
Craig Cobb Cradle Strategy

//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)
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)
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน
สคริปต์โอเพนซอร์ซ
ด้วยเจตนารมณ์หลักของ TradingView ผู้สร้างสคริปต์นี้ได้ทำให้เป็นโอเพนซอร์ส เพื่อให้เทรดเดอร์สามารถตรวจสอบและยืนยันฟังก์ชันการทำงานของมันได้ ขอชื่นชมผู้เขียน! แม้ว่าคุณจะใช้งานได้ฟรี แต่โปรดจำไว้ว่าการเผยแพร่โค้ดซ้ำจะต้องเป็นไปตาม กฎระเบียบการใช้งาน ของเรา
คำจำกัดสิทธิ์ความรับผิดชอบ
ข้อมูลและบทความไม่ได้มีวัตถุประสงค์เพื่อก่อให้เกิดกิจกรรมทางการเงิน, การลงทุน, การซื้อขาย, ข้อเสนอแนะ หรือคำแนะนำประเภทอื่น ๆ ที่ให้หรือรับรองโดย TradingView อ่านเพิ่มเติมใน ข้อกำหนดการใช้งาน