OPEN-SOURCE SCRIPT

CRT 4H/1D + FVG + OB (Entry/SL/TP Alerts) — v2.0 Gökhan

152
//version=5
indicator("CRT 4H/1D + FVG + OB (Entry/SL/TP Alerts) — v2.0", overlay=true, max_labels_count=500, max_lines_count=500)

//──── Inputs
use4H = input.bool(true, "Use 4H CRT")
use1D = input.bool(true, "Use 1D CRT")
needFVG = input.bool(true, "Require FVG confirmation")
useOBfilter = input.bool(false, "Require simple OB filter (prev body mid)")
lookFVGbars = input.int(5, "FVG lookback bars", minval=2, maxval=20)
atrLen = input.int(14, "ATR Length", minval=5)
atrMult = input.float(0.5, "ATR SL buffer (xATR)", step=0.05)
lineW = input.int(2, "Line Width", minval=1, maxval=4)
boxTransp = input.int(85, "Range Box Transparency", minval=0, maxval=100)
showBoxes = input.bool(true, "Show HTF Range Boxes")
showLines = input.bool(true, "Show HTF Lines & 50%")
showPlan = input.bool(true, "Show Entry/SL/TP lines when active")
persistBars = input.int(30, "Keep plan on chart (bars)", minval=5, maxval=500)

//──── Colors
col4H = color.new(color.teal, 0)
col1D = color.new(color.orange, 0)
colUp = color.new(color.lime, 0)
colDn = color.new(color.red, 0)
colMid = color.new(color.gray, 30)
colPlan = color.new(color.blue, 0)

