本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("TOLAG Eclipse CRT | TGL 3 V1.8", shorttitle="ECL TGL3", overlay=true, max_boxes_count=300, max_lines_count=300, max_labels_count=300)
// =====================================================
// ECLIPSE CRT V1.8
// Manipulation + structure + trade visualization
// =====================================================
color CYAN = #00DDEB
color RED = #FF456C
color PURPLE = #A46BFF
color GOLD = #FFC247
color WHITE = #F4F0FF
color MUTED = #9992AD
color DARK = #171326
string G1 = "01 | CRT Reference"
string htf = input.timeframe("240", "Reference HTF", group=G1)
bool showCRT = input.bool(true, "Show CRT Boxes", group=G1)
int crtHistory = input.int(3, "CRT Boxes to Retain", minval=1, maxval=8, group=G1)
bool showReference = input.bool(false, "Show HTF High / Low", group=G1)
string G2 = "02 | Manipulation"
bool showManip = input.bool(true, "Show Manipulation Text", group=G2)
bool showManipZone = input.bool(true, "Show Manipulation Zone", group=G2)
float minSweep = input.float(0.02, "Minimum Sweep ATR", minval=0, step=0.01, group=G2)
int reclaimWindow = input.int(5, "Reclaim Window", minval=1, maxval=20, group=G2)
int manipHistory = input.int(15, "Retain Manipulation Events", minval=1, maxval=40, group=G2)
string G3 = "03 | Market Structure"
bool showSwings = input.bool(true, "Important Swing Labels", group=G3)
bool showBreaks = input.bool(true, "BOS / MSS", group=G3)
int swingLength = input.int(8, "Swing Strength", minval=2, maxval=30, group=G3)
float swingATR = input.float(0.6, "Swing Significance ATR", minval=0, step=0.1, group=G3)
int minSwingSpacing = input.int(12, "Minimum Label Spacing", minval=2, group=G3)
string G4 = "04 | FVG"
bool showFVG = input.bool(true, "Show FVG", group=G4)
float fvgATR = input.float(0.15, "Minimum Gap ATR", minval=0, step=0.05, group=G4)
int fvgWidth = input.int(10, "FVG Width", minval=2, maxval=40, group=G4)
int fvgHistory = input.int(5, "Visible FVGs", minval=1, maxval=15, group=G4)
string G5 = "05 | BUY / SELL"
bool enableBuy = input.bool(true, "Enable BUY", group=G5)
bool enableSell = input.bool(true, "Enable SELL", group=G5)
bool showSignals = input.bool(true, "Show BUY / SELL", group=G5)
string entryMode = input.string("Sweep Reclaim", "Entry Mode", options=["Sweep Reclaim", "Sweep + MSS", "Sweep + FVG", "Sweep + MSS or FVG", "Sweep + MSS and FVG"], group=G5)
int confirmWindow = input.int(20, "Confirmation Window", minval=1, maxval=80, group=G5)
int cooldown = input.int(5, "Entry Cooldown Bars", minval=0, maxval=100, group=G5)
bool biasFilter = input.bool(false, "Require HTF Direction", group=G5)
string G6 = "06 | Trade Drawings"
bool showTrade = input.bool(true, "Draw Trades", group=G6)
bool showTradeBoxes = input.bool(true, "Show Risk / Reward Boxes", group=G6)
bool showTradePrices = input.bool(true, "Show Entry / SL / TP Prices", group=G6)
float stopATR = input.float(0.15, "Stop Buffer ATR", minval=0, step=0.05, group=G6)
float target1R = input.float(1.0, "TP1 R", minval=0.25, step=0.25, group=G6)
float target2R = input.float(2.0, "TP2 R", minval=0.5, step=0.25, group=G6)
int tradeWidth = input.int(16, "Trade Projection Width", minval=3, maxval=60, group=G6)
int tradeHistory = input.int(5, "Historical Trade Plans", minval=1, maxval=15, group=G6)
string G7 = "07 | Dashboard"
bool showDashboard = input.bool(true, "Show Dashboard", group=G7)
string dashPos = input.string("Top Right", "Position", options=["Top Right", "Top Left", "Bottom Right", "Bottom Left", "Middle Right", "Middle Left"], group=G7)
string dashSize = input.string("Small", "Size", options=["Tiny", "Small", "Normal", "Large"], group=G7)
// =====================================================
// HELPERS
// =====================================================
f_position(string p) =>
switch p
"Top Left" => position.top_left
"Bottom Right" => position.bottom_right
"Bottom Left" => position.bottom_left
"Middle Right" => position.middle_right
"Middle Left" => position.middle_left
=> position.top_right
f_size(string s) =>
switch s
"Tiny" => size.tiny
"Normal" => size.normal
"Large" => size.large
=> size.small
f_price(float p) =>
str.tostring(p, format.mintick)
// =====================================================
// DATA
// =====================================================
float atr = ta.atr(14)
bool closed = barstate.isconfirmed
bool validTF = timeframe.in_seconds(htf) > timeframe.in_seconds(timeframe.period)
bool newHTF = timeframe.change(htf)
[refO, refH, refL, refC, refT] = request.security(syminfo.tickerid, htf, [open[1], high[1], low[1], close[1], time[1]], lookahead=barmerge.lookahead_on)
bool ready = validTF and not na(refH) and not na(refL) and not na(atr)
bool htfBull = refC >= refO
plot(showReference and ready ? refH : na, "Reference High", color=color.new(RED, 60), style=plot.style_stepline)
plot(showReference and ready ? refL : na, "Reference Low", color=color.new(CYAN, 60), style=plot.style_stepline)
// =====================================================
// CRT REFERENCE BOXES
// =====================================================
var array<box> crtBoxes = array.new<box>()
var box activeCRT = na
var float crtO = na
var float crtH = na
var float crtL = na
var float crtC = na
if ready and closed
if newHTF or na(activeCRT)
crtO := open
crtH := high
crtL := low
crtC := close
activeCRT := box.new(bar_index, crtH, bar_index + 1, crtL)
array.push(crtBoxes, activeCRT)
while array.size(crtBoxes) > crtHistory
box.delete(array.shift(crtBoxes))
else
crtH := math.max(crtH, high)
crtL := math.min(crtL, low)
crtC := close
color c = crtC >= crtO ? CYAN : PURPLE
box.set_right(activeCRT, bar_index + 1)
box.set_top(activeCRT, crtH)
box.set_bottom(activeCRT, crtL)
box.set_bgcolor(activeCRT, color.new(c, showCRT ? 96 : 100))
box.set_border_color(activeCRT, color.new(c, showCRT ? 65 : 100))
box.set_text(activeCRT, showCRT ? "CRT " + htf : "")
box.set_text_color(activeCRT, color.new(c, 30))
box.set_text_size(activeCRT, size.tiny)
box.set_text_halign(activeCRT, text.align_center)
box.set_text_valign(activeCRT, text.align_center)
// =====================================================
// STRUCTURE
// =====================================================
float ph = ta.pivothigh(high, swingLength, swingLength)
float pl = ta.pivotlow(low, swingLength, swingLength)
var float lastHigh = na
var float prevHigh = na
var float lastLow = na
var float prevLow = na
var int highBar = na
var int lowBar = na
var int lastHighLabel = na
var int lastLowLabel = na
var bool highBroken = false
var bool lowBroken = false
var int trend = 0
var array<label> swingLabels = array.new<label>()
var array<line> breakLines = array.new<line>()
var array<label> breakLabels = array.new<label>()
bool bullMSS = false
bool bearMSS = false
bool bullBOS = false
bool bearBOS = false
if closed
if not na(ph)
prevHigh := lastHigh
lastHigh := ph
highBar := bar_index - swingLength
highBroken := false
bool significant = not na(prevHigh) and math.abs(ph - prevHigh) >= atr * swingATR
bool spaced = na(lastHighLabel) or highBar - lastHighLabel >= minSwingSpacing
if showSwings and significant and spaced
bool higher = ph > prevHigh
color c = higher ? CYAN : RED
array.push(swingLabels, label.new(highBar, ph, higher ? "HH" : "LH", style=label.style_label_down, color=color.new(c, 86), textcolor=c, size=size.tiny))
lastHighLabel := highBar
if not na(pl)
prevLow := lastLow
lastLow := pl
lowBar := bar_index - swingLength
lowBroken := false
bool significant = not na(prevLow) and math.abs(pl - prevLow) >= atr * swingATR
bool spaced = na(lastLowLabel) or lowBar - lastLowLabel >= minSwingSpacing
if showSwings and significant and spaced
bool higher = pl > prevLow
color c = higher ? CYAN : RED
array.push(swingLabels, label.new(lowBar, pl, higher ? "HL" : "LL", style=label.style_label_up, color=color.new(c, 86), textcolor=c, size=size.tiny))
lastLowLabel := lowBar
bool breakHigh = not na(lastHigh) and not highBroken and close > lastHigh
bool breakLow = not na(lastLow) and not lowBroken and close < lastLow
if breakHigh and not breakLow
bullMSS := trend == -1
bullBOS := trend == 1
trend := 1
highBroken := true
if showBreaks
string name = bullMSS ? "MSS" : bullBOS ? "BOS" : "BREAK"
color c = bullMSS ? GOLD : CYAN
array.push(breakLines, line.new(math.max(highBar, bar_index - 12), lastHigh, bar_index, lastHigh, color=color.new(c, 45)))
array.push(breakLabels, label.new(bar_index, lastHigh + atr * 0.08, name, style=label.style_none, textcolor=c, size=size.tiny))
if breakLow and not breakHigh
bearMSS := trend == 1
bearBOS := trend == -1
trend := -1
lowBroken := true
if showBreaks
string name = bearMSS ? "MSS" : bearBOS ? "BOS" : "BREAK"
color c = bearMSS ? GOLD : RED
array.push(breakLines, line.new(math.max(lowBar, bar_index - 12), lastLow, bar_index, lastLow, color=color.new(c, 45)))
array.push(breakLabels, label.new(bar_index, lastLow - atr * 0.08, name, style=label.style_none, textcolor=c, size=size.tiny))
while array.size(swingLabels) > 35
label.delete(array.shift(swingLabels))
while array.size(breakLines) > 25
line.delete(array.shift(breakLines))
while array.size(breakLabels) > 25
label.delete(array.shift(breakLabels))
// =====================================================
// FVG
// =====================================================
bool bullGap = closed and low > high[2] and low - high[2] >= atr * fvgATR
bool bearGap = closed and high < low[2] and low[2] - high >= atr * fvgATR
var array<box> gapBoxes = array.new<box>()
if closed and showFVG and (bullGap or bearGap)
bool up = bullGap
color c = up ? CYAN : RED
float top = up ? low : low[2]
float bottom = up ? high[2] : high
box b = box.new(bar_index - 2, top, bar_index + fvgWidth, bottom, bgcolor=color.new(c, 93), border_color=color.new(c, 70))
box.set_text(b, "FVG")
box.set_text_color(b, c)
box.set_text_size(b, size.tiny)
box.set_text_halign(b, text.align_center)
box.set_text_valign(b, text.align_center)
array.push(gapBoxes, b)
while array.size(gapBoxes) > fvgHistory
box.delete(array.shift(gapBoxes))
// =====================================================
// MANIPULATION DETECTION
// =====================================================
var int state = 0
var int direction = 0
var int sweepBar = na
var int reclaimBar = na
var float sweepExtreme = na
var float sweepLevel = na
var int usedBullPeriod = na
var int usedBearPeriod = na
var int lastEntryBar = na
var bool seenMSS = false
var bool seenFVG = false
var int manipulationCount = 0
var int buyCount = 0
var int sellCount = 0
var string crtStatus = "SCANNING"
var string signalStatus = "WAIT"
var string statusReason = "AWAIT SWEEP"
var array<box> manipBoxes = array.new<box>()
var array<label> manipLabels = array.new<label>()
bool bullManip = false
bool bearManip = false
bool buySignal = false
bool sellSignal = false
float tradeEntry = na
float tradeStop = na
float tradeTP1 = na
float tradeTP2 = na
if ready and closed
// Stage 0: Detect sweep of previous completed HTF range.
if state == 0
bool bullSweep = enableBuy and refT != usedBullPeriod and low < refL - atr * minSweep
bool bearSweep = enableSell and refT != usedBearPeriod and high > refH + atr * minSweep
if bullSweep != bearSweep
direction := bullSweep ? 1 : -1
sweepBar := bar_index
sweepExtreme := bullSweep ? low : high
sweepLevel := bullSweep ? refL : refH
seenMSS := false
seenFVG := false
state := 1
crtStatus := "SWEEP"
statusReason := "RECLAIM PENDING"
if bullSweep
usedBullPeriod := refT
else
usedBearPeriod := refT
// Stage 1: Reclaim can occur on the sweep candle.
if state == 1
sweepExtreme := direction == 1 ? math.min(sweepExtreme, low) : math.max(sweepExtreme, high)
bool reclaimed = direction == 1 ? close > sweepLevel : close < sweepLevel
if reclaimed and bar_index - sweepBar <= reclaimWindow
state := 2
reclaimBar := bar_index
bullManip := direction == 1
bearManip := direction == -1
manipulationCount += 1
crtStatus := "MANIPULATION"
statusReason := "RECLAIM CONFIRMED"
float zTop = math.max(sweepLevel, sweepExtreme)
float zBottom = math.min(sweepLevel, sweepExtreme)
if showManipZone
box mb = box.new(sweepBar, zTop, bar_index + 6, zBottom, bgcolor=color.new(GOLD, 87), border_color=color.new(GOLD, 55))
array.push(manipBoxes, mb)
while array.size(manipBoxes) > manipHistory
box.delete(array.shift(manipBoxes))
if showManip
float y = direction == 1 ? zBottom : zTop
label ml = label.new(sweepBar, y, "Manipulation", style=direction == 1 ? label.style_label_up : label.style_label_down, color=color.new(GOLD, 72), textcolor=GOLD, size=size.small)
array.push(manipLabels, ml)
while array.size(manipLabels) > manipHistory
label.delete(array.shift(manipLabels))
else if bar_index - sweepBar > reclaimWindow
state := 0
crtStatus := "SWEEP EXPIRED"
statusReason := "NO RECLAIM"
// Stage 2: Confirmation is independent of drawing toggles.
if state == 2
seenMSS := seenMSS or (direction == 1 ? bullMSS : bearMSS)
seenFVG := seenFVG or (direction == 1 ? bullGap : bearGap)
bool confirmed = switch entryMode
"Sweep + MSS" => seenMSS
"Sweep + FVG" => seenFVG
"Sweep + MSS or FVG" => seenMSS or seenFVG
"Sweep + MSS and FVG" => seenMSS and seenFVG
=> true
bool biasOK = not biasFilter or (direction == 1 ? htfBull : not htfBull)
bool cooldownOK = na(lastEntryBar) or bar_index - lastEntryBar >= cooldown
bool invalid = direction == 1 ? close < sweepExtreme : close > sweepExtreme
if invalid
state := 0
crtStatus := "INVALIDATED"
statusReason := "EXTREME BROKEN"
else if bar_index - reclaimBar > confirmWindow
state := 0
crtStatus := "EXPIRED"
statusReason := "NO CONFIRMATION"
else if confirmed and biasOK and cooldownOK
tradeEntry := close
tradeStop := direction == 1 ? sweepExtreme - atr * stopATR : sweepExtreme + atr * stopATR
float risk = math.abs(tradeEntry - tradeStop)
bool stopOK = direction == 1 ? tradeStop < tradeEntry : tradeStop > tradeEntry
if stopOK and risk > syminfo.mintick
tradeTP1 := tradeEntry + direction * risk * target1R
tradeTP2 := tradeEntry + direction * risk * target2R
buySignal := direction == 1
sellSignal := direction == -1
if buySignal
buyCount += 1
else
sellCount += 1
lastEntryBar := bar_index
signalStatus := buySignal ? "BUY" : "SELL"
crtStatus := "TRADE READY"
statusReason := "ENTRY CONFIRMED"
else
crtStatus := "ENTRY REJECTED"
statusReason := "INVALID STOP"
state := 0
else
crtStatus := "CONFIRM PENDING"
statusReason := not biasOK ? "BIAS FILTER" : not cooldownOK ? "COOLDOWN" : "AWAIT MSS / FVG"
// =====================================================
// BUY / SELL MARKERS
// =====================================================
plotshape(showSignals and buySignal, title="Eclipse BUY", style=shape.labelup, location=location.belowbar, color=CYAN, text="BUY", textcolor=DARK, size=size.small)
plotshape(showSignals and sellSignal, title="Eclipse SELL", style=shape.labeldown, location=location.abovebar, color=RED, text="SELL", textcolor=WHITE, size=size.small)
// =====================================================
// TRADE DRAWINGS
// =====================================================
var array<box> tradeBoxes = array.new<box>()
var array<line> tradeLines = array.new<line>()
var array<label> tradeLabels = array.new<label>()
if closed and showTrade and (buySignal or sellSignal)
int x2 = bar_index + tradeWidth
bool isBuy = buySignal
if showTradeBoxes
box rb = box.new(bar_index, math.max(tradeEntry, tradeStop), x2, math.min(tradeEntry, tradeStop), bgcolor=color.new(RED, 88), border_color=color.new(RED, 65))
box pb = box.new(bar_index, math.max(tradeEntry, tradeTP2), x2, math.min(tradeEntry, tradeTP2), bgcolor=color.new(CYAN, 90), border_color=color.new(CYAN, 65))
array.push(tradeBoxes, rb)
array.push(tradeBoxes, pb)
array.push(tradeLines, line.new(bar_index, tradeEntry, x2, tradeEntry, color=WHITE, width=2))
array.push(tradeLines, line.new(bar_index, tradeStop, x2, tradeStop, color=RED, style=line.style_dashed))
array.push(tradeLines, line.new(bar_index, tradeTP1, x2, tradeTP1, color=GOLD, style=line.style_dotted))
array.push(tradeLines, line.new(bar_index, tradeTP2, x2, tradeTP2, color=CYAN, width=2))
if showTradePrices
array.push(tradeLabels, label.new(x2, tradeEntry, "ENTRY " + f_price(tradeEntry), style=label.style_label_left, color=DARK, textcolor=WHITE, size=size.tiny))
array.push(tradeLabels, label.new(x2, tradeStop, "SL " + f_price(tradeStop), style=label.style_label_left, color=color.new(RED, 35), textcolor=WHITE, size=size.tiny))
array.push(tradeLabels, label.new(x2, tradeTP1, "TP1 " + f_price(tradeTP1), style=label.style_label_left, color=color.new(GOLD, 35), textcolor=DARK, size=size.tiny))
array.push(tradeLabels, label.new(x2, tradeTP2, "TP2 " + f_price(tradeTP2), style=label.style_label_left, color=color.new(CYAN, 35), textcolor=DARK, size=size.tiny))
while array.size(tradeBoxes) > tradeHistory * 2
box.delete(array.shift(tradeBoxes))
while array.size(tradeLines) > tradeHistory * 4
line.delete(array.shift(tradeLines))
while array.size(tradeLabels) > tradeHistory * 4
label.delete(array.shift(tradeLabels))
// =====================================================
// DASHBOARD
// =====================================================
var table dash = table.new(f_position(dashPos), 2, 8, bgcolor=DARK, border_color=color.new(PURPLE, 65), border_width=1)
if barstate.islast
table.clear(dash, 0, 0, 1, 7)
if showDashboard
string biasText = not validTF ? "INVALID TF" : htfBull ? "BULLISH" : "BEARISH"
string trendText = trend == 1 ? "BULLISH" : trend == -1 ? "BEARISH" : "NEUTRAL"
table.cell(dash, 0, 0, "ECLIPSE CRT", text_color=WHITE, bgcolor=color.new(PURPLE, 45), text_size=f_size(dashSize))
table.cell(dash, 1, 0, "TGL 3 V1.8", text_color=WHITE, bgcolor=color.new(PURPLE, 45), text_size=f_size(dashSize))
table.cell(dash, 0, 1, "HTF BIAS", text_color=MUTED, text_size=f_size(dashSize))
table.cell(dash, 1, 1, biasText, text_color=htfBull ? CYAN : RED, text_size=f_size(dashSize))
table.cell(dash, 0, 2, "STRUCTURE", text_color=MUTED, text_size=f_size(dashSize))
table.cell(dash, 1, 2, trendText, text_color=trend == 1 ? CYAN : trend == -1 ? RED : MUTED, text_size=f_size(dashSize))
table.cell(dash, 0, 3, "CRT PHASE", text_color=MUTED, text_size=f_size(dashSize))
table.cell(dash, 1, 3, crtStatus, text_color=GOLD, text_size=f_size(dashSize))
table.cell(dash, 0, 4, "LAST SIGNAL", text_color=MUTED, text_size=f_size(dashSize))
table.cell(dash, 1, 4, signalStatus, text_color=signalStatus == "BUY" ? CYAN : signalStatus == "SELL" ? RED : WHITE, text_size=f_size(dashSize))
table.cell(dash, 0, 5, "MANIPULATIONS", text_color=MUTED, text_size=f_size(dashSize))
table.cell(dash, 1, 5, str.tostring(manipulationCount), text_color=GOLD, text_size=f_size(dashSize))
table.cell(dash, 0, 6, "BUY / SELL", text_color=MUTED, text_size=f_size(dashSize))
table.cell(dash, 1, 6, str.tostring(buyCount) + " / " + str.tostring(sellCount), text_color=CYAN, text_size=f_size(dashSize))
table.cell(dash, 0, 7, "STATUS", text_color=MUTED, text_size=f_size(dashSize))
table.cell(dash, 1, 7, statusReason, text_color=WHITE, text_size=f_size(dashSize))
// =====================================================
// ALERTS
// =====================================================
alertcondition(bullManip, "Bullish Manipulation", "Eclipse bullish manipulation | {{ticker}} | {{interval}}")
alertcondition(bearManip, "Bearish Manipulation", "Eclipse bearish manipulation | {{ticker}} | {{interval}}")
alertcondition(bullMSS, "Bullish MSS", "Eclipse bullish MSS | {{ticker}}")
alertcondition(bearMSS, "Bearish MSS", "Eclipse bearish MSS | {{ticker}}")
alertcondition(buySignal, "Eclipse BUY", "Eclipse BUY | {{ticker}} | {{interval}}")
alertcondition(sellSignal, "Eclipse SELL", "Eclipse SELL | {{ticker}} | {{interval}}")
alertcondition(buySignal or sellSignal, "Eclipse Trade Entry", "Eclipse trade entry | {{ticker}} | {{interval}}")