本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("CRT v8", overlay=true, max_lines_count=500, max_labels_count=500)
// ───── HISTORY SETTINGS ─────
historyDays = input.int(3, "Show History (Calendar Days)", minval=1, maxval=30)
lastDay = timestamp(syminfo.timezone, year(last_bar_time, syminfo.timezone), month(last_bar_time, syminfo.timezone), dayofmonth(last_bar_time, syminfo.timezone), 0, 0)
historyStart = lastDay - (historyDays - 1) * 86400000
inHistory = time >= historyStart
// ───── TIMEFRAME SETTINGS ─────
showW = input.bool(true, "Weekly")
showD = input.bool(true, "Daily")
show4H = input.bool(true, "4 Hours")
show2H = input.bool(true, "2 Hours")
show1H = input.bool(true, "1 Hour")
show30 = input.bool(true, "30 Minutes")
show15 = input.bool(true, "15 Minutes")
show5 = input.bool(true, "5 Minutes")
show1 = input.bool(true, "1 Minute")
showOther = input.bool(true, "Other timeframes (3m, 45m, 3H, etc.)")
isW = timeframe.isweekly
isD = timeframe.isdaily
is4H = timeframe.isintraday and timeframe.multiplier == 240
is2H = timeframe.isintraday and timeframe.multiplier == 120
is1H = timeframe.isintraday and timeframe.multiplier == 60
is30 = timeframe.isintraday and timeframe.multiplier == 30
is15 = timeframe.isintraday and timeframe.multiplier == 15
is5 = timeframe.isintraday and timeframe.multiplier == 5
is1 = timeframe.isintraday and timeframe.multiplier == 1
isOther = not (isW or isD or is4H or is2H or is1H or is30 or is15 or is5 or is1)
allowedTF = (showW and isW) or (showD and isD) or (show4H and is4H) or (show2H and is2H) or (show1H and is1H) or (show30 and is30) or (show15 and is15) or (show5 and is5) or (show1 and is1) or (showOther and isOther)
// ───── CRT SETTINGS ─────
useA = input.bool(true, "Model A: Bullish (red range, sweep low, close back inside)")
useB = input.bool(true, "Model B: Bearish (green range, sweep high, close back inside)")
reqCol = input.bool(true, "Require candle color (green for A, red for B)")
strictInside = input.bool(true, "Strict: manipulation candle must not break the opposite side of the range")
ext = input.int(10, "Extend lines (bars)", minval=1)
bullCol = input.color(color.lime, "Bullish color")
bearCol = input.color(color.red, "Bearish color")
lineCol = input.color(color.white, "CRT H/L line color")
// ───── PREVIOUS CANDLE RANGE ─────
r1H = high[1]
r1L = low[1]
c1Red = close[1] < open[1]
c1Grn = close[1] > open[1]
// ───── CRT SIGNALS ─────
sigA = allowedTF and inHistory and useA and barstate.isconfirmed and c1Red and low < r1L and close > r1L and (not strictInside or high < r1H) and (not reqCol or close > open)
sigB = allowedTF and inHistory and useB and barstate.isconfirmed and c1Grn and high > r1H and close < r1H and (not strictInside or low > r1L) and (not reqCol or close < open)
sig = sigA or sigB
// ───── SIGNAL MARKERS ─────
plotshape(sigA, title="CRT Buy", style=shape.triangleup, location=location.belowbar, color=bullCol, size=size.small, text="CRT")
plotshape(sigB, title="CRT Sell", style=shape.triangledown, location=location.abovebar, color=bearCol, size=size.small, text="CRT")
// ───── CREATE CRT DRAWINGS (no indented blocks) ─────
hLine = sig ? line.new(bar_index - 1, r1H, bar_index + ext, r1H, color=lineCol, width=1) : na
lLine = sig ? line.new(bar_index - 1, r1L, bar_index + ext, r1L, color=lineCol, width=1) : na
hLbl = sig ? label.new(bar_index + ext, r1H, sigA ? "CRT High (TP)" : "CRT High", style=label.style_label_left, color=color.new(lineCol, 100), textcolor=lineCol) : na
lLbl = sig ? label.new(bar_index + ext, r1L, sigB ? "CRT Low (TP)" : "CRT Low", style=label.style_label_left, color=color.new(lineCol, 100), textcolor=lineCol) : na
buyLbl = sigA ? label.new(bar_index, low, "Manipulation", style=label.style_label_up, color=bullCol, textcolor=color.white, size=size.small) : na
sellLbl = sigB ? label.new(bar_index, high, "Manipulation", style=label.style_label_down, color=bearCol, textcolor=color.white, size=size.small) : na
// ───── TARGET / INVALIDATION TRACKING ─────
var int dir = 0
var float tp = na
var float sl = na
tpHit = allowedTF and inHistory and barstate.isconfirmed and not sig and ((dir == 1 and high >= tp) or (dir == -1 and low <= tp))
slHit = allowedTF and inHistory and barstate.isconfirmed and not sig and ((dir == 1 and close < sl) or (dir == -1 and close > sl))
bullTP = tpHit and dir == 1
bearTP = tpHit and dir == -1
bullSL = slHit and dir == 1 and not tpHit
bearSL = slHit and dir == -1 and not tpHit
dir := sigA ? 1 : sigB ? -1 : (tpHit or slHit) ? 0 : dir
tp := sigA ? r1H : sigB ? r1L : tp
sl := sigA ? low : sigB ? high : sl
// ───── ALERTS ─────
alertcondition(sigA, title="CRT Buy Signal", message="CRT BUY on {{ticker}} {{interval}} - bullish manipulation confirmed. Target: CRT High.")
alertcondition(sigB, title="CRT Sell Signal", message="CRT SELL on {{ticker}} {{interval}} - bearish manipulation confirmed. Target: CRT Low.")
alertcondition(sig, title="CRT Any Signal", message="CRT signal confirmed on {{ticker}} {{interval}}.")
alertcondition(bullTP, title="CRT Buy Target Hit", message="CRT BUY target hit on {{ticker}} {{interval}}.")
alertcondition(bearTP, title="CRT Sell Target Hit", message="CRT SELL target hit on {{ticker}} {{interval}}.")
alertcondition(bullSL, title="CRT Buy Invalidated", message="CRT BUY invalidated on {{ticker}} {{interval}}.")
alertcondition(bearSL, title="CRT Sell Invalidated", message="CRT SELL invalidated on {{ticker}} {{interval}}.")