本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("GM Supply & Demand - Easy MTF v2.2", shorttitle="GM S&D Easy", overlay=true, max_boxes_count=300, max_labels_count=200, max_bars_back=500, dynamic_requests=true)
// Original compression / ATR / ADX rules, calculated in each source timeframe.
// Complete source history is processed before its active zones are displayed.
// Requests return one confirmed source snapshot instead of intrabar arrays.
// Each source still calculates EVERY bar of its own history before sampling.
// Lower TF snapshots have one extra source-bar delay on historical chart bars.
// Active zone collections are copied only near the end of the source dataset.
// This is a live active-zone map, not a historical backtest of visible boxes.
// Minute/hour/day edition. Presets select sources; they do not change zone rules.
// Start with Intraday on a standard 5m chart. No account tier is auto-detected.
string gQuick = "1. Quick setup"
setup = input.string("Intraday", "Timeframe preset", options=["Intraday", "Scalping", "Swing", "Custom", "All 7"], group=gQuick, display=display.none,
tooltip="Intraday: 5m + 1H. Scalping: 1m + 5m + 15m. Swing: 1H + 4H + Daily. Custom uses the switches below. All 7 uses every minute/hour/day source. Start with Intraday on a standard 5m chart. Presets only select timeframes; they do not tune the zone rules or predict performance.")
zonesPerSide = input.int(2, "Zones per side / timeframe", minval=1, maxval=10, group=gQuick, display=display.none,
tooltip="Keeps up to this many active demand and supply zones from each selected timeframe. With Intraday and 2 per side, at most 8 confirmed boxes are shown. Older active zones beyond the limit are discarded, not merely hidden.")
demandColor = input.color(color.teal, "Demand colour", group=gQuick, inline="col")
supplyColor = input.color(color.red, "Supply colour", group=gQuick, inline="col")
historyChoice = input.string("Standard (5000)", "History", options=["Light (2000)", "Standard (5000)", "Extended (10000)"], group=gQuick, display=display.none,
tooltip="Requested bars per source. Standard is the default. Light reduces calculation work but can omit older zones. Extended requests more history where available. These settings do not unlock data beyond your account or symbol limits. The source matching the chart uses the chart's loaded history.")
int historyBars = historyChoice == "Light (2000)" ? 2000 : historyChoice == "Extended (10000)" ? 10000 : 5000
int maxDemandZones = zonesPerSide
int maxSupplyZones = zonesPerSide
bool customFrames = setup == "Custom"
bool allFrames = setup == "All 7"
string gCustom = "2. Custom timeframes"
showM1 = input.bool(false, "1 minute", group=gCustom, active=customFrames)
showM5 = input.bool(true, "5 minutes", group=gCustom, active=customFrames)
showM15 = input.bool(false, "15 minutes", group=gCustom, active=customFrames)
showM30 = input.bool(false, "30 minutes", group=gCustom, active=customFrames)
showH1 = input.bool(true, "1 hour", group=gCustom, active=customFrames)
showH4 = input.bool(false, "4 hours", group=gCustom, active=customFrames)
showD = input.bool(false, "Daily", group=gCustom, active=customFrames)
bool useD = allFrames or (customFrames ? showD : setup == "Swing")
bool useH4 = allFrames or (customFrames ? showH4 : setup == "Swing")
bool useH1 = allFrames or (customFrames ? showH1 : setup == "Intraday" or setup == "Swing")
bool useM30 = allFrames or (customFrames ? showM30 : false)
bool useM15 = allFrames or (customFrames ? showM15 : setup == "Scalping")
bool useM5 = allFrames or (customFrames ? showM5 : setup == "Intraday" or setup == "Scalping")
bool useM1 = allFrames or (customFrames ? showM1 : setup == "Scalping")
string gDisplay = "3. Appearance and alerts"
extendZones = input.bool(true, "Extend zones to the right", group=gDisplay)
showStrength = input.bool(false, "Show strength text inside zones", group=gDisplay,
tooltip="Strength is the original heuristic based on base length and breakout size. It is not a success probability.")
showPending = input.bool(false, "Show forming zones", group=gDisplay)
showLabels = input.bool(false, "Show breakout labels", group=gDisplay)
showDashboard = input.bool(false, "Show timeframe status table", group=gDisplay)
showHelp = input.bool(true, "Show help when no zones are visible", group=gDisplay,
tooltip="A short message explains an empty chart. It disappears when a zone is visible. No status table is shown unless enabled separately.")
showRetest = input.bool(true, "Include clean retests in alerts", group=gDisplay,
tooltip="Retest triangles remain hidden. Alerts can be created only if your TradingView plan supports technical alerts. Choose GM Zones Phone Alert for one combined alert, and Once Per Bar Close for settled notifications.")
string gLogic = "4. Advanced zone settings"
advanced = input.bool(false, "Use custom zone rules", group=gLogic,
tooltip="Off uses the original v2.1 zone rules. Enable to edit the settings below. These settings affect zone formation on every selected source timeframe.")
zoneLenInput = input.int(24, "Standard Sideways Lookback", minval=8, maxval=100, group=gLogic, active=advanced, display=display.none)
zoneLen = advanced ? zoneLenInput : 24
rangeAtrMultInput = input.float(2.4, "Standard Max Range x ATR", minval=0.05, step=0.1, group=gLogic, active=advanced, display=display.none)
rangeAtrMult = advanced ? rangeAtrMultInput : 2.4
enableMicroInput = input.bool(true, "Enable Micro Sideways Detection", group=gLogic, active=advanced, display=display.none)
enableMicro = advanced ? enableMicroInput : true
microLenInput = input.int(8, "Micro Sideways Lookback", minval=4, maxval=30, group=gLogic, active=advanced, display=display.none)
microLen = advanced ? microLenInput : 8
microRangeAtrMultInput = input.float(1.30, "Micro Max Range x ATR", minval=0.05, step=0.05, group=gLogic, active=advanced, display=display.none)
microRangeAtrMult = advanced ? microRangeAtrMultInput : 1.30
sourceModeInput = input.string("Bodies", "Zone Source", options=["Bodies", "Wicks"], group=gLogic, active=advanced, display=display.none)
sourceMode = advanced ? sourceModeInput : "Bodies"
atrLenInput = input.int(14, "ATR Length", minval=1, maxval=200, group=gLogic, active=advanced, display=display.none)
atrLen = advanced ? atrLenInput : 14
diLenInput = input.int(14, "DI Length", minval=1, maxval=200, group=gLogic, active=advanced, display=display.none)
diLen = advanced ? diLenInput : 14
adxSmoothInput = input.int(14, "ADX Smoothing", minval=1, maxval=200, group=gLogic, active=advanced, display=display.none)
adxSmooth = advanced ? adxSmoothInput : 14
maxAdxInput = input.float(20.0, "Max ADX For Sideways", minval=0, step=0.5, group=gLogic, active=advanced, display=display.none)
maxAdx = advanced ? maxAdxInput : 20.0
breakBufferAtrInput = input.float(0.08, "Break Buffer x ATR", minval=0, step=0.01, group=gLogic, active=advanced, display=display.none)
breakBufferAtr = advanced ? breakBufferAtrInput : 0.08
displacementAtrInput = input.float(1.10, "Break Displacement x ATR", minval=0.05, step=0.05, group=gLogic, active=advanced, display=display.none)
displacementAtr = advanced ? displacementAtrInput : 1.10
minBuildBarsInput = input.int(8, "Minimum Bars In Zone", minval=4, maxval=100, group=gLogic, active=advanced, display=display.none)
minBuildBars = advanced ? minBuildBarsInput : 8
minDistanceAtrInput = input.float(2.50, "Minimum Distance From Last Same Zone x ATR", minval=0, step=0.25, group=gLogic, active=advanced, display=display.none)
minDistanceAtr = advanced ? minDistanceAtrInput : 2.50
minBarsBetweenInput = input.int(20, "Minimum Bars Between Same Zone Type", minval=1, maxval=300, group=gLogic, active=advanced, display=display.none)
minBarsBetween = advanced ? minBarsBetweenInput : 20
string gColours = "5. Optional timeframe colours"
customColours = input.bool(false, "Use separate colours for each timeframe", group=gColours,
tooltip="Off uses the two colours in Quick setup. Source timeframe names remain visible inside every zone.")
dM1Input = input.color(color.lime, "1m demand", group=gColours, inline="M1", active=customColours)
sM1Input = input.color(color.red, "Supply", group=gColours, inline="M1", active=customColours)
color dM1 = customColours ? dM1Input : demandColor
color sM1 = customColours ? sM1Input : supplyColor
dM5Input = input.color(color.teal, "5m demand", group=gColours, inline="M5", active=customColours)
sM5Input = input.color(color.orange, "Supply", group=gColours, inline="M5", active=customColours)
color dM5 = customColours ? dM5Input : demandColor
color sM5 = customColours ? sM5Input : supplyColor
dM15Input = input.color(color.blue, "15m demand", group=gColours, inline="M15", active=customColours)
sM15Input = input.color(color.fuchsia, "Supply", group=gColours, inline="M15", active=customColours)
color dM15 = customColours ? dM15Input : demandColor
color sM15 = customColours ? sM15Input : supplyColor
dM30Input = input.color(color.aqua, "30m demand", group=gColours, inline="M30", active=customColours)
sM30Input = input.color(color.rgb(255, 110, 70), "Supply", group=gColours, inline="M30", active=customColours)
color dM30 = customColours ? dM30Input : demandColor
color sM30 = customColours ? sM30Input : supplyColor
dH1Input = input.color(color.lime, "1H demand", group=gColours, inline="H1", active=customColours)
sH1Input = input.color(color.red, "Supply", group=gColours, inline="H1", active=customColours)
color dH1 = customColours ? dH1Input : demandColor
color sH1 = customColours ? sH1Input : supplyColor
dH4Input = input.color(color.teal, "4H demand", group=gColours, inline="H4", active=customColours)
sH4Input = input.color(color.orange, "Supply", group=gColours, inline="H4", active=customColours)
color dH4 = customColours ? dH4Input : demandColor
color sH4 = customColours ? sH4Input : supplyColor
dDInput = input.color(color.blue, "Daily demand", group=gColours, inline="D", active=customColours)
sDInput = input.color(color.fuchsia, "Supply", group=gColours, inline="D", active=customColours)
color dD = customColours ? dDInput : demandColor
color sD = customColours ? sDInput : supplyColor
type Sample
int t
int tc
int idx
float o
float h
float l
float c
float prevH
float prevL
float atr
float adx
float standardH
float standardL
float microH
float microL
int standardStart
int microStart
// Zone records are immutable after insertion, so array.copy freezes membership.
type Zone
float top
float bot
int born
int leftTime
int rightTime
string strength
type Engine
array<Zone> demand
array<Zone> supply
int lastTime = na
float top = na
float bot = na
int startBar = na
int startTime = na
int pendingEnd = na
bool micro = false
string status = "Waiting for data"
float lastAdx = na
int dTime = 0
int sTime = 0
int drTime = 0
int srTime = 0
float dPrice = na
float sPrice = na
float drPrice = na
float srPrice = na
type Frame
array<Zone> demand
array<Zone> supply
float pendingTop
float pendingBot
int pendingStart
int pendingEnd
string status
float adx
int tc
int dTime
int sTime
int drTime
int srTime
float dPrice
float sPrice
float drPrice
float srPrice
int dCount
int sCount
type Layer
string tf
string tag
int seconds
bool enabled
color dc
color sc
Frame frame = na
int lastClose = na
f_sample() =>
float sh = sourceMode == "Bodies" ? math.max(open, close) : high
float sl = sourceMode == "Bodies" ? math.min(open, close) : low
float a = ta.atr(atrLen)
[pdi, mdi, adxValue] = ta.dmi(diLen, adxSmooth)
float standardH = ta.highest(sh, zoneLen)
float standardL = ta.lowest(sl, zoneLen)
float microH = ta.highest(sh, microLen)
float microL = ta.lowest(sl, microLen)
Sample.new(time, time_close, bar_index, open, high, low, close, high[1], low[1], a, adxValue, standardH, standardL, microH, microL, time[zoneLen - 1], time[microLen - 1])
f_remove(array<Zone> zones, int i) =>
array.remove(zones, i)
f_invalidate(array<Zone> zones, float sourceClose, bool demand) =>
int i = array.size(zones) - 1
while i >= 0
Zone z = array.get(zones, i)
if demand ? sourceClose < z.bot : sourceClose > z.top
f_remove(zones, i)
i -= 1
f_removeOverlap(array<Zone> zones, float top, float bot) =>
int i = array.size(zones) - 1
while i >= 0
Zone z = array.get(zones, i)
if bot <= z.top and top >= z.bot
f_remove(zones, i)
i -= 1
f_allowed(array<Zone> zones, float mid, float atr, int sourceBar) =>
bool allowed = true
if array.size(zones) > 0
Zone last = array.last(zones)
allowed := math.abs(mid - (last.top + last.bot) / 2.0) >= atr * minDistanceAtr and sourceBar - last.born >= minBarsBetween
allowed
f_addZone(Engine e, Sample b, bool demand, string strength) =>
array<Zone> own = demand ? e.demand : e.supply
array.push(own, Zone.new(e.top, e.bot, b.idx, e.startTime, b.tc, strength))
if array.size(own) > (demand ? maxDemandZones : maxSupplyZones)
f_remove(own, 0)
if demand
e.dTime := b.tc
e.dPrice := e.bot
else
e.sTime := b.tc
e.sPrice := e.top
true
f_process(Engine e, Sample b) =>
if not na(b)
if not na(b.tc) and (na(e.lastTime) or b.t > e.lastTime)
e.lastTime := b.t
e.lastAdx := b.adx
// Only a confirmed candle from this engine can invalidate its zones.
f_invalidate(e.demand, b.c, true)
f_invalidate(e.supply, b.c, false)
bool ready = not na(b.atr) and b.atr > 0 and not na(b.adx)
bool standard = ready and b.adx <= maxAdx and b.standardH - b.standardL <= b.atr * rangeAtrMult and not na(b.standardStart)
bool micro = ready and not standard and enableMicro and b.adx <= maxAdx and b.microH - b.microL <= b.atr * microRangeAtrMult and not na(b.microStart)
bool sideways = standard or micro
// Original ordering: expand the base while sideways, then test break.
if sideways
if na(e.top)
e.top := standard ? b.standardH : b.microH
e.bot := standard ? b.standardL : b.microL
e.startBar := b.idx - (standard ? zoneLen : microLen) + 1
e.startTime := standard ? b.standardStart : b.microStart
e.micro := micro
else
e.top := math.max(e.top, sourceMode == "Bodies" ? math.max(b.o, b.c) : b.h)
e.bot := math.min(e.bot, sourceMode == "Bodies" ? math.min(b.o, b.c) : b.l)
e.pendingEnd := b.tc
bool pending = not na(e.top)
float candleRange = b.h - b.l
bool displacement = ready and (math.abs(b.c - b.o) >= b.atr * displacementAtr or candleRange >= b.atr * displacementAtr)
bool up = pending and displacement and b.c > e.top + b.atr * breakBufferAtr
bool down = pending and displacement and b.c < e.bot - b.atr * breakBufferAtr
if up or down
int zoneBars = b.idx - e.startBar + 1
float allowedRange = b.atr * (e.micro ? microRangeAtrMult : rangeAtrMult)
float mid = (e.top + e.bot) / 2.0
bool valid = zoneBars >= minBuildBars and e.top - e.bot <= allowedRange
array<Zone> own = up ? e.demand : e.supply
if valid and f_allowed(own, mid, b.atr, b.idx)
int score = (zoneBars >= minBuildBars + 4 ? 1 : 0) + (zoneBars >= minBuildBars + 10 ? 1 : 0)
score += (candleRange >= b.atr * displacementAtr * 1.25 ? 1 : 0) + (candleRange >= b.atr * displacementAtr * 1.75 ? 1 : 0)
string strength = score >= 3 ? "STRONG" : score >= 2 ? "NORMAL" : "WEAK"
// Opposite overlaps are removed only inside this timeframe.
f_removeOverlap(up ? e.supply : e.demand, e.top, e.bot)
f_addZone(e, b, up, strength)
e.pendingEnd := na
e.top := na
e.bot := na
e.startBar := na
e.startTime := na
e.micro := false
// Same clean-retest rules as the original, measured in source bars.
if showRetest and array.size(e.demand) > 0
Zone last = array.last(e.demand)
if b.idx - last.born > 5 and b.l <= last.top and b.c > last.top and b.c > b.o and b.prevL > last.top
e.drTime := b.tc
e.drPrice := b.l
if showRetest and array.size(e.supply) > 0
Zone last = array.last(e.supply)
if b.idx - last.born > 5 and b.h >= last.bot and b.c < last.bot and b.c < b.o and b.prevH < last.bot
e.srTime := b.tc
e.srPrice := b.h
e.status := not ready ? "Warming up" : not na(e.top) ? (sideways ? (e.micro ? "Building micro" : "Building standard") : "Waiting break") : "Scanning"
// This state lives INSIDE the requested timeframe and runs on every source bar.
// Keeping only the latest chart sample would miss older active HTF zones.
f_frame() =>
Sample b = f_sample()
var Engine e = Engine.new(array.new<Zone>(), array.new<Zone>())
f_process(e, b)
array<Zone> d = na
array<Zone> s = na
// Keep recent source snapshots for confirmed-bar requests.
// The calculation above still runs over the complete requested history.
if bar_index >= last_bar_index - 2
d := array.copy(e.demand)
s := array.copy(e.supply)
Frame.new(d, s, e.top, e.bot, e.startTime, e.pendingEnd, e.status, e.lastAdx, time_close,
e.dTime, e.sTime, e.drTime, e.srTime, e.dPrice, e.sPrice, e.drPrice, e.srPrice,
array.size(e.demand), array.size(e.supply))
f_previousFrame() =>
Frame f = f_frame()
f[1]
var array<Layer> layers = array.from(
Layer.new("1D", "Daily", 86400, useD, dD, sD),
Layer.new("240", "4H", 14400, useH4, dH4, sH4),
Layer.new("60", "1H", 3600, useH1, dH1, sH1),
Layer.new("30", "30m", 1800, useM30, dM30, sM30),
Layer.new("15", "15m", 900, useM15, dM15, sM15),
Layer.new("5", "5m", 300, useM5, dM5, sM5),
Layer.new("1", "1m", 60, useM1, dM1, sM1))
var array<label> markers = array.new<label>()
array<bool> signals = array.new<bool>(4, false)
f_marker(int stamp, float price, string txt, color col, bool isUp, bool retest) =>
label id = label.new(x=stamp, y=price, text=txt, xloc=xloc.bar_time,
style=retest ? (isUp ? label.style_triangleup : label.style_triangledown) : (isUp ? label.style_label_up : label.style_label_down),
color=col, textcolor=col, size=size.tiny)
if not retest
label.set_textcolor(id, color.white)
array.push(markers, id)
if array.size(markers) > 190
label.delete(array.shift(markers))
f_events(Layer layer, Frame f) =>
if not na(layer.lastClose) and f.tc > layer.lastClose
array<int> stamps = array.from(f.dTime, f.sTime, f.drTime, f.srTime)
array<float> prices = array.from(f.dPrice, f.sPrice, f.drPrice, f.srPrice)
for i = 0 to 3
int stamp = array.get(stamps, i)
if stamp > layer.lastClose and stamp <= f.tc
array.set(signals, i, true)
bool retest = i >= 2
bool demand = i == 0 or i == 2
if not retest and showLabels
string txt = layer.tag + (retest ? (demand ? " DZ" : " SZ") : (demand ? " DEMAND" : " SUPPLY"))
f_marker(stamp, array.get(prices, i), txt, demand ? layer.dc : layer.sc, demand, retest)
layer.lastClose := f.tc
// Ordinary time-based candles only. All selected source TFs can be displayed
// on standard minute/hour/day charts or other standard time-based charts when data exists.
if barstate.isfirst and (not chart.is_standard or timeframe.isticks)
runtime.error("Use standard time-based candles. Start with a 5m chart for the Intraday preset.")
float chartSeconds = timeframe.in_seconds()
Frame chartFrame = f_frame()
// Static call sites keep source-history evaluation outside any shared loop.
// A lower-TF snapshot contains its complete zone lifecycle, not just the signal
// from its sampled candle. Thus intermediate invalidations are retained too.
f_load(simple string tf, simple int sourceSeconds, bool enabled) =>
Frame result = na
if enabled
if sourceSeconds == chartSeconds
result := barstate.isconfirmed ? chartFrame : chartFrame[1]
else if sourceSeconds > chartSeconds
result := request.security(syminfo.tickerid, tf, f_previousFrame(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_on, calc_bars_count=historyBars)
else
result := request.security(syminfo.tickerid, tf, f_previousFrame(), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off, calc_bars_count=historyBars)
result
f_apply(Layer layer, Frame f) =>
if not na(f)
f_events(layer, f)
layer.frame := f
true
f_apply(array.get(layers, 0), f_load("1D", 86400, useD))
f_apply(array.get(layers, 1), f_load("240", 14400, useH4))
f_apply(array.get(layers, 2), f_load("60", 3600, useH1))
f_apply(array.get(layers, 3), f_load("30", 1800, useM30))
f_apply(array.get(layers, 4), f_load("15", 900, useM15))
f_apply(array.get(layers, 5), f_load("5", 300, useM5))
f_apply(array.get(layers, 6), f_load("1", 60, useM1))
var array<box> drawings = array.new<box>()
f_drawZones(array<Zone> zones, Layer layer, bool demand) =>
if not na(zones)
color col = demand ? layer.dc : layer.sc
for z in zones
int opacity = z.strength == "STRONG" ? 82 : z.strength == "NORMAL" ? 88 : 93
string txt = layer.tag + (demand ? " DEMAND" : " SUPPLY") + (showStrength ? " | " + z.strength : "")
box id = box.new(left=z.leftTime, top=z.top, right=z.rightTime, bottom=z.bot, xloc=xloc.bar_time,
bgcolor=color.new(col, opacity), border_color=col, border_width=layer.seconds >= 3600 ? 3 : layer.seconds >= 60 ? 2 : 1,
extend=extendZones ? extend.right : extend.none, text=txt, text_color=color.white,
text_size=size.tiny, text_halign=text.align_right)
array.push(drawings, id)
// Draw only active zones at the chart's latest bar. This also avoids replaying
// repeated historical box creation while retaining the latest active-zone map.
if barstate.islast
for id in drawings
box.delete(id)
array.clear(drawings)
for layer in layers
if layer.enabled and not na(layer.frame)
Frame f = layer.frame
f_drawZones(f.demand, layer, true)
f_drawZones(f.supply, layer, false)
if showPending and not na(f.pendingTop)
box id = box.new(left=f.pendingStart, top=f.pendingTop, right=f.pendingEnd, bottom=f.pendingBot, xloc=xloc.bar_time,
bgcolor=color.new(color.gray, 92), border_color=color.new(color.yellow, 30),
text=layer.tag + " PENDING", text_color=color.yellow, text_size=size.tiny)
array.push(drawings, id)
bool newDemand = array.get(signals, 0)
bool newSupply = array.get(signals, 1)
bool demandRetest = array.get(signals, 2)
bool supplyRetest = array.get(signals, 3)
// Events are aggregated per chart candle; only the last marker of each event
// type/source is displayed within it. Use Once Per Bar Close for settled alerts.
alertcondition(newDemand, "New Demand Zone", "GM S&D MTF: New Demand zone on an enabled timeframe.")
alertcondition(newSupply, "New Supply Zone", "GM S&D MTF: New Supply zone on an enabled timeframe.")
alertcondition(demandRetest, "Demand Retest", "GM S&D MTF: Clean Demand retest on an enabled timeframe.")
alertcondition(supplyRetest, "Supply Retest", "GM S&D MTF: Clean Supply retest on an enabled timeframe.")
alertcondition(newDemand or newSupply or demandRetest or supplyRetest, "GM Zones Phone Alert", "GM S&D MTF: New zone or clean retest on an enabled timeframe.")
var table dash = table.new(position.top_right, 5, 9, border_width=1, bgcolor=color.new(color.black, 15))
if showDashboard and barstate.islast
table.cell(dash, 0, 0, "GM S&D", text_color=color.white, text_size=size.tiny)
table.cell(dash, 1, 0, "Demand", text_color=color.white, text_size=size.tiny)
table.cell(dash, 2, 0, "Supply", text_color=color.white, text_size=size.tiny)
table.cell(dash, 3, 0, "ADX", text_color=color.white, text_size=size.tiny)
table.cell(dash, 4, 0, "Source status", text_color=color.white, text_size=size.tiny)
for i = 0 to array.size(layers) - 1
Layer layer = array.get(layers, i)
Frame f = layer.frame
bool available = layer.enabled and not na(f)
string status = not layer.enabled ? "OFF" : not available ? "Waiting for data" : f.status
if available and (na(f.demand) or na(f.supply))
status := "Waiting for snapshot"
if layer.enabled and layer.seconds < chartSeconds
status += " | lower TF: delayed"
table.cell(dash, 0, i + 1, layer.tag, text_color=layer.enabled ? color.white : color.gray, text_size=size.tiny)
table.cell(dash, 1, i + 1, available ? str.tostring(f.dCount) : "-", text_color=layer.dc, text_size=size.tiny)
table.cell(dash, 2, i + 1, available ? str.tostring(f.sCount) : "-", text_color=layer.sc, text_size=size.tiny)
table.cell(dash, 3, i + 1, available ? str.tostring(f.adx, "#.0") : "-", text_color=color.silver, text_size=size.tiny)
table.cell(dash, 4, i + 1, status, text_color=layer.enabled ? color.silver : color.gray, text_size=size.tiny)
table.cell(dash, 0, 8, "Closed bars", text_color=color.silver, text_size=size.tiny)
table.cell(dash, 1, 8, "History / TF", text_color=color.silver, text_size=size.tiny)
table.cell(dash, 2, 8, str.tostring(historyBars), text_color=color.silver, text_size=size.tiny)
table.cell(dash, 4, 8, "Available source data only", text_color=color.silver, text_size=size.tiny)
// Help uses only current source status. It never fabricates a zone or lowers a filter.
f_help(int selectedCount, int receivedCount, int snapshotCount, int warmingCount, int visibleCount) =>
selectedCount == 0 ? "Choose a preset, or enable a Custom timeframe." : receivedCount == 0 ? "Waiting for source data. Try Intraday on a standard 5m chart." : snapshotCount < selectedCount ? "Waiting for confirmed source data. Open the status table for details." : warmingCount > 0 ? "Loading enough candles for the zone calculations." : visibleCount == 0 ? "No active zones match the rules in loaded history. Open the status table for details." : ""
var table helpTable = table.new(position.bottom_right, 1, 1, border_width=0)
if barstate.islast
table.clear(helpTable, 0, 0, 0, 0)
int selectedCount = 0
int receivedCount = 0
int snapshotCount = 0
int warmingCount = 0
for layer in layers
if layer.enabled
selectedCount += 1
if not na(layer.frame)
receivedCount += 1
Frame f = layer.frame
if not na(f.demand) and not na(f.supply)
snapshotCount += 1
if f.status == "Warming up"
warmingCount += 1
string helpText = f_help(selectedCount, receivedCount, snapshotCount, warmingCount, array.size(drawings))
if showHelp and array.size(drawings) == 0 and helpText != ""
table.cell(helpTable, 0, 0, helpText, text_color=chart.fg_color, bgcolor=color.new(chart.bg_color, 10), text_size=size.small)