本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
// [CandleChasers] FVG & Order Blocks | 1.1
// Confirmed patterns, bounded drawings, explicit source timeframes. Indicator only.
indicator("Fair Value Gaps & Order Blocks [CandleChasers]", shorttitle="[CC] Zones", overlay=true, scale=scale.none, max_boxes_count=300, max_lines_count=160, max_labels_count=160, max_bars_back=1000)
string GF = "1 · Fair value gaps"
bool enableFVG = input.bool(true, "Detect fair value gaps", group=GF, display=display.none)
float minimumGap = input.float(0.1, "Minimum gap / ATR", minval=0, step=0.05, group=GF, display=display.none)
bool fvgDisplacement = input.bool(true, "Require directional middle-candle displacement", group=GF, display=display.none)
float fvgBodyATR = input.float(0.5, "Minimum middle body / its ATR", minval=0.1, step=0.1, group=GF, display=display.none)
string fvgFill = input.string("Full fill", "FVG mitigation threshold", options=["First touch", "Midpoint", "Full fill"], group=GF, display=display.none)
string GO = "2 · Order blocks"
bool enableOB = input.bool(true, "Detect structure-break order blocks", group=GO, display=display.none)
int swingLength = input.int(5, "Structure swing left/right bars", minval=2, maxval=30, group=GO, display=display.none)
int obSearch = input.int(20, "Search for last opposite candle / bars", minval=2, maxval=100, group=GO, display=display.none)
string obRange = input.string("Full candle", "Order block boundaries", options=["Full candle", "Body"], group=GO, display=display.none)
bool obDisplacement = input.bool(true, "Require directional breakout displacement", group=GO, display=display.none)
float obBodyATR = input.float(0.6, "Minimum breakout body / ATR", minval=0.1, step=0.1, group=GO, display=display.none)
bool requireGap = input.bool(false, "Require recent same-direction FVG pattern", group=GO, display=display.none)
int confluenceBars = input.int(3, "FVG confluence window / bars", minval=0, maxval=10, group=GO, display=display.none)
string obMitigation = input.string("First touch", "Order block mitigation threshold", options=["First touch", "Midpoint", "Full fill"], group=GO, display=display.none)
string obInvalidation = input.string("Close", "Order block invalidation beyond far edge", options=["Close", "Wick"], group=GO, display=display.none)
bool retireMitigatedOB = input.bool(false, "Retire order blocks once mitigated", group=GO, display=display.none)
string GH = "3 · Higher timeframe"
bool enableHTF = input.bool(false, "Add confirmed higher-timeframe zones", group=GH, display=display.none)
string higherTF = input.timeframe("240", "Higher timeframe", group=GH, display=display.none)
string GM = "4 · Zone management"
int atrLength = input.int(14, "ATR length", minval=2, maxval=100, group=GM, display=display.none)
int maximumAge = input.int(300, "Maximum active age from detection / bars", minval=20, maxval=2000, group=GM, display=display.none)
int activeLimit = input.int(30, "Maximum live zones", minval=5, maxval=60, group=GM, display=display.none)
bool keepHistory = input.bool(true, "Keep filled / invalidated / expired zones", group=GM, display=display.none)
int historyLimit = input.int(20, "Maximum retired zones", minval=0, maxval=60, group=GM, display=display.none)
string GD = "5 · Context and display filters"
string displayMode = input.string("Nearest", "Zone display", options=["Nearest", "All live"], group=GD, display=display.none)
int nearestCount = input.int(3, "Nearest zones above / below", minval=1, maxval=10, group=GD, display=display.none)
bool freshOnly = input.bool(false, "Show untouched zones only", group=GD, display=display.none)
bool showMitigated = input.bool(true, "Show live mitigated order blocks", group=GD, display=display.none)
float minimumGrade = input.float(0, "Minimum displayed evidence grade", minval=0, maxval=100, group=GD, display=display.none)
bool showFill = input.bool(true, "Show FVG fill percentage / overlay", group=GD, display=display.none)
bool highlightOverlap = input.bool(true, "Highlight same-direction FVG / OB overlap", group=GD, display=display.none)
bool showRejections = input.bool(false, "Mark first-retest rejection candles", group=GD, display=display.none)
string GV = "6 · Appearance"
int projection = input.int(10, "Live projection / chart periods", minval=1, maxval=100, group=GV, display=display.none)
bool originPlacement = input.bool(false, "Draw from origin candle (historical placement)", group=GV, display=display.none)
bool showMidpoint = input.bool(true, "Show 50% midpoint", group=GV, display=display.none)
bool showTags = input.bool(true, "Show active zone price labels", group=GV, display=display.none)
string labelSize = input.string("Medium", "Zone label size", options=["Small", "Medium", "Large", "Extra Large"], group=GV, display=display.none)
int fillTransparency = input.int(88, "Live fill transparency", minval=50, maxval=98, group=GV, display=display.none)
color bullFVGColor = input.color(#00CFA8, "Bullish FVG", group=GV, display=display.none)
color bearFVGColor = input.color(#F06A8A, "Bearish FVG", group=GV, display=display.none)
color bullOBColor = input.color(#62A8FF, "Bullish order block", group=GV, display=display.none)
color bearOBColor = input.color(#FFB65C, "Bearish order block", group=GV, display=display.none)
string panelSize = input.string("Small", "Dashboard size", options=["Small", "Medium", "Large", "Hidden"], group=GV, display=display.none)
string panelCorner = input.string("Top Right", "Dashboard position", options=["Top Left", "Top Right", "Bottom Left", "Bottom Right"], group=GV, display=display.none)
string GA = "7 · Alerts"
bool alertNew = input.bool(true, "New FVG / order block alerts", group=GA, display=display.none)
bool alertTouch = input.bool(false, "First zone retest alerts", group=GA, display=display.none)
bool alertMitigation = input.bool(true, "Fill / mitigation alerts", group=GA, display=display.none)
bool alertInvalidation = input.bool(true, "Invalidation alerts", group=GA, display=display.none)
bool alertRejection = input.bool(false, "First-retest rejection alerts", group=GA, display=display.none)
color panelBG = color.rgb(18, 24, 35)
string zoneFont = labelSize == "Extra Large" ? size.huge : labelSize == "Large" ? size.large : labelSize == "Medium" ? size.normal : size.small
int chartMS = int(timeframe.in_seconds() * 1000)
bool validHTF = timeframe.in_seconds(higherTF) > timeframe.in_seconds()
f_price(float value) =>
str.tostring(value, format.mintick)
f_event(string events, bool enabled, string eventText) =>
enabled ? events + (str.length(events) > 0 ? " | " : "") + eventText : events
f_origin(int direction) =>
int offset = na
for i = 1 to obSearch
if (direction == 1 ? close[i] < open[i] : close[i] > open[i]) and not na(high[i])
offset := i
break
offset
// One detector shared by chart and HTF contexts. Contains no drawings or alerts.
f_detector() =>
float a = ta.atr(atrLength)
float ph = ta.pivothigh(high, swingLength, swingLength)
float pl = ta.pivotlow(low, swingLength, swingLength)
var float sh = na
var float sl = na
var bool highUsed = false
var bool lowUsed = false
var int lastBullGap = na
var int lastBearGap = na
var int lastBullOrigin = na
var int lastBearOrigin = na
int fd = 0
float ft = na
float fb = na
int fo = na
float fdisp = na
float fevidence = na
int od = 0
float ot = na
float ob = na
int oo = na
float odisp = na
float oevidence = na
bool bg = bar_index >= 2 and low > high[2] and low - high[2] >= a * minimumGap and (not fvgDisplacement or close[1] - open[1] >= a[1] * fvgBodyATR)
bool sg = bar_index >= 2 and high < low[2] and low[2] - high >= a * minimumGap and (not fvgDisplacement or open[1] - close[1] >= a[1] * fvgBodyATR)
if not na(a) and a > 0
if bg
lastBullGap := bar_index
if sg
lastBearGap := bar_index
if enableFVG and (bg or sg)
fd := bg ? 1 : -1
ft := bg ? low : low[2]
fb := bg ? high[2] : high
fo := time[2]
fdisp := not na(a[1]) and a[1] > 0 ? math.max(0, fd * (close[1] - open[1])) / a[1] : 0.0
fevidence := (ft - fb) / a
bool bh = not na(sh) and not highUsed and close > sh
bool bl = not na(sl) and not lowUsed and close < sl
if bh
highUsed := true
if bl
lowUsed := true
if enableOB and (bh != bl)
int direction = bh ? 1 : -1
bool bodyOK = not obDisplacement or direction * (close - open) >= a * obBodyATR
bool gapOK = not requireGap or (direction == 1 ? not na(lastBullGap) and bar_index - lastBullGap <= confluenceBars : not na(lastBearGap) and bar_index - lastBearGap <= confluenceBars)
int offset = f_origin(direction)
if bodyOK and gapOK and not na(offset)
float top = obRange == "Body" ? math.max(open[offset], close[offset]) : high[offset]
float bottom = obRange == "Body" ? math.min(open[offset], close[offset]) : low[offset]
bool uniqueOrigin = direction == 1 ? na(lastBullOrigin) or time[offset] != lastBullOrigin : na(lastBearOrigin) or time[offset] != lastBearOrigin
bool intact = top > bottom
for j = 0 to offset - 1
bool breached = obInvalidation == "Wick" ? (direction == 1 ? low[j] < bottom : high[j] > top) : (direction == 1 ? close[j] < bottom : close[j] > top)
if breached
intact := false
if intact and uniqueOrigin
od := direction
ot := top
ob := bottom
oo := time[offset]
odisp := math.max(0, direction * (close - open)) / a
oevidence := math.max(0, direction * (close - (direction == 1 ? sh : sl))) / a
if direction == 1
lastBullOrigin := oo
else
lastBearOrigin := oo
// Pivots confirmed now cannot affect this candle's break tests.
if not na(ph)
sh := ph
highUsed := false
if not na(pl)
sl := pl
lowUsed := false
[fd, ft, fb, fo, fdisp, fevidence, od, ot, ob, oo, odisp, oevidence, time, time_close]
f_confirmedDetector() =>
[fd, ft, fb, fo, fdisp, fevidence, od, ot, ob, oo, odisp, oevidence, stamp, closed] = f_detector()
[fd[1], ft[1], fb[1], fo[1], fdisp[1], fevidence[1], od[1], ot[1], ob[1], oo[1], odisp[1], oevidence[1], stamp[1], closed[1]]
[chartFD, chartFT, chartFB, chartFO, chartFDisp, chartFEvidence, chartOD, chartOT, chartOB, chartOO, chartODisp, chartOEvidence, chartStamp, chartClosed] = f_detector()
int hFD = 0
float hFT = na
float hFB = na
int hFO = na
float hFDisp = na
float hFEvidence = na
int hOD = 0
float hOT = na
float hOB = na
int hOO = na
float hODisp = na
float hOEvidence = na
int hStamp = na
int hClosed = na
if enableHTF and validHTF
[fd, ft, fb, fo, fdisp, fevidence, od, ot, ob, oo, odisp, oevidence, stamp, closed] = request.security(syminfo.tickerid, higherTF, f_confirmedDetector(), lookahead=barmerge.lookahead_on)
hFD := fd
hFT := ft
hFB := fb
hFO := fo
hFDisp := fdisp
hFEvidence := fevidence
hOD := od
hOT := ot
hOB := ob
hOO := oo
hODisp := odisp
hOEvidence := oevidence
hStamp := stamp
hClosed := closed
type Zone
float top
float bottom
int direction
bool isOB
int born
int stamp
int origin
int sourceClose
string sourceTF
bool higher
int id
color tint
float displacement
float evidence
bool touched = false
bool mitigated = false
bool overlapped = false
bool visible = true
float filled = 0.0
float grade = 0.0
int finish = na
string state = "FRESH"
box area = na
box fillArea = na
line middle = na
label tag = na
var array<Zone> live = array.new<Zone>()
var array<Zone> retired = array.new<Zone>()
var array<box> overlapAreas = array.new<box>(6, na)
var int nextId = 0
var int lastHTFStamp = na
f_name(Zone z) =>
(z.direction == 1 ? "BULL " : "BEAR ") + (z.isOB ? "OB" : "FVG") + " [" + (z.higher ? "HTF " : "") + z.sourceTF + "] #" + str.tostring(z.id)
f_alertName(Zone z) =>
f_name(z) + " " + f_price(z.bottom) + "–" + f_price(z.top)
f_hide(Zone z) =>
if not na(z.area)
box.delete(z.area)
z.area := na
if not na(z.fillArea)
box.delete(z.fillArea)
z.fillArea := na
if not na(z.middle)
line.delete(z.middle)
z.middle := na
if not na(z.tag)
label.delete(z.tag)
z.tag := na
true
f_draw(Zone z, bool active) =>
int leftEdge = originPlacement ? z.origin : z.stamp
int rightEdge = active ? time + chartMS * projection : z.finish
bool overlapStyle = active and highlightOverlap and z.overlapped
color border = overlapStyle ? color.rgb(255, 225, 100) : color.new(z.tint, active ? 0 : 55)
string borderStyle = active ? (z.mitigated ? line.style_dotted : line.style_solid) : (z.state == "INVALID" ? line.style_dashed : line.style_dotted)
if na(z.area)
z.area := box.new(left=leftEdge, top=z.top, right=rightEdge, bottom=z.bottom, xloc=xloc.bar_time, bgcolor=color.new(z.tint, fillTransparency), force_overlay=true)
box.set_right(z.area, rightEdge)
box.set_border_color(z.area, border)
box.set_border_style(z.area, borderStyle)
box.set_border_width(z.area, overlapStyle ? 3 : z.isOB or z.higher ? 2 : 1)
box.set_bgcolor(z.area, color.new(z.tint, not active or z.mitigated ? 95 : fillTransparency))
if showMidpoint
if na(z.middle)
z.middle := line.new(leftEdge, (z.top + z.bottom) / 2, rightEdge, (z.top + z.bottom) / 2, xloc=xloc.bar_time, style=line.style_dashed, force_overlay=true)
line.set_x2(z.middle, rightEdge)
line.set_color(z.middle, color.new(z.tint, active ? 20 : 65))
if showFill and not z.isOB and z.filled > 0
float frontier = z.direction == 1 ? z.top - (z.top-z.bottom)*z.filled : z.bottom + (z.top-z.bottom)*z.filled
float fillTop = z.direction == 1 ? z.top : frontier
float fillBottom = z.direction == 1 ? frontier : z.bottom
if na(z.fillArea)
z.fillArea := box.new(leftEdge, fillTop, rightEdge, fillBottom, xloc=xloc.bar_time, border_color=color.new(color.gray, 100), bgcolor=color.new(color.gray, active ? 80 : 95), force_overlay=true)
box.set_right(z.fillArea, rightEdge)
box.set_top(z.fillArea, fillTop)
box.set_bottom(z.fillArea, fillBottom)
box.set_bgcolor(z.fillArea, color.new(color.gray, active ? 80 : 95))
if active and showTags
if na(z.tag)
z.tag := label.new(rightEdge, z.top, "", xloc=xloc.bar_time, style=label.style_label_lower_left, color=panelBG, textcolor=z.tint, size=zoneFont, force_overlay=true)
label.set_xy(z.tag, rightEdge, z.top)
string suffix = showFill and not z.isOB ? " · " + str.tostring(z.filled*100, "#") + "% filled" : ""
label.set_text(z.tag, f_name(z) + " · " + z.state + suffix + "\n" + f_price(z.bottom) + "–" + f_price(z.top) + " · E " + str.tostring(z.grade, "#") + "/100")
label.set_tooltip(z.tag, "Source TF: " + z.sourceTF + (z.higher ? " (completed HTF)" : " (chart)") + "\nSource close ms: " + str.tostring(z.sourceClose) + "\nObserved chart bar: " + str.tostring(z.born) + "\nMidpoint: " + f_price((z.top+z.bottom)/2) + "\nEvidence points: displacement " + str.tostring(40*math.min(1,z.displacement/1.5), "#.##") + "/40; " + (z.isOB ? "break distance " : "gap size ") + str.tostring(40*math.min(1,z.evidence/0.5), "#.##") + "/40; live same-direction FVG/OB overlap " + (z.overlapped ? "20" : "0") + "/20\nEvidence grade is not win probability. Overlap points can change as zones retire.\nState/alerts remain tracked even when display filters hide this zone.")
true
f_retire(Zone z, string reason) =>
z.state := reason
z.finish := na(time_close) ? time : time_close
if not na(z.tag)
label.delete(z.tag)
z.tag := na
if keepHistory and historyLimit > 0
f_draw(z, false)
array.push(retired,z)
while array.size(retired)>historyLimit
f_hide(array.shift(retired))
true
else
f_hide(z)
true
true
f_add(float top, float bottom, int direction, bool isOB, int origin, int sourceClose, string tf, bool higher, float disp, float evidence, int id) =>
if array.size(live)>=activeLimit
int victim = 0
for i=0 to array.size(live)-1
Zone candidate = array.get(live,i)
if candidate.mitigated
victim:=i
break
f_retire(array.remove(live,victim),"CAPACITY")
color tint = isOB ? (direction==1 ? bullOBColor : bearOBColor) : (direction==1 ? bullFVGColor : bearFVGColor)
Zone z = Zone.new(top,bottom,direction,isOB,bar_index,time,origin,sourceClose,tf,higher,id,tint,disp,evidence)
z.grade := 40*math.min(1,disp/1.5) + 40*math.min(1,evidence/0.5)
array.push(live,z)
z
f_threshold(Zone z,string mode) =>
mode=="Midpoint" ? (z.top+z.bottom)/2 : mode=="Full fill" ? (z.direction==1 ? z.bottom : z.top) : (z.direction==1 ? z.top : z.bottom)
f_intersects(Zone a, Zone b) =>
a.direction==b.direction and a.isOB!=b.isOB and math.min(a.top,b.top)>math.max(a.bottom,b.bottom)
f_eligible(Zone z) =>
(not freshOnly or not z.touched) and (showMitigated or not z.mitigated) and z.grade>=minimumGrade
f_distance(Zone z) =>
close<z.bottom ? z.bottom-close : close>z.top ? close-z.top : 0.0
f_side(Zone z) =>
z.bottom>close ? 1 : z.top<close ? -1 : 0
bool newBullFVG=false
bool newBearFVG=false
bool newBullOB=false
bool newBearOB=false
bool fvgTouchEvent=false
bool obTouchEvent=false
bool fillEvent=false
bool mitigationEvent=false
bool fvgInvalidEvent=false
bool obInvalidEvent=false
bool bullRejection=false
bool bearRejection=false
string events=""
if barstate.isconfirmed
// Import before lifecycle management: first chart candle after HTF close can retest it.
if enableHTF and validHTF and not na(hStamp) and (na(lastHTFStamp) or hStamp!=lastHTFStamp)
lastHTFStamp:=hStamp
if hFD!=0
nextId+=1
Zone z=f_add(hFT,hFB,hFD,false,hFO,hClosed,higherTF,true,hFDisp,hFEvidence,nextId)
newBullFVG:=hFD==1
newBearFVG:=hFD==-1
events:=f_event(events,alertNew,f_alertName(z)+" NEW")
if hOD!=0
nextId+=1
Zone z=f_add(hOT,hOB,hOD,true,hOO,hClosed,higherTF,true,hODisp,hOEvidence,nextId)
newBullOB:=hOD==1
newBearOB:=hOD==-1
events:=f_event(events,alertNew,f_alertName(z)+" NEW")
if array.size(live)>0
for i=array.size(live)-1 to 0
Zone z=array.get(live,i)
bool expired=bar_index-z.born>maximumAge
bool invalid=(z.isOB and obInvalidation=="Wick") ? (z.direction==1 ? low<z.bottom : high>z.top) : (z.direction==1 ? close<z.bottom : close>z.top)
bool overlaps=high>=z.bottom and low<=z.top
float threshold=f_threshold(z,z.isOB ? obMitigation : fvgFill)
bool reached=overlaps and (z.direction==1 ? low<=threshold : high>=threshold)
bool terminal=false
string reason=""
if expired
terminal:=true
reason:="EXPIRED"
else if invalid
terminal:=true
reason:="INVALID"
if z.isOB
obInvalidEvent:=true
else
fvgInvalidEvent:=true
events:=f_event(events,alertInvalidation,f_alertName(z)+" INVALID")
else
if overlaps and not z.isOB
float penetration=z.direction==1 ? (z.top-low)/(z.top-z.bottom) : (high-z.bottom)/(z.top-z.bottom)
z.filled:=math.max(z.filled,math.max(0,math.min(1,penetration)))
if overlaps and not z.touched
z.touched:=true
z.state:="TOUCHED"
if z.isOB
obTouchEvent:=true
else
fvgTouchEvent:=true
events:=f_event(events,alertTouch,f_alertName(z)+" FIRST_RETEST")
bool rejects=z.direction==1 ? close>z.top and close>open : close<z.bottom and close<open
if rejects
bullRejection:=bullRejection or z.direction==1
bearRejection:=bearRejection or z.direction==-1
events:=f_event(events,alertRejection,f_alertName(z)+" FIRST_RETEST_REJECTION")
if reached and not z.mitigated
z.mitigated:=true
z.state:="MITIGATED"
if z.isOB
mitigationEvent:=true
else
fillEvent:=true
events:=f_event(events,alertMitigation,f_alertName(z)+(z.isOB ? " MITIGATED" : " FILLED"))
if not z.isOB or retireMitigatedOB
terminal:=true
reason:="MITIGATED"
if terminal
f_retire(z,reason)
array.remove(live,i)
// Chart zones form after old-zone management; formation candles are excluded from retests.
if chartFD!=0
nextId+=1
Zone z=f_add(chartFT,chartFB,chartFD,false,chartFO,chartClosed,timeframe.period,false,chartFDisp,chartFEvidence,nextId)
newBullFVG:=newBullFVG or chartFD==1
newBearFVG:=newBearFVG or chartFD==-1
events:=f_event(events,alertNew,f_alertName(z)+" NEW")
if chartOD!=0
nextId+=1
Zone z=f_add(chartOT,chartOB,chartOD,true,chartOO,chartClosed,timeframe.period,false,chartODisp,chartOEvidence,nextId)
newBullOB:=newBullOB or chartOD==1
newBearOB:=newBearOB or chartOD==-1
events:=f_event(events,alertNew,f_alertName(z)+" NEW")
if barstate.islast
// Evidence and nearest selection use every live zone; hiding never removes tracking.
if array.size(live)>0
for i=0 to array.size(live)-1
Zone z=array.get(live,i)
z.overlapped:=false
for j=0 to array.size(live)-1
if i!=j and f_intersects(z,array.get(live,j))
z.overlapped:=true
z.grade:=40*math.min(1,z.displacement/1.5)+40*math.min(1,z.evidence/0.5)+(z.overlapped ? 20 : 0)
for i=0 to array.size(live)-1
Zone z=array.get(live,i)
int rank=0
if f_eligible(z) and displayMode=="Nearest"
float distance=f_distance(z)
for j=0 to array.size(live)-1
Zone other=array.get(live,j)
if i!=j and f_eligible(other) and f_side(z)==f_side(other)
float otherDistance=f_distance(other)
if otherDistance<distance or (otherDistance==distance and other.id>z.id)
rank+=1
int limit=f_side(z)==0 ? 2 : nearestCount
z.visible:=f_eligible(z) and (displayMode=="All live" or rank<limit)
if z.visible
f_draw(z,true)
else
f_hide(z)
// Reuse up to six intersection boxes among displayed zones, newest pairs first.
int used=0
if highlightOverlap and array.size(live)>1
for i=array.size(live)-1 to 1
Zone a=array.get(live,i)
if a.visible
for j=i-1 to 0
Zone b=array.get(live,j)
if used<6 and b.visible and f_intersects(a,b)
float overlapTop=math.min(a.top,b.top)
float overlapBottom=math.max(a.bottom,b.bottom)
int leftEdge=math.max(a.stamp,b.stamp)
int rightEdge=time+chartMS*projection
box area=array.get(overlapAreas,used)
if na(area)
area:=box.new(leftEdge,overlapTop,rightEdge,overlapBottom,xloc=xloc.bar_time,border_color=color.new(color.yellow,45),bgcolor=color.new(color.yellow,85),force_overlay=true)
array.set(overlapAreas,used,area)
box.set_left(area,leftEdge)
box.set_right(area,rightEdge)
box.set_top(area,overlapTop)
box.set_bottom(area,overlapBottom)
used+=1
for i=0 to 5
if i>=used
box area=array.get(overlapAreas,i)
if not na(area)
box.delete(area)
array.set(overlapAreas,i,na)
plotshape(showRejections and bullRejection,title="Bullish first retest rejection",style=shape.triangleup,location=location.belowbar,color=bullOBColor,size=size.small,force_overlay=true)
plotshape(showRejections and bearRejection,title="Bearish first retest rejection",style=shape.triangledown,location=location.abovebar,color=bearOBColor,size=size.small,force_overlay=true)
string panelPosition=panelCorner=="Top Left" ? position.top_left : panelCorner=="Bottom Left" ? position.bottom_left : panelCorner=="Bottom Right" ? position.bottom_right : position.top_right
var table panel=table.new(panelPosition,2,12,bgcolor=panelBG,frame_color=color.gray,frame_width=1)
if barstate.islast
if panelSize!="Hidden"
int fvgCount=0
int obCount=0
int shown=0
int htfCount=0
int overlapCount=0
if array.size(live)>0
for i=0 to array.size(live)-1
Zone z=array.get(live,i)
fvgCount+=z.isOB ? 0 : 1
obCount+=z.isOB ? 1 : 0
shown+=z.visible ? 1 : 0
htfCount+=z.higher ? 1 : 0
overlapCount+=z.overlapped ? 1 : 0
string panelFont=panelSize=="Large" ? size.large : panelSize=="Medium" ? size.normal : size.small
array<string> keys=array.from("[CandleChasers]","Live FVG / OB","Displayed / live","Retired history","HTF live zones","HTF status","Overlap participants","Display","FVG threshold","OB threshold / invalid","Age limit","Evidence grade")
array<string> values=array.from("FVG & ORDER BLOCKS 1.1",str.tostring(fvgCount)+" / "+str.tostring(obCount),str.tostring(shown)+" / "+str.tostring(array.size(live)),str.tostring(array.size(retired)),str.tostring(htfCount),not enableHTF ? "Off" : not validHTF ? "Select strictly higher TF" : higherTF+" · confirmed",str.tostring(overlapCount),displayMode+(freshOnly ? " · fresh only" : ""),fvgFill,obMitigation+" / "+obInvalidation,str.tostring(maximumAge)+" chart bars","Evidence ≠ win probability")
for row=0 to 11
table.cell(panel,0,row,array.get(keys,row),bgcolor=panelBG,text_color=color.rgb(205,213,225),text_size=panelFont)
table.cell(panel,1,row,array.get(values,row),bgcolor=panelBG,text_color=color.white,text_size=panelFont)
else
table.clear(panel,0,0,1,11)
if barstate.isconfirmed and str.length(events)>0
alert("[CandleChasers] "+syminfo.tickerid+" chart "+timeframe.period+" | "+events,alert.freq_once_per_bar_close)
alertcondition(alertNew and newBullFVG,"New bullish FVG","[CandleChasers] Bullish FVG confirmed on {{ticker}} {{interval}}. Use alert() for source TF and boundaries.")
alertcondition(alertNew and newBearFVG,"New bearish FVG","[CandleChasers] Bearish FVG confirmed on {{ticker}} {{interval}}. Use alert() for source TF and boundaries.")
alertcondition(alertNew and newBullOB,"New bullish order block","[CandleChasers] Bullish OB confirmed on {{ticker}} {{interval}}. Use alert() for source TF and boundaries.")
alertcondition(alertNew and newBearOB,"New bearish order block","[CandleChasers] Bearish OB confirmed on {{ticker}} {{interval}}. Use alert() for source TF and boundaries.")
alertcondition(alertTouch and fvgTouchEvent,"First FVG retest","[CandleChasers] First FVG retest on {{ticker}} {{interval}}.")
alertcondition(alertTouch and obTouchEvent,"First OB retest","[CandleChasers] First OB retest on {{ticker}} {{interval}}.")
alertcondition(alertMitigation and fillEvent,"FVG fill threshold","[CandleChasers] FVG mitigation threshold reached on {{ticker}} {{interval}}.")
alertcondition(alertMitigation and mitigationEvent,"OB mitigation","[CandleChasers] OB mitigation threshold reached on {{ticker}} {{interval}}.")
alertcondition(alertInvalidation and fvgInvalidEvent,"FVG invalidated","[CandleChasers] FVG invalidated on {{ticker}} {{interval}}.")
alertcondition(alertInvalidation and obInvalidEvent,"OB invalidated","[CandleChasers] OB invalidated on {{ticker}} {{interval}}.")
alertcondition(alertRejection and bullRejection,"Bullish first-retest rejection","[CandleChasers] Bullish first-retest rejection on {{ticker}} {{interval}}.")
alertcondition(alertRejection and bearRejection,"Bearish first-retest rejection","[CandleChasers] Bearish first-retest rejection on {{ticker}} {{interval}}.")