本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © EyeAlgo
// Eye Volume Balloons — by Eye Algo (original code)
// 1. Balloon size = this bar's volume vs the NORMAL volume for the same time of day (not a flat average),
// ranked by percentile, so session opens don't fill the chart with fake balloons.
// 2. Each balloon floats at the bar's VOLUME CENTRE (intrabar volume-weighted price), not at the close.
// 3. Buy/sell split from lower-timeframe bars (estimated from candle shape when intrabar data is missing).
// 4. Balloon types: Push ▲ / Push ▼ (big volume + big move), Absorb (big volume, small move), Normal.
// 5. Big balloons leave a level with a life cycle: Fresh → Held ×n → Flipped → removed when broken twice.
// 6. Every balloon is tracked: follow-through rate, return-to-balloon rate, bars to return, trap rate.
//@version=6
indicator("Eye Volume Balloons [EyeAlgo]", "Eye Volume Balloons", overlay=true, max_boxes_count=500, max_lines_count=500, max_labels_count=500, max_bars_back=5000)
// ───────────────────────── Inputs ─────────────────────────
grpD = "📊 Dashboard"
dashStyle = input.string("Card", "Dashboard style", options=["Card", "HUD", "Table", "Off"], group=grpD, tooltip="Card = balloon card fixed in a corner. HUD = balloons drawn on the chart right of the last candle. Table = classic grid. Off = hidden.")
grpB = "🎈 Balloons"
useTod = input.bool(true, "Compare with same time-of-day volume (intraday)", group=grpB, tooltip="On intraday charts each bar is compared with the usual volume of that same clock time over recent days. Off = flat 50-bar average.")
todLen = input.int(20, "Time-of-day memory (days)", minval=5, maxval=100, group=grpB)
pctLen = input.int(500, "Percentile window (bars)", minval=100, maxval=4000, group=grpB)
pct1 = input.float(85, "Small balloon from percentile", minval=50, maxval=99, group=grpB)
pct2 = input.float(95, "Medium balloon from percentile", minval=60, maxval=99.5, group=grpB)
pct3 = input.float(99, "Big balloon from percentile", minval=70, maxval=99.9, step=0.1, group=grpB)
minRatio = input.float(1.5, "Minimum volume ratio (x normal)", minval=1.0, step=0.1, group=grpB)
keepBal = input.int(100, "Balloons kept on chart", minval=20, maxval=120, group=grpB)
showSmall = input.bool(true, "Show small balloons", group=grpB)
showTxt = input.bool(true, "Ratio text inside medium + big balloons (e.g. 3.4×)", group=grpB)
balScale = input.string("Normal", "Balloon size", options=["Small", "Normal", "Large"], group=grpB)
grpV = "🎨 Balloon Colours (by volume)"
volT2 = input.float(2000, "Level 2 from volume", minval=0, group=grpV)
volT3 = input.float(3000, "Level 3 from volume", minval=0, group=grpV)
gC1 = input.color(#4FC3F7, "Green candle: below L2", group=grpV, inline="g")
gC2 = input.color(#00C853, "L2", group=grpV, inline="g")
gC3 = input.color(#FFC400, "L3", group=grpV, inline="g")
rC1 = input.color(#EF7A7A, "Red candle: below L2", group=grpV, inline="r")
rC2 = input.color(#C62828, "L2", group=grpV, inline="r")
rC3 = input.color(#6D0F1A, "L3", group=grpV, inline="r")
strCol = input.color(color.gray, "Balloon string", group=grpB)
popTrap = input.bool(true, "Pop the balloon when it turns into a trap", group=grpB)
grpT = "🧭 Balloon Types"
absMax = input.float(0.8, "Absorb: bar range at most (x ATR)", minval=0.2, maxval=1.5, step=0.05, group=grpT)
pushMin = input.float(1.2, "Push: bar range at least (x ATR)", minval=0.8, maxval=3.0, step=0.05, group=grpT)
useLtf = input.bool(true, "Buy/sell split from lower timeframe", group=grpT, tooltip="Uses intrabar bars (auto timeframe). Where intrabar history is not available the split is estimated from candle shape and the dashboard shows how many bars were exact.")
grpL = "📏 Balloon Levels"
showLv = input.bool(true, "Show balloon levels", group=grpL)
lvTier = input.string("Medium + Big", "Levels from", options=["Big only", "Medium + Big"], group=grpL)
keepLv = input.int(20, "Levels kept on chart", minval=2, maxval=60, group=grpL)
lvAge = input.int(400, "Remove level after (bars)", minval=50, maxval=4000, group=grpL)
farLim = input.float(6.0, "Hide levels farther than (x ATR)", minval=1, step=0.5, group=grpL)
grpS = "📊 Tracking"
ftAtr = input.float(1.0, "Follow-through target (x ATR)", minval=0.3, maxval=5, step=0.1, group=grpS)
ftBars = input.int(20, "Follow-through window (bars)", minval=3, maxval=200, group=grpS)
retBars = input.int(50, "Return-to-balloon window (bars)", minval=5, maxval=300, group=grpS)
trapBars = input.int(3, "Trap check (bars)", minval=1, maxval=10, group=grpS, tooltip="A balloon is a trap when price closes beyond the opposite end of the balloon bar within this many bars.")
pressLen = input.int(100, "Pressure gauge window (bars)", minval=10, maxval=500, group=grpS)
grpC = "🎨 Colours & Dashboard"
bullCol = input.color(#0FA67A, "Buyers", group=grpC)
bearCol = input.color(#E5484D, "Sellers", group=grpC)
absCol = input.color(#8E5CF7, "Absorb", group=grpC)
hudGap = input.int(30, "HUD distance from last candle (bars)", minval=4, maxval=80, group=grpD)
colorCandles = input.bool(true, "Colour candles by volume level", group=grpC)
bool showDash = dashStyle == "Table"
bool showHud = dashStyle == "HUD"
bool showCard = dashStyle == "Card"
dashPos = input.string("Top Right", "Scorecard position", options=["Top Right", "Top Left", "Bottom Right", "Bottom Left"], group=grpD)
dashSize = input.string("Small", "Scorecard text", options=["Tiny", "Small", "Normal"], group=grpD)
// ───────────────────────── Core series ─────────────────────────
float atrv = ta.atr(14)
float vol = nz(volume)
// time-of-day normal volume (EMA per clock minute), updated only on closed bars
var map<int, float> todE = map.new<int, float>()
var map<int, int> todN = map.new<int, int>()
int tKey = hour(time) * 60 + minute(time)
float prevE = todE.contains(tKey) ? todE.get(tKey) : na
int prevN = todN.contains(tKey) ? todN.get(tKey) : 0
float sma50 = ta.sma(vol, 50)[1]
bool todOk = useTod and timeframe.isintraday and prevN >= 5 and not na(prevE)
float base = todOk ? prevE : sma50
if barstate.isconfirmed
float aE = 2.0 / (todLen + 1)
todE.put(tKey, na(prevE) ? vol : prevE + aE * (vol - prevE))
todN.put(tKey, prevN + 1)
float ratio = not na(base) and base > 0 ? vol / base : na
float pr = ta.percentrank(ratio, pctLen)
int tier = na(pr) or na(ratio) or ratio < minRatio ? 0 : pr >= pct3 ? 3 : pr >= pct2 ? 2 : pr >= pct1 ? 1 : 0
// intrabar split + volume centre
ltfAuto() =>
int s = timeframe.in_seconds()
s <= 900 ? "1" : s <= 3600 ? "5" : s <= 14400 ? "15" : s <= 86400 ? "60" : "240"
[iH, iL, iC, iO, iV] = request.security_lower_tf(syminfo.tickerid, ltfAuto(), [high, low, close, open, volume])
float sv = 0.0
float sp = 0.0
float bv = 0.0
if useLtf
int n = iV.size()
if n > 0
for i = 0 to n - 1
float v = nz(iV.get(i))
float c = iC.get(i)
float o = iO.get(i)
sp += (iH.get(i) + iL.get(i) + c) / 3.0 * v
sv += v
bv += c > o ? v : c == o ? v * 0.5 : 0.0
bool exact = sv > 0
float rng = high - low
float vcp = exact ? sp / sv : (high + low + 2 * close) / 4.0
float buyShare = exact ? bv / sv : (rng > 0 ? (close - low) / rng : 0.5)
float clv = rng > 0 ? (close - low) / rng : 0.5
float rangeR = not na(atrv) and atrv > 0 ? rng / atrv : na
// type: 0 Push up, 1 Push down, 2 Absorb, 3 Normal
int typ = na(rangeR) ? 3 : rangeR <= absMax ? 2 : rangeR >= pushMin and clv >= 0.65 and buyShare >= 0.5 ? 0 : rangeR >= pushMin and clv <= 0.35 and buyShare <= 0.5 ? 1 : 3
int dir = typ == 0 ? 1 : typ == 1 ? -1 : typ == 2 ? (close < close[5] ? 1 : -1) : (buyShare >= 0.5 ? 1 : -1)
bool isBal = barstate.isconfirmed and tier > 0 and vol > 0 and not na(atrv) and (showSmall or tier > 1)
// ───────────────────────── Helpers ─────────────────────────
fTypeName(int t) =>
t == 0 ? "Push ▲" : t == 1 ? "Push ▼" : t == 2 ? "Absorb" : "Normal"
fPct(int a, int b) =>
b == 0 ? "—" : str.tostring(a * 100.0 / b, "0") + "%"
// ───────────────────────── Balloons ─────────────────────────
type Balloon
label lh
label rh
label tx
line st
var Balloon[] bals = array.new<Balloon>()
var int lastBal = -100
var int stack = 0
var label[] trapL = array.new<label>()
// trackers
var array<int> trBar = array.new<int>()
var array<float> trEnt = array.new<float>()
var array<float> trVcp = array.new<float>()
var array<int> trDir = array.new<int>()
var array<float> trAtr = array.new<float>()
var array<int> trTyp = array.new<int>()
var array<float> trLo = array.new<float>()
var array<float> trHi = array.new<float>()
var array<int> trFt = array.new<int>() // 0 open, 1 hit, 2 miss
var array<int> trRet = array.new<int>() // 0 open, 1 returned, 2 not
var array<bool> trLeft = array.new<bool>()
var array<int> trTrp = array.new<int>() // 0 open, 1 trap, 2 no, 3 n/a
var array<Balloon> trLab = array.new<Balloon>()
// stats per type (index 4 = all)
var array<int> stN = array.new<int>(5, 0)
var array<int> stFtW = array.new<int>(5, 0)
var array<int> stFtD = array.new<int>(5, 0)
var array<int> stRetY = array.new<int>(5, 0)
var array<int> stRetD = array.new<int>(5, 0)
var array<int> stRetB = array.new<int>(5, 0)
var array<int> stTrpY = array.new<int>(5, 0)
var array<int> stTrpD = array.new<int>(5, 0)
var int exactBars = 0
var int balBars = 0
fAdd(array<int> a, int t, int v) =>
a.set(t, a.get(t) + v)
a.set(4, a.get(4) + v)
bool trapNow = false
bool absNow = isBal and typ == 2
bool pushUp = isBal and typ == 0
bool pushDn = isBal and typ == 1
bool bigNow = isBal and tier == 3
if isBal
float pos = rng > 0 ? (vcp - low) / rng : 0.5
string where = pos >= 0.67 ? "upper third" : pos <= 0.33 ? "lower third" : "middle"
string tip = fTypeName(typ) + " balloon · " + (tier == 3 ? "Big" : tier == 2 ? "Medium" : "Small") + "\n" +
"Volume " + str.tostring(vol, format.volume) + " = " + str.tostring(ratio, "0.0") + "× normal" + (todOk ? " for this time of day" : "") + "\n" +
"Buy " + str.tostring(buyShare * 100, "0") + "% / Sell " + str.tostring((1 - buyShare) * 100, "0") + "% (" + (exact ? "intrabar" : "estimated") + ")\n" +
"Volume centre " + str.tostring(vcp, format.mintick) + " (" + where + " of the candle)\n" +
"Range " + str.tostring(rangeR, "0.00") + " ATR"
// hot-air balloon: colour = candle side + volume level, height = how big the volume is, string to the candle high
float sc = balScale == "Small" ? 0.8 : balScale == "Large" ? 1.25 : 1.0
int gsz = int(math.round((tier == 3 ? (ratio >= 4 ? 62 : 52) : tier == 2 ? 40 : 30) * sc))
// balloons close together float at different heights so they do not cover each other
stack := bar_index - lastBal <= 3 ? (stack + 1) % 3 : 0
lastBal := bar_index
float lift = (0.6 + 0.6 * math.min(ratio, 8.0) + stack * 1.8) * sc * atrv
float balY = high + lift
bool redC = close < open
int vLv = vol >= volT3 ? 3 : vol >= volT2 ? 2 : 1
color tc = redC ? (vLv == 3 ? rC3 : vLv == 2 ? rC2 : rC1) : (vLv == 3 ? gC3 : vLv == 2 ? gC2 : gC1)
// string starts a little above the wick so the wick stays visible
line stl = line.new(bar_index, high + 0.35 * atrv, bar_index, balY, color=color.new(strCol, 10), style=line.style_dotted, width=1)
label lh = label.new(bar_index, balY, "⬮", style=label.style_label_center, color=#00000000, textcolor=tc, size=gsz, tooltip=tip)
// knot at the bottom of the balloon, where the string is tied
label rh = label.new(bar_index, balY, "\n\n▴", style=label.style_label_center, color=#00000000, textcolor=tc, size=int(math.round(gsz * 0.28)), tooltip=tip)
string arw = typ == 2 ? "◆" : buyShare >= 0.5 ? "▲" : "▼"
label tx = showTxt ? label.new(bar_index, balY, arw + str.tostring(ratio, "0.0") + "×" , style=label.style_label_center, color=#00000000, textcolor=color.white, size=tier == 3 ? 12 : tier == 2 ? 9 : 7, tooltip=tip) : na
Balloon b = Balloon.new(lh, rh, tx, stl)
bals.push(b)
if bals.size() > keepBal
Balloon o = bals.shift()
label.delete(o.lh), label.delete(o.rh), label.delete(o.tx), line.delete(o.st)
// tracker
trBar.push(bar_index), trEnt.push(close), trVcp.push(vcp), trDir.push(dir), trAtr.push(atrv)
trTyp.push(typ), trLo.push(low), trHi.push(high), trFt.push(0), trRet.push(0), trLeft.push(false)
trTrp.push(typ == 2 ? 3 : 0), trLab.push(b)
fAdd(stN, typ, 1)
balBars += 1
if exact
exactBars += 1
if trBar.size() > 400
trBar.shift(), trEnt.shift(), trVcp.shift(), trDir.shift(), trAtr.shift(), trTyp.shift(), trLo.shift(), trHi.shift()
trFt.shift(), trRet.shift(), trLeft.shift(), trTrp.shift(), trLab.shift()
// update trackers on closed bars
if barstate.isconfirmed and trBar.size() > 0
for i = trBar.size() - 1 to 0
int age = bar_index - trBar.get(i)
if age > 0
int d = trDir.get(i)
int t = trTyp.get(i)
float a = trAtr.get(i)
float e = trEnt.get(i)
float vc = trVcp.get(i)
// follow-through (adverse checked first = conservative)
if trFt.get(i) == 0
float fav = d > 0 ? high - e : e - low
float adv = d > 0 ? e - low : high - e
if adv >= ftAtr * a
trFt.set(i, 2)
fAdd(stFtD, t, 1)
else if fav >= ftAtr * a
trFt.set(i, 1)
fAdd(stFtD, t, 1)
fAdd(stFtW, t, 1)
else if age >= ftBars
trFt.set(i, 2)
fAdd(stFtD, t, 1)
// return to balloon (volume centre) after price has left it by 0.5 ATR
if trRet.get(i) == 0
if not trLeft.get(i)
if math.abs(close - vc) >= 0.5 * a
trLeft.set(i, true)
else if low <= vc and high >= vc
trRet.set(i, 1)
fAdd(stRetD, t, 1)
fAdd(stRetY, t, 1)
fAdd(stRetB, t, age)
if trRet.get(i) == 0 and age >= retBars
trRet.set(i, 2)
fAdd(stRetD, t, 1)
// trap
if trTrp.get(i) == 0
bool tp = d > 0 ? close < trLo.get(i) : close > trHi.get(i)
if tp
trTrp.set(i, 1)
fAdd(stTrpD, t, 1)
fAdd(stTrpY, t, 1)
trapNow := true
Balloon tb = trLab.get(i)
if popTrap
label.set_text(tb.lh, "✸"), label.set_textcolor(tb.lh, color.new(color.gray, 20))
label.set_text(tb.rh, ""), label.set_text(tb.tx, "pop")
label.set_textcolor(tb.tx, color.gray)
else
label.set_textcolor(tb.lh, color.new(color.gray, 30))
if not popTrap
trapL.push(label.new(bar_index, d > 0 ? low : high, "✕ trap", style=d > 0 ? label.style_label_up : label.style_label_down, color=#00000000, textcolor=color.gray, size=size.tiny))
if trapL.size() > 40
label.delete(trapL.shift())
else if age >= trapBars
trTrp.set(i, 2)
fAdd(stTrpD, t, 1)
if trFt.get(i) != 0 and trRet.get(i) != 0 and trTrp.get(i) != 0
trBar.remove(i), trEnt.remove(i), trVcp.remove(i), trDir.remove(i), trAtr.remove(i), trTyp.remove(i)
trLo.remove(i), trHi.remove(i), trFt.remove(i), trRet.remove(i), trLeft.remove(i), trTrp.remove(i), trLab.remove(i)
// ───────────────────────── Balloon levels ─────────────────────────
var array<float> lvP = array.new<float>()
var array<int> lvB = array.new<int>()
var array<int> lvSd = array.new<int>() // +1 support, -1 resistance
var array<int> lvSt = array.new<int>() // 0 fresh, 1 held, 2 flipped
var array<int> lvT = array.new<int>()
var array<color> lvC = array.new<color>()
var array<line> lvLn = array.new<line>()
var array<label> lvLb = array.new<label>()
var int lvHeld = 0
var int lvBroke = 0
bool lvBreakNow = false
int lvMin = lvTier == "Big only" ? 3 : 2
if showLv and isBal and tier >= lvMin
int lvV = vol >= volT3 ? 3 : vol >= volT2 ? 2 : 1
color c = close < open ? (lvV == 3 ? rC3 : lvV == 2 ? rC2 : rC1) : (lvV == 3 ? gC3 : lvV == 2 ? gC2 : gC1)
lvP.push(vcp), lvB.push(bar_index), lvSd.push(close >= vcp ? 1 : -1), lvSt.push(0), lvT.push(0), lvC.push(c)
lvLn.push(line.new(bar_index, vcp, bar_index + 6, vcp, color=color.new(c, 30), width=1))
lvLb.push(label.new(bar_index + 4, vcp, "", style=label.style_label_left, color=c, textcolor=color.white, size=size.normal))
if lvP.size() > keepLv
line.delete(lvLn.shift()), label.delete(lvLb.shift())
lvP.shift(), lvB.shift(), lvSd.shift(), lvSt.shift(), lvT.shift(), lvC.shift()
if lvP.size() > 0 and not na(atrv)
float tol = 0.1 * atrv
for i = lvP.size() - 1 to 0
float p = lvP.get(i)
int sd = lvSd.get(i)
int st = lvSt.get(i)
bool del = bar_index - lvB.get(i) > lvAge
if barstate.isconfirmed and bar_index > lvB.get(i) and not del
bool touch = sd > 0 ? low <= p + tol and nz(low[1]) > p + tol : high >= p - tol and nz(high[1]) < p - tol
bool brk = sd > 0 ? close < p - 2 * tol : close > p + 2 * tol
if brk
lvBroke += 1
lvBreakNow := true
if st == 2
del := true
else
lvSd.set(i, -sd), lvSt.set(i, 2), lvT.set(i, 0)
else if touch
lvHeld += 1
lvT.set(i, lvT.get(i) + 1)
if st == 0
lvSt.set(i, 1)
if del
line.delete(lvLn.get(i)), label.delete(lvLb.get(i))
lvLn.remove(i), lvLb.remove(i), lvP.remove(i), lvB.remove(i), lvSd.remove(i), lvSt.remove(i), lvT.remove(i), lvC.remove(i)
else
st := lvSt.get(i)
int tn = lvT.get(i)
color c = lvC.get(i)
bool far = math.abs(close - p) > farLim * atrv
color lc = far ? #00000000 : color.new(c, st == 2 ? 45 : st == 1 ? 10 : 35)
line ln = lvLn.get(i)
line.set_x1(ln, math.max(lvB.get(i), bar_index - 4900))
line.set_x2(ln, bar_index + 6)
line.set_color(ln, lc)
line.set_width(ln, st == 1 ? 4 : 3)
line.set_style(ln, line.style_solid)
label lb = lvLb.get(i)
label.set_x(lb, bar_index + 6)
label.set_y(lb, p)
label.set_color(lb, far ? #00000000 : color.new(c, st == 2 ? 30 : 0))
label.set_textcolor(lb, far ? #00000000 : color.white)
label.set_text(lb, str.tostring(p, format.mintick) + " · " + (st == 0 ? "Fresh" : st == 1 ? "Held ×" + str.tostring(tn) : "Flipped" + (tn > 0 ? " · held ×" + str.tostring(tn) : "")))
// ───────────────────────── Candle colours (volume level) ─────────────────────────
bool redBar = close < open
int vLvB = vol >= volT3 ? 3 : vol >= volT2 ? 2 : 1
color volC = redBar ? (vLvB == 3 ? rC3 : vLvB == 2 ? rC2 : rC1) : (vLvB == 3 ? gC3 : vLvB == 2 ? gC2 : gC1)
color candC = tier > 0 ? volC : (redBar ? rC1 : gC1)
plotcandle(colorCandles ? open : na, colorCandles ? high : na, colorCandles ? low : na, colorCandles ? close : na, "Volume candles", color=candC, wickcolor=candC, bordercolor=candC, editable=true, display=display.pane)
barcolor(colorCandles ? candC : na, title="Volume bar colour")
// ───────────────────────── Pressure gauge ─────────────────────────
float pB = isBal ? vol * buyShare : 0.0
float pS = isBal ? vol * (1 - buyShare) : 0.0
float sB = math.sum(pB, pressLen)
float sS = math.sum(pS, pressLen)
float press = sB + sS > 0 ? sB / (sB + sS) : na
// ───────────────────────── Scorecard (grid) ─────────────────────────
tsz = dashSize == "Tiny" ? size.tiny : dashSize == "Normal" ? size.normal : size.small
tpos = switch dashPos
"Top Left" => position.top_left
"Bottom Right" => position.bottom_right
"Bottom Left" => position.bottom_left
=> position.top_right
var table tb = table.new(tpos, 6, 11, border_color=color.new(chart.fg_color, 90), border_width=1, frame_color=color.new(chart.fg_color, 78), frame_width=1)
var bool merged = false
fCell(int c, int r, string t, color tc, color bg, string al) =>
table.cell(tb, c, r, t, text_color=tc, text_size=tsz, bgcolor=bg, text_halign=al)
fRate(int a, int b, bool good) =>
float x = b == 0 ? na : a * 100.0 / b
color c = na(x) ? color.new(chart.fg_color, 40) : (good ? (x >= 55 ? bullCol : x <= 40 ? bearCol : chart.fg_color) : (x <= 30 ? bullCol : x >= 50 ? bearCol : chart.fg_color))
[na(x) ? "—" : str.tostring(x, "0") + "%", c]
if showDash and barstate.islast
color bg = chart.bg_color
color fg = chart.fg_color
color dim = color.new(chart.fg_color, 40)
color hd = color.new(chart.fg_color, 92)
string L = text.align_left
string C = text.align_center
// row 0: title
fCell(0, 0, "🎈 EYE VOLUME BALLOONS", fg, hd, L)
for c = 1 to 5
fCell(c, 0, "", fg, hd, C)
// row 1: pressure gauge
int cells = na(press) ? 0 : int(math.round(press * 12))
string gauge = ""
for k = 0 to 11
gauge += k < cells ? "▰" : "▱"
string pTxt = na(press) ? "Balloon pressure: no balloons in last " + str.tostring(pressLen) + " bars" : "Buyers " + str.tostring(press * 100, "0") + "% " + gauge + " " + str.tostring((1 - press) * 100, "0") + "% Sellers (last " + str.tostring(pressLen) + " bars)"
fCell(0, 1, pTxt, na(press) ? dim : press >= 0.55 ? bullCol : press <= 0.45 ? bearCol : fg, bg, L)
for c = 1 to 5
fCell(c, 1, "", fg, bg, C)
// row 2: column heads
fCell(0, 2, "", dim, hd, L)
fCell(1, 2, "Push ▲", bullCol, hd, C)
fCell(2, 2, "Push ▼", bearCol, hd, C)
fCell(3, 2, "Absorb", absCol, hd, C)
fCell(4, 2, "Normal", fg, hd, C)
fCell(5, 2, "All", fg, hd, C)
// rows 3-7
fCell(0, 3, "Balloons", dim, bg, L)
fCell(0, 4, "Follow-through " + str.tostring(ftAtr, "0.0") + " ATR", dim, bg, L)
fCell(0, 5, "Came back to balloon", dim, bg, L)
fCell(0, 6, "Avg bars to come back", dim, bg, L)
fCell(0, 7, "Trap rate", dim, bg, L)
for t = 0 to 4
fCell(t + 1, 3, str.tostring(stN.get(t)), fg, bg, C)
[f1, c1] = fRate(stFtW.get(t), stFtD.get(t), true)
fCell(t + 1, 4, f1, c1, bg, C)
[f2, c2] = fRate(stRetY.get(t), stRetD.get(t), true)
fCell(t + 1, 5, f2, c2, bg, C)
int ry = stRetY.get(t)
fCell(t + 1, 6, ry == 0 ? "—" : str.tostring(stRetB.get(t) * 1.0 / ry, "0"), fg, bg, C)
if t == 2
fCell(t + 1, 7, "n/a", dim, bg, C)
else
[f3, c3] = fRate(stTrpY.get(t), stTrpD.get(t), false)
fCell(t + 1, 7, f3, c3, bg, C)
// row 8: levels
string lvTxt = "Balloon levels: " + str.tostring(lvP.size()) + " live · touches held " + fPct(lvHeld, lvHeld + lvBroke) + " of " + str.tostring(lvHeld + lvBroke)
fCell(0, 8, lvTxt, fg, bg, L)
for c = 1 to 5
fCell(c, 8, "", fg, bg, C)
// row 9: data badge
string vt = syminfo.volumetype == "tick" ? "tick volume" : syminfo.volumetype == "n/a" ? "no volume data!" : "real volume"
string dTxt = "Data: " + vt + " · split exact on " + fPct(exactBars, balBars) + " of balloons · base: " + (todOk ? "time-of-day" : "50-bar avg")
fCell(0, 9, dTxt, syminfo.volumetype == "n/a" ? bearCol : dim, bg, L)
for c = 1 to 5
fCell(c, 9, "", fg, bg, C)
// row 10: note
fCell(0, 10, "In-sample on this chart · bar-close only · before spread/commission", dim, bg, L)
for c = 1 to 5
fCell(c, 10, "", fg, bg, C)
if not merged
table.merge_cells(tb, 0, 0, 5, 0)
table.merge_cells(tb, 0, 1, 5, 1)
table.merge_cells(tb, 0, 8, 5, 8)
table.merge_cells(tb, 0, 9, 5, 9)
table.merge_cells(tb, 0, 10, 5, 10)
merged := true
// ───────────────────────── Balloon HUD (drawn on the chart) ─────────────────────────
var label[] hudL = array.new<label>()
var line[] hudLn = array.new<line>()
var box[] hudB = array.new<box>()
fR(int a, int b) =>
b == 0 ? "—" : str.tostring(a * 100.0 / b, "0") + "%"
if barstate.islast
for l in hudL
label.delete(l)
hudL.clear()
for l in hudLn
line.delete(l)
hudLn.clear()
for b in hudB
box.delete(b)
hudB.clear()
if showHud and not na(atrv) and atrv > 0
int x0 = bar_index + hudGap
float yBal = close + 4.2 * atrv
float yBsk = close + 0.6 * atrv
color none = #00000000
color fg = chart.fg_color
color dim = color.new(chart.fg_color, 35)
string[] nm = array.from("PUSH ▲", "PUSH ▼", "ABSORB", "NORMAL", "ALL")
color[] bc = array.from(gC2, rC2, absCol, #78909C, gC3)
// title
hudL.push(label.new(x0 + 28, yBal + 3.0 * atrv, "🎈 EYE VOLUME BALLOONS", style=label.style_label_center, color=none, textcolor=fg, size=16))
// basket with the pressure gauge
int cells = na(press) ? 0 : int(math.round(press * 10))
string g = ""
for k = 0 to 9
g += k < cells ? "▰" : "▱"
string bTxt = na(press) ? "No balloons in last " + str.tostring(pressLen) + " bars" : "Buyers " + str.tostring(press * 100, "0") + "% " + g + " " + str.tostring((1 - press) * 100, "0") + "% Sellers"
color bCol = na(press) ? color.gray : press >= 0.55 ? gC2 : press <= 0.45 ? rC2 : #8D6E63
hudB.push(box.new(x0 - 5, yBsk + 0.5 * atrv, x0 + 61, yBsk - 0.5 * atrv, border_color=bCol, border_width=2, bgcolor=color.new(bCol, 80), text=bTxt, text_color=fg, text_size=12))
// five balloons with strings to the basket
for t = 0 to 4
int xb = x0 + t * 14
float yb = yBal + (t % 2 == 0 ? 0.0 : -0.8 * atrv)
color c = bc.get(t)
hudLn.push(line.new(xb, yb, xb, yBsk + 0.5 * atrv, color=color.new(fg, 50), style=line.style_dotted))
hudL.push(label.new(xb, yb, "⬮", style=label.style_label_center, color=none, textcolor=c, size=150))
string tx = nm.get(t) + "\n" + str.tostring(stN.get(t)) + "\nFT " + fR(stFtW.get(t), stFtD.get(t)) + "\nBack " + fR(stRetY.get(t), stRetD.get(t)) + (t == 2 ? "" : "\nTrap " + fR(stTrpY.get(t), stTrpD.get(t)))
hudL.push(label.new(xb, yb, tx, style=label.style_label_center, color=none, textcolor=color.white, size=10))
// footer
string vt = syminfo.volumetype == "tick" ? "tick volume" : syminfo.volumetype == "n/a" ? "no volume data!" : "real volume"
hudL.push(label.new(x0 + 28, yBsk - 1.0 * atrv, "Levels held " + fR(lvHeld, lvHeld + lvBroke) + " · " + vt + " · in-sample, bar close, before costs", style=label.style_label_center, color=none, textcolor=dim, size=8))
// ───────────────────────── Balloon card (fixed on screen) ─────────────────────────
var table cd = table.new(tpos, 5, 10, frame_color=color.new(chart.fg_color, 80), frame_width=1)
var bool cdMerged = false
if showCard and barstate.islast
color none = #00000000
color fg = chart.fg_color
color dim = color.new(chart.fg_color, 40)
color bgc = color.new(chart.bg_color, 0)
string[] nm = array.from("Push ▲", "Push ▼", "Absorb", "Normal", "All")
color[] bc = array.from(gC2, rC2, absCol, #78909C, gC3)
table.cell(cd, 0, 0, "🎈 EYE VOLUME BALLOONS", text_color=fg, text_size=12, bgcolor=bgc)
for c = 1 to 4
table.cell(cd, c, 0, "", bgcolor=bgc)
for t = 0 to 4
color c = bc.get(t)
// balloon, string, then the stats in the balloon's colour
table.cell(cd, t, 1, "⬮", text_color=c, text_size=34, bgcolor=bgc)
table.cell(cd, t, 2, "┊", text_color=dim, text_size=10, bgcolor=bgc)
table.cell(cd, t, 3, nm.get(t), text_color=color.white, text_size=10, bgcolor=c)
table.cell(cd, t, 4, str.tostring(stN.get(t)) + " balloons", text_color=fg, text_size=9, bgcolor=color.new(c, 82))
table.cell(cd, t, 5, "FT " + fR(stFtW.get(t), stFtD.get(t)), text_color=fg, text_size=9, bgcolor=color.new(c, 82))
table.cell(cd, t, 6, "Back " + fR(stRetY.get(t), stRetD.get(t)), text_color=fg, text_size=9, bgcolor=color.new(c, 82))
table.cell(cd, t, 7, t == 2 ? "Trap n/a" : "Trap " + fR(stTrpY.get(t), stTrpD.get(t)), text_color=fg, text_size=9, bgcolor=color.new(c, 82))
// basket: buyer / seller pressure
int cells = na(press) ? 0 : int(math.round(press * 12))
string g = ""
for k = 0 to 11
g += k < cells ? "▰" : "▱"
color pc = na(press) ? color.gray : press >= 0.55 ? gC2 : press <= 0.45 ? rC2 : #8D6E63
string pt = na(press) ? "🧺 No balloons in last " + str.tostring(pressLen) + " bars" : "🧺 Buyers " + str.tostring(press * 100, "0") + "% " + g + " " + str.tostring((1 - press) * 100, "0") + "% Sellers"
table.cell(cd, 0, 8, pt, text_color=fg, text_size=10, bgcolor=color.new(pc, 70))
string vt = syminfo.volumetype == "tick" ? "tick volume" : syminfo.volumetype == "n/a" ? "no volume data!" : "real volume"
table.cell(cd, 0, 9, "Levels held " + fR(lvHeld, lvHeld + lvBroke) + " · " + vt + " · in-sample, bar close, before costs", text_color=dim, text_size=8, bgcolor=bgc)
for c = 1 to 4
table.cell(cd, c, 8, "", bgcolor=color.new(pc, 70))
table.cell(cd, c, 9, "", bgcolor=bgc)
if not cdMerged
table.merge_cells(cd, 0, 0, 4, 0)
table.merge_cells(cd, 0, 8, 4, 8)
table.merge_cells(cd, 0, 9, 4, 9)
cdMerged := true
// ───────────────────────── Alerts ─────────────────────────
alertcondition(bigNow, "Big balloon", "Eye Volume Balloons: big volume balloon on bar close")
alertcondition(pushUp, "Push ▲ balloon", "Eye Volume Balloons: buyers push balloon on bar close")
alertcondition(pushDn, "Push ▼ balloon", "Eye Volume Balloons: sellers push balloon on bar close")
alertcondition(absNow, "Absorb balloon", "Eye Volume Balloons: absorption balloon (big volume, small move) on bar close")
alertcondition(barstate.isconfirmed and trapNow, "Balloon trap", "Eye Volume Balloons: a balloon turned into a trap")
alertcondition(barstate.isconfirmed and lvBreakNow, "Balloon level broken", "Eye Volume Balloons: price closed through a balloon level")
if isBal and tier >= 2
alert("Eye Volume Balloons | " + syminfo.ticker + " " + timeframe.period + " | " + fTypeName(typ) + " " + (tier == 3 ? "BIG" : "MEDIUM") + " balloon | " + str.tostring(ratio, "0.0") + "× normal | buy " + str.tostring(buyShare * 100, "0") + "% | centre " + str.tostring(vcp, format.mintick), alert.freq_once_per_bar_close)