//──── Helpers: previous HTF candle OHLC
f_prevHTF(tf) =>
hh = request.security(symbol=syminfo.tickerid, timeframe=tf, expression=high[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
ll = request.security(symbol=syminfo.tickerid, timeframe=tf, expression=low[1], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
[hh, ll]

[H4_hi_raw, H4_lo_raw] = f_prevHTF("240")
[D1_hi_raw, D1_lo_raw] = f_prevHTF("D")

H4_hi = nz(H4_hi_raw)
H4_lo = nz(H4_lo_raw)
D1_hi = nz(D1_hi_raw)
D1_lo = nz(D1_lo_raw)

H4_mid = (H4_hi + H4_lo)/2.0
D1_mid = (D1_hi + D1_lo)/2.0

//──── Local
h = high, l = low, c = close, o = open

//──── CRT: Sweep & Reclaim
H4_upSweep = use4H and (h > H4_hi) and (c < H4_hi) // yukarı süpür → aşağı dönüş
H4_dnSweep = use4H and (l < H4_lo) and (c > H4_lo) // aşağı süpür → yukarı dönüş
D1_upSweep = use1D and (h > D1_hi) and (c < D1_hi)
D1_dnSweep = use1D and (l < D1_lo) and (c > D1_lo)

// Hangi TF tetikledi? Öncelik: 4H sonra 1D (isteğe göre değiştirilebilir)
bearSweep = H4_upSweep or (not H4_upSweep and D1_upSweep)
bullSweep = H4_dnSweep or (not H4_dnSweep and D1_dnSweep)
useH4levels = H4_upSweep or H4_dnSweep

rngHi = useH4levels ? H4_hi : D1_hi
rngLo = useH4levels ? H4_lo : D1_lo
rngMid= useH4levels ? H4_mid: D1_mid

//──── FVG (classic 3-candle)
// Bullish FVG at bar i: low > high[i-2]
// Bearish FVG at bar i: high < low[i-2]
f_hasBullFVG(window) =>
ok = false
for i = 0 to window-1
ok := ok or (low > high[i+2])
ok

f_hasBearFVG(window) =>
ok = false
for i = 0 to window-1
ok := ok or (high < low[i+2])
ok

bullFVG = f_hasBullFVG(lookFVGbars) // yukarı dönüş teyidi
bearFVG = f_hasBearFVG(lookFVGbars) // aşağı dönüş teyidi

//──── Basit OB filtresi (prev body midpoint reclaim)
// Bullish: c > (o[1]+c[1])/2
// Bearish: c < (o[1]+c[1])/2
prevMid = (o[1] + c[1]) / 2.0
bullOBok = c > prevMid
bearOBok = c < prevMid

// Zorunlu teyit seti
bullConfirm = (not needFVG or bullFVG) and (not useOBfilter or bullOBok)
bearConfirm = (not needFVG or bearFVG) and (not useOBfilter or bearOBok)

// Nihai SETUP (yön + teyit)
bearSetup = bearSweep and bearConfirm
bullSetup = bullSweep and bullConfirm

//──── Lines & Boxes
plot(showLines and use4H ? H4_hi : na, "4H High", col4H, lineW, plot.style_linebr)
plot(showLines and use4H ? H4_lo : na, "4H Low", col4H, lineW, plot.style_linebr)
plot(showLines and use4H ? H4_mid: na, "4H 50%", colMid, 1, plot.style_linebr)

plot(showLines and use1D ? D1_hi : na, "1D High", col1D, lineW, plot.style_linebr)
plot(showLines and use1D ? D1_lo : na, "1D Low", col1D, lineW, plot.style_linebr)
plot(showLines and use1D ? D1_mid: na, "1D 50%", colMid, 1, plot.style_linebr)

var box h4Box = na
var box d1Box = na
if showBoxes and barstate.islast
if use4H and not na(H4_hi) and not na(H4_lo)
if na(h4Box)
h4Box := box.new(bar_index-1, H4_lo, bar_index, H4_hi, bgcolor=color.new(col4H, boxTransp), border_color=col4H)
else
box.set_left(h4Box, bar_index-1), box.set_right(h4Box, bar_index)
box.set_bottom(h4Box, H4_lo), box.set_top(h4Box, H4_hi)
if use1D and not na(D1_hi) and not na(D1_lo)
if na(d1Box)
d1Box := box.new(bar_index-1, D1_lo, bar_index, D1_hi, bgcolor=color.new(col1D, boxTransp), border_color=col1D)
else
box.set_left(d1Box, bar_index-1), box.set_right(d1Box, bar_index)
box.set_bottom(d1Box, D1_lo), box.set_top(d1Box, D1_hi)

//──── Entry/SL/TP Plan (stateful)
atr = ta.atr(atrLen)
tick = syminfo.mintick

var bool planActive = false
var bool planBull = na
var float planEntry = na
var float planSL = na
var float planTP1 = na
var float planTP2 = na
var int planBars = 0

// Yeni setup oluştuğunda plan kur
if barstate.isconfirmed
if bearSetup
planActive := true, planBull := false
planEntry := rngHi // retest: prev High
planSL := math.max(high, rngHi) + atrMult*atr
planTP1 := rngMid
planTP2 := rngLo
planBars := 0
label.new(bar_index, high, "CRT BEAR setup\nEntry≈"+str.tostring(planEntry)+"\nSL≈"+str.tostring(planSL)+"\nTP1≈"+str.tostring(planTP1)+" TP2≈"+str.tostring(planTP2),
style=label.style_label_down, color=color.new(colDn,0), textcolor=color.white, size=size.tiny)
if bullSetup
planActive := true, planBull := true
planEntry := rngLo // retest: prev Low
planSL := math.min(low, rngLo) - atrMult*atr
planTP1 := rngMid
planTP2 := rngHi
planBars := 0
label.new(bar_index, low, "CRT BULL setup\nEntry≈"+str.tostring(planEntry)+"\nSL≈"+str.tostring(planSL)+"\nTP1≈"+str.tostring(planTP1)+" TP2≈"+str.tostring(planTP2),
style=label.style_label_up, color=color.new(colUp,0), textcolor=color.white, size=size.tiny)

// Plan takibi
entryTouched = planActive and ((planBull and low <= planEntry) or (not planBull and high >= planEntry))
tp1Hit = planActive and ((planBull and high >= planTP1) or (not planBull and low <= planTP1))
tp2Hit = planActive and ((planBull and high >= planTP2) or (not planBull and low <= planTP2))
slHit = planActive and ((planBull and low <= planSL) or (not planBull and high >= planSL))

if planActive
planBars += 1
// de-activate on exit
if slHit or tp2Hit or planBars > persistBars
planActive := false

// Görsel plan çizgileri
plot(showPlan and planActive ? planEntry : na, "Entry", color.new(colPlan, 0), 2, plot.style_linebr)
plot(showPlan and planActive ? planSL : na, "SL", color.new(color.red, 0), 2, plot.style_linebr)
plot(showPlan and planActive ? planTP1 : na, "TP1", color.new(color.gray, 0), 1, plot.style_linebr)
plot(showPlan and planActive ? planTP2 : na, "TP2", color.new(color.gray, 0), 1, plot.style_linebr)

// İşaretler
plotshape(bearSetup, title="Bear Setup", style=shape.triangledown, location=location.abovebar, size=size.tiny, color=colDn, text="CRT▼")
plotshape(bullSetup, title="Bull Setup", style=shape.triangleup, location=location.belowbar, size=size.tiny, color=colUp, text="CRT▲")

//──── Alerts
alertcondition(bearSetup, title="CRT Setup Ready (Bearish)",
message="CRT Bearish setup ready on {{ticker}} {{interval}} | Entry≈{{plot(\"Entry\")}} SL≈{{plot(\"SL\")}} TP1≈{{plot(\"TP1\")}} TP2≈{{plot(\"TP2\")}}")
alertcondition(bullSetup, title="CRT Setup Ready (Bullish)",
message="CRT Bullish setup ready on {{ticker}} {{interval}} | Entry≈{{plot(\"Entry\")}} SL≈{{plot(\"SL\")}} TP1≈{{plot(\"TP1\")}} TP2≈{{plot(\"TP2\")}}")
alertcondition(entryTouched, title="CRT Retest Filled",
message="CRT Entry retest filled on {{ticker}} {{interval}}")

Haftungsausschluss

Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.