本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © EyeAlgo
// Eye Imbalance Zones — by Eye Algo (original code)
// 1. Imbalance zones: every fair value gap (3-candle imbalance) becomes a demand or supply zone. If the last opposite candle
// before the move (the order block) is found, the two are stacked into one "FVG + OB" zone. Gaps from one higher
// timeframe can be added too (HTF zones, confirmed on the HTF bar close).
// 2. Zone grade ⭐ / ⭐⭐ / ⭐⭐⭐: ⭐ gap found, ⭐ strong displacement candle, ⭐ high volume on that candle.
// 3. Fill meter: each live zone shows how much of the gap price has already used.
// 4. First-touch scoreboard: the first time price comes back to a zone, the script records HELD or BROKEN.
// The dashboard shows the measured held rate per zone type, per grade and per session on this symbol.
// 5. Flips: a zone broken by a close becomes an inverse zone (iFVG); the order block of a broken FVG + OB zone becomes a breaker.
//@version=6
indicator("Eye Imbalance Zones [EyeAlgo]", overlay = true, max_boxes_count = 500, max_lines_count = 500, max_labels_count = 500, max_bars_back = 100)
// ═══════════════════════════════════════════════════════════════════════════
// SETTINGS
// ═══════════════════════════════════════════════════════════════════════════
GZ = "🧱 Imbalance Zones"
minGap = input.float(0.15, "Minimum gap size (× ATR)", minval = 0.0, step = 0.05, group = GZ, display = display.none,
tooltip = "A fair value gap must be at least this many 14-bar ATRs tall to become a zone. Smaller gaps are ignored.")
needDir = input.bool(true, "Middle candle must close in the move's direction", group = GZ, display = display.none,
tooltip = "On = a bullish gap needs a green middle candle, a bearish gap a red one.")
obLook = input.int(5, "Order block search (bars before the move)", minval = 1, maxval = 20, group = GZ, display = display.none,
tooltip = "Looks back this many candles before the move for the last opposite-colour candle (the order block). Found = the zone becomes 'FVG + OB'.")
obBody = input.bool(false, "Order block = candle body only", group = GZ, display = display.none, tooltip = "Off = the order block candle's full high-low range.")
mergeW = input.int(3, "Merge overlapping zones formed within (bars)", minval = 0, maxval = 10, group = GZ, display = display.none,
tooltip = "A new gap that overlaps or sits right next to (within 0.25 ATR) an untouched zone on the same side formed within this many bars is merged into it, so one move gives one zone. 0 = never merge.")
mitMode = input.string("Close beyond", "Zone removed when", options = ["Close beyond", "Wick beyond", "50% reached"], group = GZ, display = display.none,
tooltip = "Close beyond = a close beyond the break level (the gap, or the order block for FVG + OB zones). Wick beyond = any trade beyond it. 50% reached = price trades to the middle of the gap. A zone still waiting for its first-touch result is kept until that result is known. Only a close beyond creates an inverse zone or breaker. This also changes the statistics: with Wick beyond or 50% reached, fewer zones survive to be closed through, so fewer inverse / breaker zones are created and scored.")
showInv = input.bool(true, "Broken zones flip into inverse zones (iFVG)", group = GZ, display = display.none,
tooltip = "When a close breaks through a zone, its gap becomes a zone on the other side (a broken demand zone becomes supply, and the other way round). Chart-timeframe zones only.")
showBrk = input.bool(true, "Broken FVG + OB zones leave a breaker", group = GZ, display = display.none,
tooltip = "When a close breaks through an FVG + OB zone, its order block becomes a breaker zone on the other side.")
maxAge = input.int(600, "Zone expires after (bars)", minval = 50, maxval = 4900, group = GZ, display = display.none,
tooltip = "Chart-timeframe zones are removed after this many bars. HTF zones live this many HTF candles' worth of bars, so they are not dropped before price can reach them. Zones that expire before price returns are never scored, so this setting changes the statistics. If more than 100 zones are live at once, the oldest untouched zones are dropped and never scored (shown in the full statistics rows).")
GH = "🕐 Higher Timeframe & Sessions"
useHtf = input.bool(true, "Add gaps from a higher timeframe", group = GH, display = display.none,
tooltip = "Gaps found on this timeframe are added as 'FVG <HTF>' zones (e.g. 'FVG 4H') once the higher-timeframe candle has closed (no repaint). Only used when it is higher than the chart timeframe.")
htfTf = input.timeframe("240", "Higher timeframe", group = GH, display = display.none)
sesF = input.string("All", "Only zones formed in", options = ["All", "Asia", "London", "New York", "London + New York"], group = GH, display = display.none,
tooltip = "Intraday charts only, chart-timeframe zones only. Session of the middle (displacement) candle, by UTC hour: Asia 00–07, London 07–13, New York 13–22 (22–24 counts as Asia), fixed UTC hours with no daylight-saving shift. Zones from other sessions are not created at all, so they and their inverse / breaker zones are left out of every statistic. HTF zones are not filtered.")
showPD = input.bool(true, "Show previous day high / low", group = GH, display = display.none)
showPW = input.bool(false, "Show previous week high / low", group = GH, display = display.none)
GG = "⭐ Zone Grade"
dispMin = input.float(1.2, "⭐ Strong displacement: middle candle body ≥ (× ATR)", minval = 0.1, step = 0.1, group = GG, display = display.none)
volMin = input.float(1.3, "⭐ High volume: middle candle volume ≥ (× 50-bar average)", minval = 1.05, step = 0.1, group = GG, display = display.none,
tooltip = "Needs volume data (tick volume on forex / CFD). Without volume data no zone gets this star, so ⭐⭐⭐ cannot appear.")
GR = "🎯 First-Touch Reaction"
reactATR = input.float(1.0, "HELD = close this far away from the zone (× ATR)", minval = 0.25, step = 0.25, group = GR, display = display.none,
tooltip = "After the first touch, a close this many 14-bar ATRs (measured at the touch) away from the zone's near edge = HELD. A close the same distance back through the near edge, or a close beyond the break level = BROKEN. HTF zones use the higher timeframe's ATR. The same rule for every zone type.")
reactW = input.int(12, "Reaction window after the first touch (bars)", minval = 2, maxval = 100, group = GR, display = display.none,
tooltip = "HELD or BROKEN must happen within this many bars (the touch bar included), otherwise the touch counts as 'no decision'. HTF zones get the same number of higher-timeframe candles (counted in chart bars, max 3000), so every type has the same time to react. No decision counts as not held in the %.")
minSamp = input.int(30, "Minimum samples before a % is shown", minval = 5, maxval = 500, group = GR, display = display.none,
tooltip = "A held rate is shown only after this many finished first touches; small samples move a lot.")
GD = "🎨 Display"
maxShow = input.int(3, "Zones shown per side (nearest)", minval = 1, maxval = 8, group = GD, display = display.none)
maxDist = input.float(6.0, "Hide zones further than (× ATR)", minval = 1.0, step = 0.5, group = GD, display = display.none,
tooltip = "Zones and levels further than this many 50-bar ATRs from price are not drawn, so the price scale is not squeezed. Zones are still tracked.")
showOB = input.bool(true, "Show order block part", group = GD, display = display.none)
showCE = input.bool(true, "Show 50% line of the gap", group = GD, display = display.none)
showFill = input.bool(true, "Show fill meter (part of the gap already used)", group = GD, display = display.none)
showHist = input.bool(true, "Show finished zones and ✓ / ✗ first-touch marks", group = GD, display = display.none, tooltip = "No mark is drawn for 'no decision'.")
fullHist = input.bool(false, "Show past zones on the full chart", group = GD, display = display.none,
tooltip = "On = on every past candle, the nearest demand zone below price and the nearest supply zone above price that were live at that moment are shaded, across the whole chart history (no drawing limit). The last 300 ✓ / ✗ marks also stay. Off = only the latest finished zones near price.")
keepHist = input.int(10, "Finished zones kept on chart (✓ / ✗ marks: max 15)", minval = 1, maxval = 100, group = GD, display = display.none,
tooltip = "✓ / ✗ marks: the same number, max 15.")
ext = input.int(12, "Extend zones right (bars)", minval = 2, maxval = 50, group = GD, display = display.none)
demC = input.color(#22C997, "Demand", inline = "c1", group = GD, display = display.none)
supC = input.color(#F2547D, "Supply", inline = "c1", group = GD, display = display.none)
invC = input.color(#A78BFA, "Inverse", inline = "c2", group = GD, display = display.none)
bkrC = input.color(#FF9800, "Breaker", inline = "c2", group = GD, display = display.none)
htfC = input.color(#4FC3F7, "HTF zone", inline = "c3", group = GD, display = display.none)
lvlC = input.color(#78909C, "Levels", inline = "c3", group = GD, display = display.none)
hdrC = input.color(#1E2433, "Table header", group = GD, display = display.none)
showLg = input.bool(true, "Show colour legend", group = GD, display = display.none)
GT = "📋 Table & Alerts"
showTb = input.bool(true, "Show summary table", group = GT, display = display.none)
showFull = input.bool(false, "Show full statistics rows", group = GT, display = display.none, tooltip = "Adds sample counts, zones tracked and average bars to the first touch.")
tbPos = input.string("Top right", "Table position", options = ["Top right", "Top left", "Bottom right", "Bottom left"], group = GT, display = display.none)
showBn = input.bool(true, "Show status banner (bottom)", group = GT, display = display.none)
detailAlerts = input.bool(true, "Detailed alert() messages", group = GT, display = display.none,
tooltip = "Create the alert with 'Any alert() function call' to get the zone range, type and grade in the message (new zones, first touch, retest).")
// ═══════════════════════════════════════════════════════════════════════════
// COMMON
// ═══════════════════════════════════════════════════════════════════════════
const int MAXZ = 100 // live zones kept in memory (more makes the script too slow)
const int NT = 5 // zone types: 0 FVG, 1 FVG + OB, 2 inverse FVG, 3 breaker, 4 HTF FVG
atr = ta.atr(14)
atrL = ta.atr(50)
avgVol = ta.sma(nz(volume) > 0 ? volume : 1.0, 50)
relV = (nz(volume) > 0 ? volume : 1.0) / avgVol
// panels and text are drawn as one dark card on any chart theme (default look tuned for the light theme)
color dkBg = #131722
color dkTx = #D1D4DC
color dkMu = #8A93A6
// chart theme: zones are drawn stronger on a dark background and lighter on a light one
bool isDk = color.r(chart.bg_color) + color.g(chart.bg_color) + color.b(chart.bg_color) < 384
int htfS = timeframe.in_seconds(htfTf)
bool htfOn = useHtf and htfS > timeframe.in_seconds()
// reaction window for HTF zones: the same number of HTF candles, counted in chart bars (max 3000)
int rwH = int(math.min(reactW * math.max(1, math.round(htfS / timeframe.in_seconds())), 3000))
string htfL = str.endswith(htfTf, "M") ? htfTf : htfS % 604800 == 0 ? str.tostring(htfS / 604800) + "W" : htfS % 86400 == 0 ? str.tostring(htfS / 86400) + "D" : htfS % 3600 == 0 ? str.tostring(htfS / 3600) + "H" : htfS % 60 == 0 ? str.tostring(htfS / 60) + "m" : str.tostring(htfS) + "s"
px(float p) => str.tostring(p, format.mintick)
f_stars(int n) => n >= 3 ? "⭐⭐⭐" : n == 2 ? "⭐⭐" : "⭐"
f_tyN(int t) => t == 0 ? "FVG" : t == 1 ? "FVG + OB" : t == 2 ? "Inverse FVG" : t == 3 ? "Breaker" : "FVG " + htfL
f_col(int sd, int t) => t == 2 ? invC : t == 3 ? bkrC : t == 4 ? htfC : sd == 1 ? demC : supC
// session bucket of a bar time by UTC hour: 0 Asia, 1 London, 2 New York
f_ses(int t) =>
int h = hour(t, "UTC")
h >= 7 and h < 13 ? 1 : h >= 13 and h < 22 ? 2 : 0
// last opposite-colour candle before the move (offset from the current bar), -1 = none
f_ob(int sd) =>
int ix = -1
for i = 2 to obLook + 1
if sd == 1 ? close[i] < open[i] : close[i] > open[i]
ix := i
break
ix
// higher-timeframe gap of the last CLOSED HTF candle (used with lookahead on + [1] offsets, so it never repaints)
f_htf() =>
float a = ta.atr(14)
float rv = (nz(volume) > 0 ? volume : 1.0) / ta.sma(nz(volume) > 0 ? volume : 1.0, 50)
bool bu = low > high[2] and low - high[2] >= minGap * a and (not needDir or close[1] > open[1])
bool be = high < low[2] and low[2] - high >= minGap * a and (not needDir or close[1] < open[1])
int g = 1 + (math.abs(close[1] - open[1]) >= dispMin * nz(a[1], a) ? 1 : 0) + (nz(rv[1]) >= volMin ? 1 : 0)
[bu[1], be[1], low[1], high[3], high[1], low[3], g[1], a[1]]
[hBu, hBe, hL1, hH3, hH1, hL3, hG, hAtr] = request.security(syminfo.tickerid, htfTf, f_htf(), lookahead = barmerge.lookahead_on)
[pdH, pdL] = request.security(syminfo.tickerid, "D", [high[1], low[1]], lookahead = barmerge.lookahead_on)
[pwH, pwL] = request.security(syminfo.tickerid, "W", [high[1], low[1]], lookahead = barmerge.lookahead_on)
bool htfCh = timeframe.change(htfTf)
var int hb1 = na // first chart bar of the current HTF candle
var int hb2 = na // ... of the previous one
var int hb3 = na // ... of the one before (the middle candle of a just-confirmed HTF gap)
if htfCh
hb3 := hb2
hb2 := hb1
hb1 := bar_index
bool newHtf = htfOn and htfCh
// ═══════════════════════════════════════════════════════════════════════════
// STATE
// ═══════════════════════════════════════════════════════════════════════════
// live zones (side: 1 = demand below price, -1 = supply above)
var array<float> zTop = array.new<float>() // gap top
var array<float> zBot = array.new<float>() // gap bottom
var array<float> zFar = array.new<float>() // break level (far edge incl. the order block)
var array<float> zObT = array.new<float>()
var array<float> zObB = array.new<float>()
var array<int> zObX = array.new<int>() // order block bar
var array<int> zSd = array.new<int>()
var array<int> zTy = array.new<int>()
var array<int> zGr = array.new<int>()
var array<int> zBn = array.new<int>() // bar the zone was confirmed
var array<int> zX1 = array.new<int>() // bar where the zone box starts
var array<int> zSs = array.new<int>() // session bucket (-1 = not scored by session)
var array<int> zSt = array.new<int>() // 0 fresh, 1 touched (waiting), 2 not held, 3 held, 4 held and retested
var array<int> zTb = array.new<int>() // first-touch bar
var array<float> zTa = array.new<float>() // ATR at the touch
var array<float> zMx = array.new<float>() // deepest fill of the gap so far (1.0 = 100 %)
// first-touch scoreboard per type, per grade and per session
var array<int> sN = array.new<int>(NT, 0)
var array<int> sHeld = array.new<int>(NT, 0)
var array<int> sBrk = array.new<int>(NT, 0)
var array<int> gN = array.new<int>(3, 0)
var array<int> gHeld = array.new<int>(3, 0)
var array<int> qN = array.new<int>(3, 0)
var array<int> qHeld = array.new<int>(3, 0)
var array<float> hDep = array.new<float>() // fill % of the gap at the moment a zone held
var int tchN = 0
var int tchSum = 0
var int dropN = 0 // untouched zones dropped by the live-zone cap (never scored)
var array<box> hBx = array.new<box>()
var array<label> hLb = array.new<label>()
f_held(int t) => sN.get(t) >= minSamp ? 100.0 * sHeld.get(t) / sN.get(t) : na
f_gHeld(int g) => gN.get(g) >= minSamp ? 100.0 * gHeld.get(g) / gN.get(g) : na
f_qHeld(int q) => qN.get(q) >= minSamp ? 100.0 * qHeld.get(q) / qN.get(q) : na
f_pct(float v) => na(v) ? "–" : str.tostring(v, "0") + "%"
// add a zone, or merge a chart-timeframe gap into an untouched overlapping zone on the same side formed within the merge window
f_add(int sd, float top, float bot, float far, float obT, float obB, int obX, int ty, int gr, int x1, int ss, int bn, int st0) =>
int k = -1
bool uO = false // a merged zone became FVG + OB
bool u3 = false // a merged zone became ⭐⭐⭐
float tol = 0.25 * nz(atr, 0.0) // stacked gaps from one leg sit next to each other: merge them within a small tolerance
if ty < 2 and mergeW > 0 and zTop.size() > 0
for i = zTop.size() - 1 to 0
if zSd.get(i) == sd and zSt.get(i) == 0 and zTy.get(i) < 2 and bar_index - zBn.get(i) <= mergeW and top >= zBot.get(i) - tol and bot <= zTop.get(i) + tol
k := i
break
if k >= 0
uO := ty == 1 and zTy.get(k) == 0
u3 := gr >= 3 and zGr.get(k) < 3
zTop.set(k, math.max(zTop.get(k), top))
zBot.set(k, math.min(zBot.get(k), bot))
// the order block drawn always matches the break level
if not na(obT) and (na(zObT.get(k)) or (sd == 1 ? far < zFar.get(k) : far > zFar.get(k)))
zObT.set(k, obT)
zObB.set(k, obB)
zObX.set(k, obX)
zFar.set(k, sd == 1 ? math.min(zFar.get(k), far) : math.max(zFar.get(k), far))
zTy.set(k, math.max(zTy.get(k), ty))
zGr.set(k, math.max(zGr.get(k), gr))
else
zTop.push(top)
zBot.push(bot)
zFar.push(far)
zObT.push(obT)
zObB.push(obB)
zObX.push(obX)
zSd.push(sd)
zTy.push(ty)
zGr.push(gr)
zBn.push(bn)
zX1.push(math.max(x1, bar_index - 4900))
zSs.push(ss)
zSt.push(st0)
zTb.push(0)
zTa.push(0.0)
zMx.push(0.0)
[k < 0, uO, u3]
f_del(int i) =>
zTop.remove(i)
zBot.remove(i)
zFar.remove(i)
zObT.remove(i)
zObB.remove(i)
zObX.remove(i)
zSd.remove(i)
zTy.remove(i)
zGr.remove(i)
zBn.remove(i)
zX1.remove(i)
zSs.remove(i)
zSt.remove(i)
zTb.remove(i)
zTa.remove(i)
zMx.remove(i)
// ═══════════════════════════════════════════════════════════════════════════
// 0. HIGHER-TIMEFRAME GAP, confirmed when its HTF candle closed (added before the live loop,
// so the first chart bar of the new HTF candle can already touch it)
// ═══════════════════════════════════════════════════════════════════════════
bool newHz = false
int hwSd = 1
float hwTop = na
float hwBot = na
if barstate.isconfirmed and newHtf and (hBu or hBe) and not na(atr)
int xH = na(hb3) ? bar_index - 1 : hb3
if hBu
[hz1, hz2, hz3] = f_add(1, hL1, hH3, hH3, na, na, 0, 4, hG, xH, -1, bar_index - 1, 0)
newHz := hz1
hwSd := 1
hwTop := hL1
hwBot := hH3
else
[hz1, hz2, hz3] = f_add(-1, hL3, hH1, hL3, na, na, 0, 4, hG, xH, -1, bar_index - 1, 0)
newHz := hz1
hwSd := -1
hwTop := hL3
hwBot := hH1
// ═══════════════════════════════════════════════════════════════════════════
// 1. LIVE ZONES: fill, first touch, HELD / BROKEN, retest, removal (bar close only)
// ═══════════════════════════════════════════════════════════════════════════
bool evTouch = false
bool evHeld = false
bool evBrk = false
bool evFlip = false
bool evRet = false
int aSd = 0
int aTy = 0
int aGr = 0
float aTop = na
float aBot = na
int aN = 0 // first touches on this bar
int rSd = 0 // retest event (kept apart from the first-touch event of the same bar)
int rTy = 0
int rGr = 0
float rTop = na
float rBot = na
// flipped zones created this bar (added after the loop)
array<float> nT = array.new<float>()
array<float> nB = array.new<float>()
array<int> nS = array.new<int>()
array<int> nG = array.new<int>()
array<int> nY = array.new<int>()
if barstate.isconfirmed and zTop.size() > 0
for i = zTop.size() - 1 to 0
int sd = zSd.get(i)
float top = zTop.get(i)
float bot = zBot.get(i)
float far = zFar.get(i)
int bn = zBn.get(i)
if bar_index > bn
float gap = math.max(top - bot, syminfo.mintick)
float fl = sd == 1 ? (top - low) / gap : (high - bot) / gap
if fl > zMx.get(i)
zMx.set(i, fl)
bool brk = sd == 1 ? close < far : close > far // close beyond the break level (gap + order block)
float farF = sd == 1 ? (top - far) / gap : (far - bot) / gap
bool mit = mitMode == "Wick beyond" ? zMx.get(i) > farF : mitMode == "50% reached" ? zMx.get(i) >= 0.5 : brk // latched by the deepest fill
int st = zSt.get(i)
bool inZ = sd == 1 ? low <= top : high >= bot
if st == 3 and inZ
zSt.set(i, 4)
st := 4
evRet := true
rSd := sd
rTy := zTy.get(i)
rGr := zGr.get(i)
rTop := top
rBot := bot
if st == 0 and inZ
st := 1
zSt.set(i, 1)
zTb.set(i, bar_index)
zTa.set(i, zTy.get(i) == 4 ? nz(hAtr, nz(atr, top - bot)) : nz(atr, top - bot)) // HTF zones are scored with the HTF ATR
tchN += 1
tchSum += bar_index - bn
evTouch := true
aN += 1
aSd := sd
aTy := zTy.get(i)
aGr := zGr.get(i)
aTop := top
aBot := bot
if st == 1
float ta0 = zTa.get(i)
// symmetric rule around the near edge: HELD = close reactATR ATR away from it, BROKEN = close the same distance back through it
// (a close beyond the break level is always BROKEN, so the zone is removed and flips on that bar)
bool brkS = brk or (sd == 1 ? close <= top - reactATR * ta0 : close >= bot + reactATR * ta0)
bool held = sd == 1 ? close >= top + reactATR * ta0 : close <= bot - reactATR * ta0
int rw = zTy.get(i) == 4 ? rwH : reactW // HTF zones get the same number of HTF candles
if brkS or held or bar_index - zTb.get(i) >= rw - 1
int ty = zTy.get(i)
int gr = zGr.get(i)
int ss = zSs.get(i)
sN.set(ty, sN.get(ty) + 1)
if ty < 2
gN.set(gr - 1, gN.get(gr - 1) + 1)
if ss >= 0
qN.set(ss, qN.get(ss) + 1)
if held
sHeld.set(ty, sHeld.get(ty) + 1)
if ty < 2
gHeld.set(gr - 1, gHeld.get(gr - 1) + 1)
if ss >= 0
qHeld.set(ss, qHeld.get(ss) + 1)
hDep.push(math.min(zMx.get(i), 1.0) * 100.0)
if hDep.size() > 400
hDep.shift()
else if brkS
sBrk.set(ty, sBrk.get(ty) + 1)
if held
evHeld := true
zSt.set(i, held ? 3 : 2)
if showHist and (held or brkS)
hLb.push(label.new(zTb.get(i), sd == 1 ? top : bot, held ? "✓" : "✗", style = sd == 1 ? label.style_label_up : label.style_label_down,
color = color(na), textcolor = held ? (isDk ? #3DDC97 : #0B8F5A) : (isDk ? #FF6B6B : #D32F2F), size = size.small,
tooltip = f_tyN(ty) + " " + f_stars(gr) + " " + px(bot) + " – " + px(top) + (held ? ": HELD on the first touch (closed " : ": BROKEN on the first touch (closed ") +
str.tostring(reactATR, "0.0") + " ATR " + (held ? "away from the zone" : "back through its near edge, or beyond the break level") + " within " + str.tostring(rw) + " bars). Mark placed on the touch bar once the result was known."))
while hLb.size() > (fullHist ? 300 : math.min(keepHist, 15))
hLb.shift().delete()
// removal: a zone waiting for its first-touch result is kept until the result is known;
int stE = zSt.get(i)
bool old = bar_index - bn >= (zTy.get(i) == 4 ? maxAge * math.max(1, htfS / timeframe.in_seconds()) : maxAge)
if stE != 1 and (brk or mit or old)
int ty2 = zTy.get(i)
if brk
evBrk := true
if showHist and ty2 != 4 and (brk or mit) and math.max(math.abs(top - close), math.abs(bot - close)) <= maxDist * nz(atrL, atr)
color hc = f_col(sd, ty2)
hBx.push(box.new(math.max(zX1.get(i), bar_index - 4900), top, bar_index, bot, border_color = color.new(hc, isDk ? 55 : 45), bgcolor = color.new(hc, isDk ? 90 : 86), border_style = line.style_dotted))
while hBx.size() > keepHist
hBx.shift().delete()
if brk and showInv and ty2 < 2
nT.push(top)
nB.push(bot)
nS.push(-sd)
nG.push(zGr.get(i))
nY.push(2)
evFlip := true
if brk and showBrk and ty2 == 1 and not na(zObT.get(i))
nT.push(zObT.get(i))
nB.push(zObB.get(i))
nS.push(-sd)
nG.push(zGr.get(i))
nY.push(3)
evFlip := true
f_del(i)
// ═══════════════════════════════════════════════════════════════════════════
// 2. NEW ZONES (gap confirmed on bar close)
// ═══════════════════════════════════════════════════════════════════════════
int obUp = f_ob(1)
int obDn = f_ob(-1)
bool bullGap = low > high[2] and low - high[2] >= minGap * atr and (not needDir or close[1] > open[1])
bool bearGap = high < low[2] and low[2] - high >= minGap * atr and (not needDir or close[1] < open[1])
int grNew = 1 + (math.abs(close[1] - open[1]) >= dispMin * nz(atr[1], atr) ? 1 : 0) + (nz(relV[1]) >= volMin ? 1 : 0)
int sesNow = timeframe.isintraday ? f_ses(time[1]) : -1
bool sesOk = sesF == "All" or not timeframe.isintraday or (sesF == "Asia" ? sesNow == 0 : sesF == "London" ? sesNow == 1 : sesF == "New York" ? sesNow == 2 : sesNow >= 1)
bool newBull = false
bool newBear = false
int nwTy = 0
int nwGr = 1
int nwSd = 1
float nwTop = na
float nwBot = na
bool mgOB = false // a merge turned a zone into FVG + OB
bool mg3 = false // a merge turned a zone into ⭐⭐⭐
if barstate.isconfirmed and not na(atr)
if nT.size() > 0
for j = 0 to nT.size() - 1
[fq1, fq2, fq3] = f_add(nS.get(j), nT.get(j), nB.get(j), nS.get(j) == 1 ? nB.get(j) : nT.get(j), na, na, 0, nY.get(j), nG.get(j), bar_index, -1, bar_index, 0)
if bullGap and sesOk
float top = low
float bot = high[2]
float oT = na
float oB = na
int oX = 0
if obUp >= 2
oT := obBody ? math.max(open[obUp], close[obUp]) : high[obUp]
oB := obBody ? math.min(open[obUp], close[obUp]) : low[obUp]
oX := bar_index - obUp
if oB >= top
oT := na
oB := na
else
oT := math.min(oT, top)
int ty = na(oB) ? 0 : 1
[nb1, nb2, nb3] = f_add(1, top, bot, na(oB) ? bot : math.min(bot, oB), oT, oB, oX, ty, grNew, bar_index - 1, sesNow, bar_index, 0)
newBull := nb1
mgOB := mgOB or nb2
mg3 := mg3 or nb3
nwSd := 1
nwTy := ty
nwGr := grNew
nwTop := top
nwBot := bot
if bearGap and sesOk
float top = low[2]
float bot = high
float oT = na
float oB = na
int oX = 0
if obDn >= 2
oT := obBody ? math.max(open[obDn], close[obDn]) : high[obDn]
oB := obBody ? math.min(open[obDn], close[obDn]) : low[obDn]
oX := bar_index - obDn
if oT <= bot
oT := na
oB := na
else
oB := math.max(oB, bot)
int ty = na(oT) ? 0 : 1
[ne1, ne2, ne3] = f_add(-1, top, bot, na(oT) ? top : math.max(top, oT), oT, oB, oX, ty, grNew, bar_index - 1, sesNow, bar_index, 0)
newBear := ne1
mgOB := mgOB or ne2
mg3 := mg3 or ne3
nwSd := -1
nwTy := ty
nwGr := grNew
nwTop := top
nwBot := bot
// the oldest zones make room: zones already scored go first, then the oldest untouched zone (any type);
// a zone waiting for its first-touch result is never removed. Untouched zones dropped this way are counted.
while zTop.size() > MAXZ
int r = -1
for j = 0 to zTop.size() - 1
if zSt.get(j) >= 2
r := j
break
if r < 0
for j = 0 to zTop.size() - 1
if zSt.get(j) != 1
r := j
break
if r < 0
break
if zSt.get(r) == 0
dropN += 1
f_del(r)
// ═══════════════════════════════════════════════════════════════════════════
// 2b. FULL-CHART HISTORY: the nearest live demand / supply zone on every bar, drawn with plots + fill
// (plots have no drawing limit, so this covers the whole loaded history)
// ═══════════════════════════════════════════════════════════════════════════
float rDT = na
float rDB = na
float rST = na
float rSB = na
color rDC = na
color rSC = na
int rDI = -1
int rSI = -1
if fullHist and zTop.size() > 0
for i = 0 to zTop.size() - 1
float tq = zTop.get(i)
float bq = zBot.get(i)
if zSd.get(i) == 1 and bq <= close and (na(rDT) or tq > rDT)
rDT := tq
rDB := bq
rDC := f_col(1, zTy.get(i))
rDI := zBn.get(i) * 10 + zTy.get(i)
if zSd.get(i) == -1 and tq >= close and (na(rSB) or bq < rSB)
rST := tq
rSB := bq
rSC := f_col(-1, zTy.get(i))
rSI := zBn.get(i) * 10 + zTy.get(i)
// a one-bar gap where the zone changes, so two zones are never joined by a line
bool dNew = rDI != nz(rDI[1], -2)
bool sNew = rSI != nz(rSI[1], -2)
pDT = plot(fullHist and not dNew ? rDT : na, "Past demand top", color = color.new(nz(rDC, demC), 45), style = plot.style_linebr, display = display.pane, editable = false)
pDB = plot(fullHist and not dNew ? rDB : na, "Past demand bottom", color = color.new(nz(rDC, demC), 75), style = plot.style_linebr, display = display.pane, editable = false)
pST = plot(fullHist and not sNew ? rST : na, "Past supply top", color = color.new(nz(rSC, supC), 75), style = plot.style_linebr, display = display.pane, editable = false)
pSB = plot(fullHist and not sNew ? rSB : na, "Past supply bottom", color = color.new(nz(rSC, supC), 45), style = plot.style_linebr, display = display.pane, editable = false)
fill(pDT, pDB, color.new(nz(rDC, demC), isDk ? 76 : 86))
fill(pST, pSB, color.new(nz(rSC, supC), isDk ? 76 : 86))
// ═══════════════════════════════════════════════════════════════════════════
// 3. LAST-BAR DRAWING: nearest zones, fill meter, levels, table, status banner
// ═══════════════════════════════════════════════════════════════════════════
var array<box> dBx = array.new<box>()
var array<line> dLn = array.new<line>()
var array<label> dLb = array.new<label>()
var table bnr = table.new(position.bottom_center, 1, 1, frame_color = color(na), frame_width = 0)
tpos = tbPos == "Top left" ? position.top_left : tbPos == "Bottom right" ? position.bottom_right : tbPos == "Bottom left" ? position.bottom_left : position.top_right
int lgR = showFull ? 11 : 7
var table lg = table.new(tbPos == "Bottom right" ? position.bottom_left : position.bottom_right, 5, 1, bgcolor = color.new(dkBg, 4), frame_color = color.new(dkTx, 75), frame_width = 1, border_color = color.new(dkBg, 4), border_width = 2)
if barstate.isfirst and showLg
array<string> lgN = array.from("Demand", "Supply", "Inverse", "Breaker")
array<color> lgC = array.from(demC, supC, invC, bkrC)
if htfOn
lgN.insert(2, "FVG " + htfL)
lgC.insert(2, htfC)
for c = 0 to lgN.size() - 1
table.cell(lg, c, 0, "■ " + lgN.get(c), text_color = lgC.get(c), text_size = size.small)
var table tb = table.new(tpos, 2, lgR + 1, bgcolor = color.new(dkBg, 4), border_color = color.new(dkTx, 88), border_width = 1, frame_color = color.new(dkTx, 75), frame_width = 1)
f_cell(int r, string k, string v, color vc) =>
table.cell(tb, 0, r, k, text_color = dkMu, text_size = r >= 7 ? size.small : size.normal, text_halign = text.align_left)
table.cell(tb, 1, r, v, text_color = vc, text_size = r >= 7 ? size.small : size.normal, text_halign = text.align_right)
// sample count with held % / broken % of one zone type
f_hb(int t) => str.tostring(sN.get(t)) + (sN.get(t) >= minSamp ? " (" + str.tostring(100.0 * sHeld.get(t) / sN.get(t), "0") + "/" + str.tostring(100.0 * sBrk.get(t) / sN.get(t), "0") + ")" : "")
if barstate.isfirst and showTb
table.cell(tb, 0, 0, "EYE IMBALANCE ZONES" + (sesF != "All" and timeframe.isintraday ? " · " + sesF + " chart-TF zones only" : ""), text_color = demC, bgcolor = hdrC, text_size = size.normal, text_halign = text.align_center)
table.merge_cells(tb, 0, 0, 1, 0)
table.cell(tb, 0, lgR, "▲ demand · ▼ supply · ✓ held · ✗ broken on first touch\n% = held / all first touches (no decision counts as not held)\ngrade & session rows: FVG and FVG + OB only\nin-sample on this chart, not a forecast", text_color = dkMu, text_size = size.small, text_halign = text.align_left)
table.merge_cells(tb, 0, lgR, 1, lgR)
f_zoneTxt(int i) =>
int ty = zTy.get(i)
int st = zSt.get(i)
float mx = zMx.get(i)
string fs = st == 0 ? "fresh" : str.tostring(math.min(mx, 1.0) * 100.0, "0") + "% filled" + (st == 1 ? " · result pending" : st == 2 ? " · 1st touch done" : " ✓")
(zSd.get(i) == 1 ? "▲ " : "▼ ") + f_tyN(ty) + " " + f_stars(zGr.get(i)) + " · " + fs
if barstate.islast
for b in dBx
b.delete()
for l in dLn
l.delete()
for x in dLb
x.delete()
dBx.clear()
dLn.clear()
dLb.clear()
int x0 = bar_index + ext
int inIx = -1 // zone price is inside (highest grade)
int nxIx = -1 // nearest zone price is outside of
float nxD = 1e100
int nDem = -1
int nSup = -1
if zTop.size() > 0 and not na(atrL) and atrL > 0
array<float> dd = array.new<float>()
for i = 0 to zTop.size() - 1
float t0 = zTop.get(i)
float b0 = zBot.get(i)
// distance to the full zone (gap + order block part up to the break level)
float hi = zSd.get(i) == 1 ? t0 : math.max(t0, zFar.get(i))
float lo = zSd.get(i) == 1 ? math.min(b0, zFar.get(i)) : b0
float d = close > hi ? close - hi : close < lo ? lo - close : 0.0
dd.push(d <= maxDist * atrL ? d : 1e100)
if d == 0.0 and (inIx < 0 or zGr.get(i) > zGr.get(inIx))
inIx := i
if d > 0.0 and d <= maxDist * atrL and d < nxD
nxD := d
nxIx := i
int cD = 0
int cS = 0
array<float> shT = array.new<float>()
array<float> shB = array.new<float>()
array<int> shS = array.new<int>()
array<int> shG = array.new<int>()
array<float> lbY = array.new<float>() // label heights already used (labels too close are moved right)
while dd.min() < 1e99
int ix = dd.indexof(dd.min())
dd.set(ix, 1e100)
int sd = zSd.get(ix)
if (sd == 1 ? cD : cS) >= maxShow
continue
// a zone overlapping a nearer zone on the same side is not drawn again (keeps labels readable),
// unless it is an HTF zone or has a higher grade than the zone it overlaps
bool ovl = false
if shT.size() > 0
for q = 0 to shT.size() - 1
if shS.get(q) == sd and zTop.get(ix) >= shB.get(q) and zBot.get(ix) <= shT.get(q) and zTy.get(ix) != 4 and zGr.get(ix) <= shG.get(q)
ovl := true
break
if ovl
continue
shT.push(zTop.get(ix))
shB.push(zBot.get(ix))
shS.push(sd)
shG.push(zGr.get(ix))
if sd == 1
cD += 1
if nDem < 0
nDem := ix
else
cS += 1
if nSup < 0
nSup := ix
float t = zTop.get(ix)
float bt = zBot.get(ix)
int ty = zTy.get(ix)
int gr = zGr.get(ix)
float mx = zMx.get(ix)
color zc = f_col(sd, ty)
int x1 = math.max(zX1.get(ix), bar_index - 4900)
int tr = isDk ? (gr >= 3 ? 52 : gr == 2 ? 62 : 72) : (gr >= 3 ? 56 : gr == 2 ? 66 : 74)
// only the part within the hide distance is drawn, so tall zones never squeeze the price scale
float lim = maxDist * atrL
float tD = math.min(t, close + lim)
float bD = math.max(bt, close - lim)
dBx.push(box.new(x1, tD, x0, bD, border_color = color.new(zc, isDk ? 15 : ty == 4 ? 0 : 30), border_width = ty == 4 ? 2 : 1, bgcolor = color.new(zc, tr)))
if showFill and mx > 0
float fT = sd == 1 ? t : bt + math.min(mx, 1.0) * (t - bt)
float fB = sd == 1 ? t - math.min(mx, 1.0) * (t - bt) : bt
fT := math.min(fT, tD)
fB := math.max(fB, bD)
if fT > fB
dBx.push(box.new(x1, fT, x0, fB, border_color = color(na), bgcolor = color.new(chart.bg_color, isDk ? 62 : 68))) // used part of the gap fades toward the background
float fLv = sd == 1 ? fB : fT // fill level line, so the meter stays readable on a light chart
dLn.push(line.new(x1, fLv, x0, fLv, color = color.new(zc, isDk ? 20 : 10), width = 2))
if showOB and ty == 1 and not na(zObT.get(ix))
float oTd = math.min(zObT.get(ix), close + lim)
float oBd = math.max(zObB.get(ix), close - lim)
if oTd > oBd
dBx.push(box.new(math.max(zObX.get(ix), bar_index - 4900), oTd, x0, oBd, border_color = color.new(zc, isDk ? 30 : 40), border_width = 1, border_style = line.style_dashed, bgcolor = color(na)))
if showCE and (t + bt) / 2 <= tD and (t + bt) / 2 >= bD
dLn.push(line.new(x1, (t + bt) / 2, x0, (t + bt) / 2, color = isDk ? color.new(zc, 30) : color.new(#455A64, 25), style = line.style_dotted, width = 1))
float hr = f_held(ty)
float gh = f_gHeld(gr - 1)
float ly = (tD + bD) / 2
int lx = x0
if lbY.size() > 0
for q = 0 to lbY.size() - 1
if math.abs(lbY.get(q) - ly) < 0.45 * atrL
lx += 28
lbY.push(ly)
dLb.push(label.new(lx, ly, f_zoneTxt(ix) + (na(hr) ? "" : " · this type held " + str.tostring(hr, "0") + "% of past 1st touches"), style = label.style_label_left,
color = color.new(dkBg, 10), textcolor = zc, size = gr >= 3 ? size.normal : size.small,
tooltip = (sd == 1 ? "Demand zone: " : "Supply zone: ") + f_tyN(ty) + " " + f_stars(gr) + (ty == 3 ? "\nZone " : "\nGap ") + px(bt) + " – " + px(t) +
(ty == 1 and not na(zObT.get(ix)) ? "\nOrder block " + px(zObB.get(ix)) + " – " + px(zObT.get(ix)) : "") +
"\nBreak level (close beyond): " + px(zFar.get(ix)) + (mitMode != "Close beyond" ? " · removed earlier: " + mitMode : "") + "\nFilled so far: " + str.tostring(math.min(mx, 1.0) * 100.0, "0") + "%" +
"\nThis type held on the first touch before: " + (na(hr) ? "not enough data yet" : str.tostring(hr, "0") + "% (" + str.tostring(sN.get(ty)) + " touches)") +
(ty >= 2 ? "" : "\nThis grade (FVG and FVG + OB pooled) held on the first touch before: " + (na(gh) ? "not enough data yet" : str.tostring(gh, "0") + "% (" + str.tostring(gN.get(gr - 1)) + " touches)")) +
"\nNo decision counts as not held. Past behaviour on this chart only, not a forecast."))
// previous day / week levels (intraday charts)
if timeframe.isintraday and not na(atrL)
array<float> lvP = array.from(pdH, pdL, pwH, pwL)
array<string> lvN = array.from("PDH", "PDL", "PWH", "PWL")
for k = 0 to 3
float lv = lvP.get(k)
if (k < 2 ? showPD : showPW) and not na(lv) and math.abs(lv - close) <= maxDist * atrL
dLn.push(line.new(bar_index - 40, lv, x0, lv, color = color.new(lvlC, 15), style = line.style_dashed, width = 2))
dLb.push(label.new(bar_index - 40, lv, lvN.get(k) + " " + px(lv), style = k == 0 or k == 2 ? label.style_label_down : label.style_label_up, color = color.new(dkBg, 5), textcolor = lvlC, size = size.small,
tooltip = (k == 0 ? "Previous day high" : k == 1 ? "Previous day low" : k == 2 ? "Previous week high" : "Previous week low") + " " + px(lv)))
if showTb
f_cell(1, "Nearest demand ▲", nDem < 0 ? "none in range" : px(zBot.get(nDem)) + " – " + px(zTop.get(nDem)) + " · " + f_tyN(zTy.get(nDem)) + " " + f_stars(zGr.get(nDem)), demC)
f_cell(2, "Nearest supply ▼", nSup < 0 ? "none in range" : px(zBot.get(nSup)) + " – " + px(zTop.get(nSup)) + " · " + f_tyN(zTy.get(nSup)) + " " + f_stars(zGr.get(nSup)), supC)
f_cell(3, "Held on 1st touch", "FVG " + f_pct(f_held(0)) + " · FVG+OB " + f_pct(f_held(1)) + (htfOn ? " · " + htfL + " " + f_pct(f_held(4)) : ""), dkTx)
f_cell(4, "Flipped zones held", "Inverse " + f_pct(f_held(2)) + " · Breaker " + f_pct(f_held(3)), dkTx)
f_cell(5, "Held by grade (FVG, FVG+OB)", "⭐ " + f_pct(f_gHeld(0)) + " · ⭐⭐ " + f_pct(f_gHeld(1)) + " · ⭐⭐⭐ " + f_pct(f_gHeld(2)), dkTx)
f_cell(6, timeframe.isintraday ? "Held by session formed (FVG, FVG+OB)" : "Held zones were filled (median)", timeframe.isintraday ? "Asia " + f_pct(f_qHeld(0)) + " · London " + f_pct(f_qHeld(1)) + " · NY " + f_pct(f_qHeld(2)) :
(hDep.size() >= minSamp ? str.tostring(hDep.percentile_nearest_rank(50), "0") + "% of the gap" : "collecting…"), dkTx)
if showFull
f_cell(7, timeframe.isintraday ? "Held zones were filled (median)" : "Avg bars to 1st touch", timeframe.isintraday ? (hDep.size() >= minSamp ? str.tostring(hDep.percentile_nearest_rank(50), "0") + "% of the gap" : "collecting…") : (tchN > 0 ? str.tostring(tchSum / tchN, "0") : "–"), dkTx)
f_cell(8, "1st touches (held / broken %) · FVG · FVG+OB · Inv · Brk · HTF", f_hb(0) + " · " + f_hb(1) + " · " + f_hb(2) + " · " + f_hb(3) + " · " + f_hb(4) +
" · all: held / broken / no decision " + str.tostring(sHeld.sum()) + " / " + str.tostring(sBrk.sum()) + " / " + str.tostring(sN.sum() - sHeld.sum() - sBrk.sum()), dkTx)
f_cell(9, "1st touches · ⭐ · ⭐⭐ · ⭐⭐⭐", str.tostring(gN.get(0)) + " · " + str.tostring(gN.get(1)) + " · " + str.tostring(gN.get(2)), dkTx)
f_cell(10, timeframe.isintraday ? "Live zones · avg bars to 1st touch" : "Live zones", str.tostring(zTop.size()) + (timeframe.isintraday ? " · " + (tchN > 0 ? str.tostring(tchSum / tchN, "0") : "–") : "") + " · dropped untouched " + str.tostring(dropN), dkTx)
// status banner: what is happening now, in one line
string stt = "NO ACTIVE ZONE NEARBY"
color sc = #455A64
if inIx >= 0
float hr2 = f_held(zTy.get(inIx))
int stI = zSt.get(inIx)
bool inG = close <= zTop.get(inIx) and close >= zBot.get(inIx)
string ph = stI == 0 ? (inG ? "first touch now" : "first touch now · in the order block") : str.tostring(math.min(zMx.get(inIx), 1.0) * 100.0, "0") + "% filled"
stt := "PRICE INSIDE " + (zSd.get(inIx) == 1 ? "▲ DEMAND " : "▼ SUPPLY ") + f_tyN(zTy.get(inIx)) + " " + f_stars(zGr.get(inIx)) + " · " + ph +
(na(hr2) ? "" : " · this type held " + str.tostring(hr2, "0") + "% of 1st touches before (this chart, no decision = not held)")
sc := f_col(zSd.get(inIx), zTy.get(inIx))
else if nxIx >= 0
stt := "NEXT ZONE " + (zSd.get(nxIx) == 1 ? "▲ DEMAND " : "▼ SUPPLY ") + px(zBot.get(nxIx)) + " – " + px(zTop.get(nxIx)) + " · " + px(nxD) + " away · " + f_tyN(zTy.get(nxIx)) + " " + f_stars(zGr.get(nxIx))
sc := f_col(zSd.get(nxIx), zTy.get(nxIx))
if showBn
table.cell(bnr, 0, 0, stt, text_color = 0.299 * color.r(sc) + 0.587 * color.g(sc) + 0.114 * color.b(sc) > 140 ? #000000 : #FFFFFF, bgcolor = color.new(sc, 12), text_size = size.normal)
// ═══════════════════════════════════════════════════════════════════════════
// ALERTS
// ═══════════════════════════════════════════════════════════════════════════
alertcondition(barstate.isconfirmed and newBull, "New demand zone ▲", "{{ticker}} new bullish imbalance (demand) zone")
alertcondition(barstate.isconfirmed and newBear, "New supply zone ▼", "{{ticker}} new bearish imbalance (supply) zone")
alertcondition(barstate.isconfirmed and (((newBull or newBear) and nwTy == 1) or mgOB), "New FVG + OB zone", "{{ticker}} new imbalance zone stacked with its order block (or a merged zone gained one)")
alertcondition(barstate.isconfirmed and (((newBull or newBear) and grNew >= 3) or mg3), "New ⭐⭐⭐ zone", "{{ticker}} new 3-star imbalance zone (strong displacement + high volume), or a merged zone became 3-star")
alertcondition(barstate.isconfirmed and newHz, "New HTF zone", "{{ticker}} new higher-timeframe imbalance zone")
alertcondition(barstate.isconfirmed and evTouch, "Zone first touch", "{{ticker}} price touched an imbalance zone for the first time")
alertcondition(barstate.isconfirmed and evHeld, "Zone HELD", "{{ticker}} an imbalance zone held on its first touch")
alertcondition(barstate.isconfirmed and evRet, "Zone retest (after HELD)", "{{ticker}} price came back to a zone that held on its first touch")
alertcondition(barstate.isconfirmed and evBrk, "Zone closed through (removed)", "{{ticker}} a close went beyond a zone's break level; the zone was removed")
alertcondition(barstate.isconfirmed and evFlip, "Flipped to inverse zone / breaker", "{{ticker}} a broken zone flipped into an inverse zone or breaker")
if detailAlerts and barstate.isconfirmed
if newBull or newBear
alert(syminfo.ticker + " — Eye Imbalance Zones: new " + (nwSd == 1 ? "DEMAND ▲ " : "SUPPLY ▼ ") + f_tyN(nwTy) + " " + f_stars(nwGr) + " zone " + px(nwBot) + " – " + px(nwTop), alert.freq_once_per_bar_close)
if newHz
alert(syminfo.ticker + " — Eye Imbalance Zones: new " + (hwSd == 1 ? "DEMAND ▲ " : "SUPPLY ▼ ") + f_tyN(4) + " " + f_stars(hG) + " zone " + px(hwBot) + " – " + px(hwTop), alert.freq_once_per_bar_close)
if (mgOB or mg3) and not (newBull or newBear)
alert(syminfo.ticker + " — Eye Imbalance Zones: a merged zone became " + (mgOB ? "FVG + OB " : "") + (mg3 ? "⭐⭐⭐" : ""), alert.freq_once_per_bar_close)
if evTouch
alert(syminfo.ticker + " — Eye Imbalance Zones: first touch of " + (aSd == 1 ? "DEMAND ▲ " : "SUPPLY ▼ ") + f_tyN(aTy) + " " + f_stars(aGr) + " zone " + px(aBot) + " – " + px(aTop) + (aN > 1 ? " (+" + str.tostring(aN - 1) + " more)" : "") +
(na(f_held(aTy)) ? "" : " (this type held " + str.tostring(f_held(aTy), "0") + "% of first touches before, no decision = not held, in-sample)"), alert.freq_once_per_bar_close)
if evRet
alert(syminfo.ticker + " — Eye Imbalance Zones: retest of HELD " + (rSd == 1 ? "DEMAND ▲ " : "SUPPLY ▼ ") + f_tyN(rTy) + " " + f_stars(rGr) + " zone " + px(rBot) + " – " + px(rTop), alert.freq_once_per_bar_close)
if evHeld
alert(syminfo.ticker + " — Eye Imbalance Zones: a zone HELD on its first touch", alert.freq_once_per_bar_close)
if evBrk
alert(syminfo.ticker + " — Eye Imbalance Zones: a close went beyond a zone's break level, zone removed" + (evFlip ? " → inverse zone / breaker created" : ""), alert.freq_once_per_bar_close)