OPEN-SOURCE SCRIPT

CRT + SMC MY

66
//version=5
indicator("CRT + SMC MultiTF (Fixed Requests)", overlay=true, max_labels_count=500, max_boxes_count=200)

// ---------------- INPUTS ----------------
htfTF = input.string("60", title="HTF timeframe (60=1H, 240=4H)")
midTF = input.string("5", title="Mid timeframe (5 or 15)")
execTF = input.string("1", title="Exec timeframe (1 for sniper)")
useMAfilter = input.bool(true, "Require HTF MA filter")
htf_ma_len = input.int(50, "HTF MA length")
showOB = input.bool(true, "Show Order Blocks (midTF)")
showFVG = input.bool(true, "Show Fair Value Gaps (execTF)")
showEntries = input.bool(true, "Show Entry arrows & SL/TP")
slBuffer = input.int(3, "SL buffer (ticks)")
rrTarget = input.float(4.0, "Default R:R target")
useKillzone = input.bool(false, "Use London/NY Killzone (approx NY-5 timezone)")

// ---------------- REQUESTS (ALL at top-level) ----------------
// HTF series
htf_open = request.security(syminfo.tickerid, htfTF, open)
htf_high = request.security(syminfo.tickerid, htfTF, high)
htf_low = request.security(syminfo.tickerid, htfTF, low)
htf_close = request.security(syminfo.tickerid, htfTF, close)
htf_ma = request.security(syminfo.tickerid, htfTF, ta.sma(close, htf_ma_len))

htf_prev_high = request.security(syminfo.tickerid, htfTF, high[1])
htf_prev_low = request.security(syminfo.tickerid, htfTF, low[1])

// midTF series for OB detection
mid_open = request.security(syminfo.tickerid, midTF, open)
mid_high = request.security(syminfo.tickerid, midTF, high)
mid_low = request.security(syminfo.tickerid, midTF, low)
mid_close = request.security(syminfo.tickerid, midTF, close)
mid_median_body = request.security(syminfo.tickerid, midTF, ta.median(math.abs(close - open), 8))

// execTF series for FVG and micro structure
exec_high = request.security(syminfo.tickerid, execTF, high)
exec_low = request.security(syminfo.tickerid, execTF, low)
exec_open = request.security(syminfo.tickerid, execTF, open)
exec_close = request.security(syminfo.tickerid, execTF, close)

// Also get shifted values needed for heuristics (all top-level)
exec_high_1 = request.security(syminfo.tickerid, execTF, high[1])
exec_high_2 = request.security(syminfo.tickerid, execTF, high[2])
exec_low_1 = request.security(syminfo.tickerid, execTF, low[1])
exec_low_2 = request.security(syminfo.tickerid, execTF, low[2])

mid_low_1 = request.security(syminfo.tickerid, midTF, low[1])
mid_high_1 = request.security(syminfo.tickerid, midTF, high[1])

// ---------------- HTF logic ----------------
htf_ma_bias_long = htf_close > htf_ma
htf_ma_bias_short = htf_close < htf_ma

htf_sweep_high = (htf_high > htf_prev_high) and (htf_close < htf_prev_high)
htf_sweep_low = (htf_low < htf_prev_low) and (htf_close > htf_prev_low)

htf_final_long = htf_sweep_low and (not useMAfilter or htf_ma_bias_long)
htf_final_short = htf_sweep_high and (not useMAfilter or htf_ma_bias_short)

// HTF label (single label updated)
var label htf_label = na
if barstate.islast
label.delete(htf_label)
if htf_final_long
htf_label := label.new(bar_index, high, "HTF BIAS: LONG", style=label.style_label_left, color=color.green, textcolor=color.white)
else if htf_final_short
htf_label := label.new(bar_index, low, "HTF BIAS: SHORT", style=label.style_label_left, color=color.red, textcolor=color.white)

// ---------------- midTF OB detection (heuristic) ----------------
mid_body = math.abs(mid_close - mid_open)
is_bear_mid = (mid_open > mid_close) and (mid_body >= mid_median_body)
is_bull_mid = (mid_open < mid_close) and (mid_body >= mid_median_body)

mid_bear_disp = is_bear_mid and (mid_low < mid_low_1)
mid_bull_disp = is_bull_mid and (mid_high > mid_high_1)

// Store last OB values (safe top-level assignments)
var float last_bear_ob_top = na
var float last_bear_ob_bot = na
var int last_bear_ob_time = na
var float last_bull_ob_top = na
var float last_bull_ob_bot = na
var int last_bull_ob_time = na

