本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Crypto Liquidation Heatmap", overlay = true, max_boxes_count = 480, max_polylines_count = 100, max_labels_count = 10, max_bars_back = 100, behind_chart = true)
// Independently implemented from the accompanying frozen specification.
// Estimates from net OI growth; not exchange liquidation orders or measured leverage.
// Each contract has two sides. Scenarios are alternatives, not additive positions.
string G_MODEL = "01 · Exposure assumptions"
float lev1 = input.float(10, "Leverage scenario A", minval = 2, maxval = 100, group = G_MODEL, tooltip = "An assumed leverage, not observed trader leverage. All three scenarios receive the same net new OI independently.")
float lev2 = input.float(25, "Leverage scenario B", minval = 2, maxval = 100, group = G_MODEL, tooltip = "Alternative leverage hypothesis. Keep scenarios distinct to make agreement meaningful.")
float lev3 = input.float(50, "Leverage scenario C", minval = 2, maxval = 100, group = G_MODEL, tooltip = "Alternative leverage hypothesis. The display averages scenarios; their weights are not probabilities.")
float mmr = input.float(0.5, "Assumed maintenance margin %", minval = 0.01, maxval = 5, step = 0.05, group = G_MODEL, tooltip = "Simplified linear isolated margin only. Must be below 100 divided by the largest leverage. Excludes fees, collateral changes and risk tiers.") / 100
float halfLife = input.float(24, "Memory half-life · hours", minval = 1, maxval = 168, group = G_MODEL, tooltip = "Time-based forgetting assumption. A fading band does not prove positions closed.")
float maxAge = input.float(72, "Maximum cohort age · hours", minval = 1, maxval = 336, group = G_MODEL, tooltip = "Hard memory expiry. The cohort-count cap can shorten this horizon.")
int capacity = input.int(96, "Maximum OI-growth cohorts", minval = 12, maxval = 160, group = G_MODEL, tooltip = "Retains only the newest positive-OI observations. Oldest cohorts are dropped at capacity; the dashboard reports those drops.")
string G_GRID = "02 · Heatmap and scenario agreement"
float binPct = input.float(0.35, "Price-bin width %", minval = 0.05, maxval = 2, step = 0.05, group = G_GRID, tooltip = "Fixed logarithmic bins. Wider bins increase apparent scenario agreement. This is display resolution, not predictive accuracy.")
int rows = input.int(24, "Price rows", minval = 12, maxval = 24, step = 2, group = G_GRID, tooltip = "Rows centered around each snapshot close. Distant modeled exposure can fall outside the display.")
int columns = input.int(18, "Historical snapshots", minval = 6, maxval = 18, group = G_GRID, tooltip = "Frozen snapshots, each beginning at its calculation close. Old snapshots are discarded to bound drawing count.")
int stride = input.int(4, "Bars per snapshot", minval = 1, maxval = 12, group = G_GRID, tooltip = "Sample-and-hold history, not tick history. Latest profile updates on every confirmed close.")
float saturation = input.float(0.8, "Full color · modeled OI %", minval = 0.05, maxval = 10, step = 0.05, group = G_GRID, tooltip = "Fixed color scale shared across historical snapshots. Values are scenario-average exposure divided by then-current OI.")
float agreementFloor = input.float(0.05, "Per-scenario agreement floor · OI %", minval = 0.01, maxval = 5, step = 0.01, group = G_GRID, tooltip = "A border requires the SAME two scenarios to exceed this floor in the base bin AND one overlapping half-bin-shifted bin. Tests one grid displacement, not accuracy or probability.")
string G_VIEW = "03 · Presentation"
bool showHeading = input.bool(true, "Show heading and key", group = G_VIEW)
bool showDashboard = input.bool(true, "Show diagnostics", group = G_VIEW)
bool theme = input.bool(true, "Navy background / neutral candles", group = G_VIEW, tooltip = "Presentation only. Blue denotes short-side estimates above price; orange denotes long-side estimates below price.")
int profileWidth = input.int(18, "Profile width · bars", minval = 8, maxval = 40, group = G_VIEW, tooltip = "Current confirmed exposure, placed to the right of price. Leave right chart margin for this profile.")
string G_HISTORY = "04 · Historical coverage"
string historyMode = input.string("Auto", "History view", options = ["Auto", "Recent", "Long history"], group = G_HISTORY, tooltip = "Auto uses the recent snapshot view below 12h and long history on 12h or 1D. Long history changes retained drawings, not exposure aging or leverage assumptions.")
int historyDays = input.int(730, "Historical window · days", minval = 30, maxval = 3650, group = G_HISTORY, tooltip = "Requested lookback ending at the latest loaded chart bar. Actual coverage depends on available OI. Old snapshots describe estimates at that past time, not positions still open today.")
int historyColumns = input.int(240, "Historical time samples", minval = 60, maxval = 360, step = 20, group = G_HISTORY, tooltip = "The window is sampled at an epoch-aligned whole-bar stride. With 730 days, 240 samples and 12h bars, snapshots are seven bars apart. Fine intrabar changes are not shown.")
bool showMeter = input.bool(true, "Show exposure meter", group = G_VIEW, tooltip = "Left-side color scale for modeled exposure in a price bin, as a percentage of open interest at that time. Blue is short-side exposure and orange is long-side exposure.")
string meterPosition = input.string("Lower left", "Meter position", options = ["Lower left", "Middle left", "Lower right"], group = G_VIEW, tooltip = "Choose a clear corner for the scale when candles overlap it.")
bool showBandNumbers = input.bool(true, "Show exposure inside profile bands", group = G_VIEW, tooltip = "Each number is the modeled exposure in that price bin as a percentage of open interest at the last confirmed close.")
string palette = input.string("Multicolor", "Band colors", options = ["Multicolor", "Classic blue/orange"], group = G_VIEW, tooltip = "Shorts progress from violet through blue to cyan. Longs progress from rust through orange to yellow. Brighter colors indicate more modeled exposure.")
color BLUE = #246BFF
color ORANGE = #FF8A18
color NAVY = #091322
color INK = #E3EAF5
float stepLog = math.log(1 + binPct / 100)
int barMs = int(timeframe.in_seconds() * 1000)
bool longHistory = historyMode == "Long history" or (historyMode == "Auto" and barMs >= 43200000)
int historyStride = longHistory ? math.max(1, int(math.ceil(historyDays * 86400000.0 / barMs / historyColumns))) : stride
int historyCutoff = last_bar_time - historyDays * 86400000
int retainedColumns = longHistory ? historyColumns : columns
string oiSymbol = ticker.standard(syminfo.tickerid) + "_OI"
[oi, oiTime, oiCloseTime] = request.security(oiSymbol, timeframe.period, [close, time, time_close], gaps = barmerge.gaps_on, lookahead = barmerge.lookahead_off, ignore_invalid_symbol = true)
bool supported = chart.is_standard and syminfo.prefix == "BINANCE" and str.endswith(syminfo.ticker, "USDT.P") and (timeframe.isintraday or timeframe.isdaily) and barMs >= 300000 and barMs <= 86400000
bool parametersOK = mmr < 1 / math.max(lev1, lev2, lev3) and lev1 != lev2 and lev1 != lev3 and lev2 != lev3
bool dataOK = supported and parametersOK and not na(oi) and oi > 0 and oiTime == time and oiCloseTime == time_close and low > 0
type Cohort
int born
array<float> lp
array<float> sp
array<float> lw
array<float> sw
type Frame
int stamp
int finish
int origin
float denominator
array<float> longs
array<float> shorts
array<int> stableLong
array<int> stableShort
type PaintBucket
array<chart.point> points
color shade
f_long(float entry, float leverage, float margin) =>
entry * (1 - 1 / leverage) / (1 - margin)
f_short(float entry, float leverage, float margin) =>
entry * (1 + 1 / leverage) / (1 + margin)
f_grid(array<Cohort> pool, int origin, int count, float step, float offset = 0) =>
array<float> longs = array.new_float(count * 3, 0)
array<float> shorts = array.new_float(count * 3, 0)
for cohort in pool
for j = 0 to 8
int scenario = int(j / 3)
int lr = int(math.floor(math.log(cohort.lp.get(j)) / step - offset)) - origin
int sr = int(math.floor(math.log(cohort.sp.get(j)) / step - offset)) - origin
if lr >= 0 and lr < count
int index = lr * 3 + scenario
longs.set(index, longs.get(index) + cohort.lw.get(j))
if sr >= 0 and sr < count
int index = sr * 3 + scenario
shorts.set(index, shorts.get(index) + cohort.sw.get(j))
[longs, shorts]
f_cell(array<float> values, int row, float denominator) =>
float total = 0
int agreement = 0
for s = 0 to 2
float pct = 100 * values.get(row * 3 + s) / denominator
total += pct / 3
agreement += pct >= agreementFloor ? 1 : 0
[total, agreement]
// Same inventory, shifted bin origin. Count matching scenario identities,
// not just two unrelated agreement counts; never add the two grids' masses.
f_stable(array<float> base, array<float> shifted, int row, float denominator) =>
int leftSupport = 0
int rightSupport = 0
for s = 0 to 2
bool basePass = 100 * base.get(row * 3 + s) / denominator >= agreementFloor
leftSupport += basePass and 100 * shifted.get(row * 3 + s) / denominator >= agreementFloor ? 1 : 0
rightSupport += basePass and 100 * shifted.get((row + 1) * 3 + s) / denominator >= agreementFloor ? 1 : 0
math.max(leftSupport, rightSupport)
// Twelve intervals plus a distinct full-strength swatch for values at the cap.
f_level(float pct) =>
math.min(12, int(12 * math.sqrt(pct / saturation)))
f_shade(int level, bool longSide) =>
color shade = color.new(longSide ? ORANGE : BLUE, 94 - 6 * level)
if palette == "Multicolor"
color dim = longSide ? #512638 : #352451
color mid = longSide ? #D05229 : #3D51BD
color bright = longSide ? #F79A26 : #178CC9
color peak = longSide ? #FFF269 : #77F0DB
shade := level <= 4 ? color.from_gradient(level, 0, 4, dim, mid) : level <= 8 ? color.from_gradient(level, 4, 8, mid, bright) : color.from_gradient(level, 8, 12, bright, peak)
shade
f_color(float pct, bool longSide) =>
f_shade(f_level(pct), longSide)
var array<Cohort> cohorts = array.new<Cohort>()
var array<Frame> frames = array.new<Frame>()
var array<box> drawing = array.new<box>()
var array<polyline> historyDrawing = array.new<polyline>()
// Rectangles share a transparent, exactly retraced bridge to the first point.
// The bridge encloses zero area. This batches independent cells by color and
// avoids the 500-box ceiling without inventing extra historical observations.
f_rectangle(PaintBucket bucket, int left, int right, float bottom, float top, array<polyline> rendered) =>
if bucket.points.size() > 8990
rendered.push(polyline.new(bucket.points, closed = true, xloc = xloc.bar_time, line_color = na, fill_color = bucket.shade))
bucket.points.clear()
if bucket.points.size() == 0
bucket.points.push(chart.point.from_time(left, bottom))
bucket.points.push(chart.point.from_time(left, bottom))
bucket.points.push(chart.point.from_time(right, bottom))
bucket.points.push(chart.point.from_time(right, top))
bucket.points.push(chart.point.from_time(left, top))
bucket.points.push(chart.point.from_time(left, bottom))
bucket.points.push(bucket.points.first())
var float previousOI = na
var int previousClose = na
var int lastClose = na
var float lastPrice = na
var float lastOI = na
var int evicted = 0
var int resets = 0
var int observations = 0
var float longTotal = 0
var float shortTotal = 0
var float visibleFraction = 0
var int agreementLong = 0
var int agreementShort = 0
var int stableLongCount = 0
var int stableShortCount = 0
var bool hadLongAgreement = false
var bool hadShortAgreement = false
var array<float> currentLong = array.new_float(rows * 3, 0)
var array<float> currentShort = array.new_float(rows * 3, 0)
var array<int> currentStableLong = array.new_int(rows, 0)
var array<int> currentStableShort = array.new_int(rows, 0)
var int currentOrigin = 0
float crossedLong = 0
float crossedShort = 0
bool continuityLost = false
bool newLongAgreement = false
bool newShortAgreement = false
if barstate.isconfirmed
bool contiguous = not na(previousClose) and time == previousClose
bool reset = not dataOK or (not na(previousClose) and not contiguous)
if reset
continuityLost := not na(previousOI)
resets += continuityLost ? 1 : 0
cohorts.clear()
// Keep valid past observations in long-history mode; each frame has an
// explicit finish, so no cell carries through a missing-data interval.
if not longHistory
frames.clear()
previousOI := na
previousClose := na
lastOI := na
lastClose := na
longTotal := 0
shortTotal := 0
currentLong.fill(0)
currentShort.fill(0)
currentStableLong.fill(0)
currentStableShort.fill(0)
observations := 0
visibleFraction := 0
agreementLong := 0
agreementShort := 0
stableLongCount := 0
stableShortCount := 0
hadLongAgreement := false
hadShortAgreement := false
if dataOK
float delta = na(previousOI) ? 0 : oi - previousOI
float contraction = na(previousOI) ? 1 : math.min(1, oi / previousOI)
float aging = na(previousClose) ? 1 : math.pow(0.5, (time_close - previousClose) / 3600000.0 / halfLife)
if cohorts.size() > 0
for c = cohorts.size() - 1 to 0
Cohort cohort = cohorts.get(c)
bool expired = time_close - cohort.born > maxAge * 3600000
float remaining = 0
for j = 0 to 8
float lw = cohort.lw.get(j)
float sw = cohort.sw.get(j)
bool crossL = low <= cohort.lp.get(j)
bool crossS = high >= cohort.sp.get(j)
// Expired memory is not classified as a newly crossed estimate.
crossedLong += not expired and crossL ? lw / 3 : 0
crossedShort += not expired and crossS ? sw / 3 : 0
lw := expired or crossL ? 0 : lw * contraction * aging
sw := expired or crossS ? 0 : sw * contraction * aging
cohort.lw.set(j, lw)
cohort.sw.set(j, sw)
remaining += lw + sw
if remaining == 0
cohorts.remove(c)
if delta > 0
if cohorts.size() >= capacity
cohorts.shift()
evicted += 1
Cohort cohort = Cohort.new(time_close, array.new_float(), array.new_float(), array.new_float(), array.new_float())
for scenario = 0 to 2
float leverage = scenario == 0 ? lev1 : scenario == 1 ? lev2 : lev3
for e = 0 to 2
float entry = e == 0 ? low : e == 1 ? hl2 : high
float weight = delta * (e == 1 ? 0.5 : 0.25)
float lp = f_long(entry, leverage, mmr)
float sp = f_short(entry, leverage, mmr)
cohort.lp.push(lp)
cohort.sp.push(sp)
cohort.lw.push(lp < close ? weight : 0)
cohort.sw.push(sp > close ? weight : 0)
cohorts.push(cohort)
longTotal := 0
shortTotal := 0
for cohort in cohorts
longTotal += cohort.lw.sum() / 3
shortTotal += cohort.sw.sum() / 3
currentOrigin := int(math.floor(math.log(close) / stepLog)) - int(rows / 2)
[gridLong, gridShort] = f_grid(cohorts, currentOrigin, rows, stepLog)
[shiftLong, shiftShort] = f_grid(cohorts, currentOrigin - 1, rows + 1, stepLog, 0.5)
currentLong := gridLong
currentShort := gridShort
float total = longTotal + shortTotal
visibleFraction := total > 0 ? 100 * (gridLong.sum() + gridShort.sum()) / 3 / total : 0
agreementLong := 0
agreementShort := 0
stableLongCount := 0
stableShortCount := 0
for row = 0 to rows - 1
[lpct, lsupport] = f_cell(gridLong, row, oi)
[spct, ssupport] = f_cell(gridShort, row, oi)
agreementLong += lsupport >= 2 ? 1 : 0
agreementShort += ssupport >= 2 ? 1 : 0
int stableL = f_stable(gridLong, shiftLong, row, oi)
int stableS = f_stable(gridShort, shiftShort, row, oi)
currentStableLong.set(row, stableL)
currentStableShort.set(row, stableS)
stableLongCount += stableL >= 2 ? 1 : 0
stableShortCount += stableS >= 2 ? 1 : 0
newLongAgreement := stableLongCount > 0 and not hadLongAgreement
newShortAgreement := stableShortCount > 0 and not hadShortAgreement
hadLongAgreement := stableLongCount > 0
hadShortAgreement := stableShortCount > 0
// A cell is a sample-and-hold observation, bounded by actual continuity.
if frames.size() > 0 and not na(previousOI)
Frame activeFrame = frames.last()
activeFrame.finish := time_close
bool inHistoryWindow = not longHistory or time_close >= historyCutoff
bool takeSnapshot = inHistoryWindow and (int(time_close / barMs) % historyStride == 0 or (longHistory and (frames.size() == 0 or na(previousOI))))
if takeSnapshot
frames.push(Frame.new(time_close, time_close, currentOrigin, oi, gridLong.copy(), gridShort.copy(), currentStableLong.copy(), currentStableShort.copy()))
if frames.size() > retainedColumns
frames.shift()
if longHistory
while frames.size() > 0
if frames.first().stamp >= historyCutoff
break
frames.shift()
previousOI := oi
previousClose := time_close
lastClose := time_close
lastPrice := close
lastOI := oi
observations += 1
bgcolor(theme ? NAVY : na)
barcolor(theme ? (close >= open ? #DDE5F1 : #78869B) : na)
var table header = table.new(position.top_center, 1, 3)
var table key = table.new(position.bottom_center, 1, 2)
var table info = table.new(position.top_right, 2, 12, bgcolor = color.new(NAVY, 15))
var table meter = table.new(meterPosition == "Lower left" ? position.bottom_left : meterPosition == "Lower right" ? position.bottom_right : position.middle_left, 3, 15, bgcolor = NAVY)
if barstate.isfirst
table.merge_cells(meter, 0, 0, 2, 0)
if barstate.islastconfirmedhistory or (barstate.islast and barstate.isconfirmed)
for item in drawing
box.delete(item)
drawing.clear()
for item in historyDrawing
polyline.delete(item)
historyDrawing.clear()
array<PaintBucket> buckets = array.new<PaintBucket>()
if longHistory
for side = 0 to 1
for level = 0 to 12
color shade = f_shade(level, side == 0)
buckets.push(PaintBucket.new(array.new<chart.point>(), shade))
buckets.push(PaintBucket.new(array.new<chart.point>(), color.new(INK, 78)))
if not na(lastOI) or longHistory
if frames.size() > 0
for f = 0 to frames.size() - 1
Frame frame = frames.get(f)
int end = frame.finish
if end > frame.stamp
for row = 0 to rows - 1
[lpct, lsupport] = f_cell(frame.longs, row, frame.denominator)
[spct, ssupport] = f_cell(frame.shorts, row, frame.denominator)
bool longSide = lpct >= spct
float pct = math.max(lpct, spct)
int support = longSide ? frame.stableLong.get(row) : frame.stableShort.get(row)
if pct > 0.001
float bottom = math.exp((frame.origin + row) * stepLog)
float top = math.exp((frame.origin + row + 1) * stepLog)
color border = support >= 2 ? color.new(longSide ? ORANGE : BLUE, support == 3 ? 20 : 50) : na
if longHistory
int level = f_level(pct)
f_rectangle(buckets.get((longSide ? 0 : 13) + level), frame.stamp, end, bottom, top, historyDrawing)
if support >= 2
float midpoint = (top + bottom) / 2
f_rectangle(buckets.get(26), frame.stamp, end, midpoint - (top - bottom) * 0.07, midpoint + (top - bottom) * 0.07, historyDrawing)
else
drawing.push(box.new(frame.stamp, top, end, bottom, xloc = xloc.bar_time, border_color = border, bgcolor = f_color(pct, longSide)))
int profileLeft = lastClose + barMs * 3
for row = 0 to rows - 1
[lpct, lsupport] = f_cell(currentLong, row, lastOI)
[spct, ssupport] = f_cell(currentShort, row, lastOI)
bool longSide = lpct >= spct
float pct = math.max(lpct, spct)
int support = longSide ? currentStableLong.get(row) : currentStableShort.get(row)
if pct > 0.001
float bottom = math.exp((currentOrigin + row) * stepLog)
float top = math.exp((currentOrigin + row + 1) * stepLog)
int width = math.max(1, int(profileWidth * math.min(1, pct / saturation)))
string caption = showBandNumbers ? str.tostring(pct, pct < 0.01 ? "0.000" : "0.00") : ""
box profileBand = box.new(profileLeft, top, profileLeft + width * barMs, bottom, xloc = xloc.bar_time, bgcolor = f_color(pct, longSide), border_color = support >= 2 ? color.new(longSide ? ORANGE : BLUE, 25) : na, text = caption, text_color = palette == "Multicolor" and f_level(pct) >= (longSide ? 7 : 9) ? NAVY : color.white, text_size = size.small, text_halign = text.align_center, text_valign = text.align_center, text_wrap = text.wrap_none)
drawing.push(profileBand)
if longHistory
for bucket in buckets
if bucket.points.size() > 0
historyDrawing.push(polyline.new(bucket.points, closed = true, xloc = xloc.bar_time, line_color = na, fill_color = bucket.shade))
table.clear(header, 0, 0, 0, 2)
table.clear(key, 0, 0, 0, 1)
table.clear(info, 0, 0, 1, 11)
if showMeter and (not na(lastOI) or frames.size() > 0)
table.cell(meter, 0, 0, "Exposure scale", text_color = INK, text_size = 14)
table.cell(meter, 0, 1, "Short", text_color = #79A4FF, text_size = 11)
table.cell(meter, 1, 1, "Long", text_color = #FFAD63, text_size = 11)
table.cell(meter, 2, 1, "% OI", text_color = INK, text_size = 11, tooltip = "Lower edge of each shade, as a percentage of open interest when sampled.")
for level = 0 to 12
int row = 14 - level
float lowerEdge = saturation * math.pow(level / 12.0, 2)
string label = level % 3 == 0 ? str.tostring(lowerEdge, "0.00##") + (level == 12 ? "+" : "") : ""
table.cell(meter, 0, row, "", width = 2, height = 1.6, bgcolor = f_shade(level, false))
table.cell(meter, 1, row, "", width = 2, height = 1.6, bgcolor = f_shade(level, true))
table.cell(meter, 2, row, label, height = 1.6, text_color = INK, text_size = 10, bgcolor = NAVY)
else
table.clear(meter, 0, 0, 2, 14)
if showHeading
table.cell(header, 0, 0, "", height = 4)
table.cell(header, 0, 1, "CRYPTO LIQUIDATION HEATMAP", text_color = INK, text_size = 30)
table.cell(header, 0, 2, showBandNumbers ? "Band numbers = estimated % of open interest" : "Estimated exposure at the last confirmed close", text_color = INK, text_size = 15)
table.cell(key, 0, 0, palette == "Multicolor" ? "SHORT violet → blue → cyan LONG rust → orange → yellow" : "BLUE short-side estimates ORANGE long-side estimates", text_color = INK, text_size = 13, bgcolor = color.new(NAVY, 12))
table.cell(key, 0, 1, "Brighter bands = more exposure · " + (longHistory ? "Historical inset" : "Historical border") + " = agreement after a half-bin shift", text_color = #9DAEC6, text_size = 11, bgcolor = color.new(NAVY, 12))
string status = not supported ? "Binance USDT.P · standard 5m–1D" : not parametersOK ? "Check distinct leverage / margin" : na(lastOI) ? "NO ALIGNED OI — model empty" : observations < 2 ? "BASELINE — awaiting OI change" : "CONFIRMED · estimates only"
if showDashboard or na(lastOI)
table.cell(info, 0, 0, "MODEL", text_color = INK, text_size = 11)
table.cell(info, 1, 0, status, text_color = na(lastOI) ? ORANGE : INK, text_size = 11)
table.cell(info, 0, 1, "OI feed", text_color = #9DAEC6, text_size = 10)
table.cell(info, 1, 1, oiSymbol, text_color = INK, text_size = 10)
table.cell(info, 0, 2, "Scenarios", text_color = #9DAEC6, text_size = 10)
table.cell(info, 1, 2, str.tostring(lev1) + " / " + str.tostring(lev2) + " / " + str.tostring(lev3) + "x", text_color = INK, text_size = 10)
table.cell(info, 0, 3, "Cohorts / cap drops", text_color = #9DAEC6, text_size = 10)
table.cell(info, 1, 3, str.tostring(cohorts.size()) + " / " + str.tostring(evicted), text_color = INK, text_size = 10)
table.cell(info, 0, 4, "History resets", text_color = #9DAEC6, text_size = 10)
table.cell(info, 1, 4, str.tostring(resets), text_color = INK, text_size = 10)
table.cell(info, 0, 5, "In current grid", text_color = #9DAEC6, text_size = 10)
table.cell(info, 1, 5, str.tostring(visibleFraction, "#.0") + "% modeled mass", text_color = INK, text_size = 10)
table.cell(info, 0, 6, "Raw agreement L / S", text_color = #9DAEC6, text_size = 10)
table.cell(info, 1, 6, str.tostring(agreementLong) + " / " + str.tostring(agreementShort), text_color = INK, text_size = 10)
table.cell(info, 0, 7, "State as of", text_color = #9DAEC6, text_size = 10)
table.cell(info, 1, 7, na(lastClose) ? "—" : str.format_time(lastClose, "MM-dd HH:mm", "UTC") + " UTC", text_color = INK, text_size = 10)
table.cell(info, 0, 8, "Crossing proxy", text_color = #9DAEC6, text_size = 10)
table.cell(info, 1, 8, "Last price OHLC · not mark", text_color = INK, text_size = 10)
table.cell(info, 0, 9, "Grid-stable bins L / S", text_color = #9DAEC6, text_size = 10)
table.cell(info, 1, 9, str.tostring(stableLongCount) + " / " + str.tostring(stableShortCount), text_color = INK, text_size = 10)
table.cell(info, 0, 10, "Retained history starts", text_color = #9DAEC6, text_size = 10)
table.cell(info, 1, 10, frames.size() > 0 ? str.format_time(frames.first().stamp, "yyyy-MM-dd", "UTC") : "No observations", text_color = INK, text_size = 10)
table.cell(info, 0, 11, "Samples / cadence", text_color = #9DAEC6, text_size = 10)
table.cell(info, 1, 11, str.tostring(frames.size()) + " / " + str.tostring(historyStride) + " bars", text_color = INK, text_size = 10)
plot(oi, "Source OI", display = display.data_window)
plot(dataOK ? 1 : 0, "Aligned supported data", display = display.data_window)
plot(longTotal, "Mean surviving long estimates · OI units", display = display.data_window)
plot(shortTotal, "Mean surviving short estimates · OI units", display = display.data_window)
plot(crossedLong, "Crossed long estimates · not liquidations", display = display.data_window)
plot(crossedShort, "Crossed short estimates · not liquidations", display = display.data_window)
plot(cohorts.size(), "Retained cohorts", display = display.data_window)
plot(evicted, "Capacity drops", display = display.data_window)
plot(resets, "OI continuity resets", display = display.data_window)
plot(visibleFraction, "Displayed fraction %", display = display.data_window)
plot(agreementLong, "Long agreement bins", display = display.data_window)
plot(agreementShort, "Short agreement bins", display = display.data_window)
plot(observations, "Continuous valid observations", display = display.data_window)
plot(oiTime, "OI timestamp", display = display.data_window)
plot(oiCloseTime, "OI close timestamp", display = display.data_window)
plot(stableLongCount, "Grid-stable long bins", display = display.data_window)
plot(stableShortCount, "Grid-stable short bins", display = display.data_window)
plot(frames.size(), "Retained historical snapshots", display = display.data_window)
plot(frames.size() > 0 ? frames.first().stamp : na, "Oldest snapshot timestamp", display = display.data_window)
// Hidden same-feed audit fields allow independent state reconstruction without
// relying on a different exchange's candles or a shorter main-chart buffer.
plot(low, "Audit low", display = display.none)
plot(high, "Audit high", display = display.none)
plot(close, "Audit close", display = display.none)
alertcondition(barstate.isconfirmed and crossedLong > 0, "Long estimates crossed", "Price crossed modeled long-side levels. These are estimates, not observed liquidation events.")
alertcondition(barstate.isconfirmed and crossedShort > 0, "Short estimates crossed", "Price crossed modeled short-side levels. These are estimates, not observed liquidation events.")
alertcondition(barstate.isconfirmed and newLongAgreement, "Grid-stable long agreement appeared", "At least one displayed long-side bin now has the same two or more scenarios above threshold after a half-bin shift. Not a trading signal.")
alertcondition(barstate.isconfirmed and newShortAgreement, "Grid-stable short agreement appeared", "At least one displayed short-side bin now has the same two or more scenarios above threshold after a half-bin shift. Not a trading signal.")
alertcondition(barstate.isconfirmed and continuityLost, "OI continuity lost", "OI or price continuity broke. Liquidation Heatmap cleared its model and is rebuilding from aligned observations.")