if mid_bear_disp
last_bear_ob_top := mid_open
last_bear_ob_bot := mid_close
last_bear_ob_time := timenow

if mid_bull_disp
last_bull_ob_top := mid_close
last_bull_ob_bot := mid_open
last_bull_ob_time := timenow

// Draw OB boxes (draw always but can be toggled)
if showOB
if not na(last_bear_ob_top)
box.new(bar_index - 1, last_bear_ob_top, bar_index + 1, last_bear_ob_bot, border_color=color.new(color.red,0), bgcolor=color.new(color.red,85))
if not na(last_bull_ob_top)
box.new(bar_index - 1, last_bull_ob_top, bar_index + 1, last_bull_ob_bot, border_color=color.new(color.green,0), bgcolor=color.new(color.green,85))

// ---------------- execTF FVG detection (top-level logic) ----------------
// simple 3-candle gap heuristic
bull_fvg_local = exec_low_2 > exec_high_1
bear_fvg_local = exec_high_2 < exec_low_1

// Compute FVG box coords at top-level
fvg_bull_top = exec_high_1
fvg_bull_bot = exec_low_2
fvg_bear_top = exec_high_2
fvg_bear_bot = exec_low_1

if showFVG
if bull_fvg_local
box.new(bar_index - 2, fvg_bull_top, bar_index, fvg_bull_bot, border_color=color.new(color.green,0), bgcolor=color.new(color.green,85))
if bear_fvg_local
box.new(bar_index - 2, fvg_bear_top, bar_index, fvg_bear_bot, border_color=color.new(color.red,0), bgcolor=color.new(color.red,85))

// ---------------- micro structure on execTF ----------------
micro_high = exec_high
micro_low = exec_low
micro_high_1 = exec_high_1
micro_low_1 = exec_low_1

micro_bos_long = micro_high > micro_high_1
micro_bos_short = micro_low < micro_low_1

// ---------------- killzone check (top-level) ----------------
kill_ok = true
if useKillzone
hh = hour(time('GMT-5'))
mm = minute(time('GMT-5'))
// London approx
inLondon = (hh > 2 or (hh == 2 and mm >= 45)) and (hh < 5 or (hh == 5 and mm <= 0))
inNY = (hh > 8 or (hh == 8 and mm >= 20)) and (hh < 11 or (hh == 11 and mm <= 30))
kill_ok := inLondon or inNY

// ---------------- Entry logic (top-level boolean decisions) ----------------
hasBullOB = not na(last_bull_ob_top)
hasBearOB = not na(last_bear_ob_top)

entryLong = htf_final_long and hasBullOB and micro_bos_long and bull_fvg_local and kill_ok
entryShort = htf_final_short and hasBearOB and micro_bos_short and bear_fvg_local and kill_ok

// ---------------- SL / TP suggestions and plotting ----------------
var label lastEntryLabel = na
if entryLong or entryShort
entryPrice = close
suggestedSL = entryLong ? (htf_low - slBuffer * syminfo.mintick) : (htf_high + slBuffer * syminfo.mintick)
slDist = math.abs(entryPrice - suggestedSL)
suggestedTP = entryLong ? (entryPrice + slDist * rrTarget) : (entryPrice - slDist * rrTarget)

if showEntries
label.delete(lastEntryLabel)
lastEntryLabel := label.new(bar_index, entryPrice, entryLong ? "ENTRY LONG" : "ENTRY SHORT", style=label.style_label_center, color=entryLong ? color.green : color.red, textcolor=color.white)
line.new(bar_index, suggestedSL, bar_index + 20, suggestedSL, color=color.orange, style=line.style_dashed)
line.new(bar_index, suggestedTP, bar_index + 40, suggestedTP, color=color.aqua, style=line.style_dashed)

plotshape(entryLong, title="Entry Long", location=location.belowbar, color=color.green, style=shape.triangleup, size=size.small)
plotshape(entryShort, title="Entry Short", location=location.abovebar, color=color.red, style=shape.triangledown, size=size.small)

alertcondition(entryLong, title="CRT SMC Entry Long", message="Entry Long — HTF bias + midTF OB + execTF confirmation")
alertcondition(entryShort, title="CRT SMC Entry Short", message="Entry Short — HTF bias + midTF OB + execTF confirmation")

免责声明

这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。