Impulse Move S/R Zones

CBeamsGlitter · study · 501 行 · 点赞 43 · TradingView 原页

本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。

Pine Script

//@version=6
// Historical Supply/Demand Zones (12M)
// Finds prices where this instrument repeatedly FAILED over ~12 months of daily bars
// and draws the surviving zones on any intraday chart — reference levels for large
// intraday moves, where today's / yesterday's / this week's extremes go irrelevant.
//
// ARCHITECTURE: detection, clustering and scoring run inside the daily request.security()
// context; only the finished zone set (<= 48) crosses the boundary. Returning raw pivots
// instead blows Pine's memory limit (RE10139). Band filtering and bucketing happen on the
// CHART side so they use live price — see v2.6.
//
// v2.4: lookback was multiplying a TRADING-bar count by calendar ms (window ~30% short);
//       absolute crossings cap replaced by an exposure-normalised rate penalty, because
//       touch count and crossing count are positively correlated and a hard cap deleted
//       precisely the well-evidenced zones this tool exists to find.
// v2.5: all daily-context state gated on confirmed bars — tolerance no longer drifts as
//       today's range expands, TAIL no longer flickers.
// v2.6: band filter + bucketing moved to the chart context. They previously used the daily
//       series' close, which in pre-market is YESTERDAY'S close — so the whole window sat
//       in the wrong place during exactly the hours a pre-market report is built. Band can
//       now also be expressed in ATR multiples: a fixed percentage means wildly different
//       things across instruments (NVDA ATR ~3.5% of price, AMD ~8.9%, where +/-6% is less
//       than one average day's range and the tool goes blind).
indicator("Impulse Move S/R Zones", "IM S/R", overlay = true, max_boxes_count = 60, max_labels_count = 60, max_bars_back = 500)
 
// ══════════════════════════════ INPUTS ══════════════════════════════
gD = "Detection"
inSym = input.symbol("", "Detection symbol (blank = chart)", group = gD, tooltip = "Micros lack 12M history. MES -> CME_MINI:ES1!, MNQ -> CME_MINI:NQ1!, MCL -> NYMEX:CL1!. NOTE: a B-ADJ (back-adjusted) chart puts historical zones at back-adjusted prices, not where they traded.")
inLB  = input.int(252, "Lookback (trading days)", minval = 40, maxval = 300, group = gD)
inPiv = input.int(3, "Pivot left/right", minval = 1, maxval = 10, group = gD)
inFwd = input.int(10, "Reaction window (bars)", minval = 3, maxval = 30, group = gD)
inRTH = input.bool(true, "RTH-only detection", group = gD, tooltip = "On for MES/MNQ and equities. OFF for MCL — overnight crude is real price discovery.")
 
gG = "Gap edges"
inGap    = input.bool(true, "Include gap edges", group = gG, tooltip = "For equities: pivots are structurally blind inside a gap, but earnings-gap edges are durable levels. Futures rarely produce any.")
inGapMin = input.float(0.5, "Min gap size (x ATR)", minval = 0.1, step = 0.1, group = gG)
 
gC = "Clustering & scoring"
inTol  = input.float(0.15, "Cluster tolerance (x ATR)", minval = 0.02, maxval = 1.0, step = 0.01, group = gC, tooltip = "ATR-relative so one setting ports across instruments. Calibrated on ES (ATR 1.6% of price) and NVDA (4.0%).")
inHL   = input.float(180, "Decay half-life (days)", minval = 10, group = gC)
inRate = input.float(15.0, "Max crossings per 100 bars", minval = 1.0, maxval = 100.0, step = 0.5, group = gC, tooltip = "Exposure-normalised, so an old zone is not punished for having had more time to be crossed. Generous by design — rejects pathological chop only; ordinary chop is demoted by the score penalty instead.")
 
gB = "Cross-symbol basis"
inBasis  = input.string("Auto", "Basis translation", options = ["Auto", "Off", "Manual"], group = gB, tooltip = "Needed when the detection symbol differs from the chart symbol. Index futures continuous contracts (ES1!, NQ1!) are BACK-ADJUSTED: historical prices are shifted by the cumulative roll gaps, ~20 points per month on ES, so a 12-month-old zone lands ~250 points from where it actually traded. Detect on the cash index (SP:SPX for MES, NASDAQ:NDX for MNQ) instead and let this shift the zones into futures terms. Auto = difference of the two symbols' last confirmed daily closes. Exactly zero when the symbols match.")
inBasisM = input.float(0.0, "   Manual basis (chart minus detection)", step = 0.25, group = gB)
 
gV = "Display"
inPer   = input.int(3, "Zones per bucket", minval = 1, maxval = 8, group = gV)
inBMode = input.string("ATR", "Band mode", options = ["ATR", "Percent"], group = gV, tooltip = "ATR is the safer default: a fixed percentage is a different amount of room on every instrument. On a name whose ATR is ~9% of price, +/-6% is under one average day's range and almost nothing qualifies.")
inBAtr  = input.float(2.0, "   Band, ATR mode (+/- ATR)", minval = 0.5, maxval = 12.0, step = 0.5, group = gV, tooltip = "2.0 covers roughly one very large session in either direction. On a high-ATR name 3.0 is already +/-25% and starts dragging in irrelevant structure.")
inBPct  = input.float(6.0, "   Band, Percent mode (+/- %)", minval = 1.0, maxval = 40.0, step = 0.5, group = gV)
inProx  = input.float(1.0, "Proximity weight", minval = 0.0, maxval = 4.0, step = 0.25, group = gV, tooltip = "Divides score by (1 + weight x distance-in-ATR) for ranking only. Without it a well-evidenced zone 1.5 ATR away outranks a decent one you are standing on — wrong priority for a tool meant to be read during a fast move. 0 disables.")
inBack  = input.int(300, "Box left extent (bars)", minval = 50, maxval = 450, group = gV)
inTbl   = input.bool(true, "Show level table", group = gV)
inTxt   = input.string("Small", "Text size", options = ["Tiny", "Small", "Medium", "Large"], group = gV)
inTheme = input.string("Auto", "Text contrast", options = ["Auto", "Force light text", "Force dark text"], group = gV, tooltip = "Auto reads the chart background and picks contrasting text, so the table stays readable on a white theme. Override only if a custom theme fools the luminance test.")
cSup    = input.color(color.new(color.teal,   82), "Support", group = gV)
cRes    = input.color(color.new(color.red,    82), "Resistance", group = gV)
cCon    = input.color(color.new(color.orange, 82), "Containing spot", group = gV)
 
txtSz = inTxt == "Tiny" ? size.tiny : inTxt == "Small" ? size.small : inTxt == "Medium" ? size.normal : size.large
 
// ══════════════════════════ THEME-AWARE COLOURS ══════════════════════════
// Everything here was hardcoded white, which disappears on a light chart.
// chart.bg_color / chart.fg_color track the user's theme; the luminance helper
// is still needed for the tag colours and for label text, which sits on the
// zone's own colour rather than on the chart background.
f_lum(color c) => 0.299 * color.r(c) + 0.587 * color.g(c) + 0.114 * color.b(c)
f_on(color c)  => f_lum(c) > 140 ? color.black : color.white
 
lightBg = inTheme == "Auto" ? f_lum(chart.bg_color) > 128 : inTheme == "Force dark text"
tTxt    = inTheme == "Auto" ? chart.fg_color : (lightBg ? color.black : color.white)
tDim    = color.new(tTxt, 45)
tHdrBg  = lightBg ? color.new(color.gray, 65) : color.new(color.gray, 30)
// saturated red/orange/teal wash out badly on white, so darken them there
tRes    = lightBg ? #B00020 : color.red
tAt     = lightBg ? #A85400 : color.orange
tSup    = lightBg ? #00695C : color.teal
 
// Anchors the study to the chart's price scale. A study that plots no series gets its
// own scale, which decouples box/label prices from the candles entirely.
plot(close, "scale anchor", color = color.new(color.white, 100), display = display.none, editable = false)
 
// ══════════════════════════ HELPERS (global scope) ══════════════════════════
f_rankBy(array<int> bk, array<float> sc) =>
    out = array.new_int()
    tmp = array.copy(bk)
    while array.size(tmp) > 0
        bi = 0
        bs = -1e18
        for q = 0 to array.size(tmp) - 1
            v = array.get(sc, array.get(tmp, q))
            if v > bs
                bs := v
                bi := q
        array.push(out, array.get(tmp, bi))
        array.remove(tmp, bi)
    out
 
// ══════════════════ DETECTION + CLUSTERING (daily context) ══════════════════
f_zones(simple int L, simple int R, simple int fwd, simple bool useGap, simple float gapMin, simple int lb, simple float tolA, simple float hl, simple float maxRate) =>
    var array<float> aP  = array.new_float()
    var array<int>   aT  = array.new_int()
    var array<float> aR  = array.new_float()
    var array<int>   aK  = array.new_int()
    var array<int>   aDT = array.new_int()
    var array<float> aDC = array.new_float()
    var array<float> oLo = array.new_float()
    var array<float> oHi = array.new_float()
    var array<int>   oN  = array.new_int()
    var array<int>   oXs = array.new_int()
    var array<int>   oTl = array.new_int()
    var array<int>   oGp = array.new_int()
    var array<float> oRt = array.new_float()
    var array<float> oSc = array.new_float()
    var float atrC = na
    var float clsC = na      // detection symbol's last CONFIRMED daily close
 
    atrD = ta.atr(14)
    loF  = ta.lowest(low, fwd)
    hiF  = ta.highest(high, fwd)
    phc  = ta.pivothigh(L, R)
    plc  = ta.pivotlow(L, R)
 
    // Everything that mutates state is gated on a closed bar. Without this the forming
    // daily bar feeds the arrays on every realtime tick: tolerance drifts as today's
    // range expands (merging clusters mid-session) and TAIL flickers between 0 and its
    // real value as price oscillates around a zone mid.
    isConf = barstate.isconfirmed
    if isConf
        atrC := atrD
        clsC := close
        array.push(aDT, time)
        array.push(aDC, close)
        if array.size(aDT) > lb + 30
            array.shift(aDT)
            array.shift(aDC)
 
    off = R + fwd
    av  = na(atrD[off]) ? atrD : atrD[off]
 
    if isConf and bar_index > off + 20 and not na(av) and av > 0
        if not na(phc[fwd])
            pv = high[off]
            array.push(aP, pv)
            array.push(aT, time[off])
            array.push(aR, (pv - loF[R]) / av)
            array.push(aK, 1)
        if not na(plc[fwd])
            pw = low[off]
            array.push(aP, pw)
            array.push(aT, time[off])
            array.push(aR, (hiF[R] - pw) / av)
            array.push(aK, 0)
 
    if isConf and useGap and bar_index > 1 and not na(atrD) and atrD > 0
        gUp = low - high[1]
        gDn = low[1] - high
        if gUp > gapMin * atrD
            array.push(aP, high[1])
            array.push(aT, time[1])
            array.push(aR, gUp / atrD)
            array.push(aK, 2)
            array.push(aP, low)
            array.push(aT, time)
            array.push(aR, gUp / atrD)
            array.push(aK, 2)
        if gDn > gapMin * atrD
            array.push(aP, low[1])
            array.push(aT, time[1])
            array.push(aR, gDn / atrD)
            array.push(aK, 2)
            array.push(aP, high)
            array.push(aT, time)
            array.push(aR, gDn / atrD)
            array.push(aK, 2)
 
    if isConf and array.size(aP) > 500
        array.shift(aP)
        array.shift(aT)
        array.shift(aR)
        array.shift(aK)
 
    if barstate.islast and array.size(aP) > 0 and array.size(aDT) > 30 and not na(atrC) and atrC > 0
        array.clear(oLo)
        array.clear(oHi)
        array.clear(oN)
        array.clear(oXs)
        array.clear(oTl)
        array.clear(oGp)
        array.clear(oRt)
        array.clear(oSc)
 
        nD = array.size(aDT)
        // window boundary taken from the daily array itself — multiplying a TRADING-bar
        // count by calendar milliseconds made the window ~30% shorter than advertised
        tCut  = array.get(aDT, math.max(0, nD - 1 - lb))
        tLast = array.get(aDT, nD - 1)
        tol   = tolA * atrC
 
        fP = array.new_float()
        fT = array.new_int()
        fK = array.new_int()
        fW = array.new_float()
        for i = 0 to array.size(aP) - 1
            tt = array.get(aT, i)
            if tt >= tCut
                ageD = (tLast - tt) / 86400000.0
                array.push(fP, array.get(aP, i))
                array.push(fT, tt)
                array.push(fK, array.get(aK, i))
                array.push(fW, math.pow(0.5, ageD / hl) * math.min(array.get(aR, i), 4.0))
 
        nF = array.size(fW)
        if nF > 0
            zLo = array.new_float()
            zHi = array.new_float()
            zSc = array.new_float()
            zN  = array.new_int()
            zTl = array.new_int()
            zXs = array.new_int()
            zGp = array.new_int()
            zRt = array.new_float()
 
            // SEED clustering — strongest pivot seeds a zone and absorbs only pivots
            // within +/-tol OF THE SEED. Single-linkage daisy-chains a whole quarter
            // into one blob; this cannot, width caps at 2*tol.
            ord  = array.sort_indices(fW, order.descending)
            used = array.new_bool(nF, false)
 
            for oi = 0 to nF - 1
                si = array.get(ord, oi)
                if not array.get(used, si)
                    seed = array.get(fP, si)
                    array.set(used, si, true)
                    mLo = seed
                    mHi = seed
                    mSc = array.get(fW, si)
                    mN  = 1
                    mFt = array.get(fT, si)
                    mGp = array.get(fK, si) == 2 ? 1 : 0
                    for j = 0 to nF - 1
                        if not array.get(used, j) and math.abs(array.get(fP, j) - seed) <= tol
                            array.set(used, j, true)
                            pj = array.get(fP, j)
                            mLo := math.min(mLo, pj)
                            mHi := math.max(mHi, pj)
                            mSc += array.get(fW, j)
                            mN  += 1
                            mFt := math.min(mFt, array.get(fT, j))
                            if array.get(fK, j) == 2
                                mGp := 1
 
                    md = (mLo + mHi) / 2.0
                    xs = 0
                    lastX = -1
                    fidx = nD - 1
                    for k = 1 to nD - 1
                        if array.get(aDT, k) >= mFt and k < fidx
                            fidx := k
                        if array.get(aDT, k) > mFt
                            if (array.get(aDC, k - 1) - md) * (array.get(aDC, k) - md) < 0
                                xs += 1
                                lastX := k
                    tl   = lastX >= 0 ? nD - 1 - lastX : -1
                    expo = math.max(1, (nD - 1) - fidx)
                    rate = xs / expo * 100.0
 
                    if rate <= maxRate
                        array.push(zLo, mLo)
                        array.push(zHi, mHi)
                        array.push(zSc, mSc / (1.0 + rate * 0.25))
                        array.push(zN,  mN)
                        array.push(zTl, tl)
                        array.push(zXs, xs)
                        array.push(zGp, mGp)
                        array.push(zRt, rate)
 
            // Emit the whole zone set, best-scoring first, UNFILTERED by band and
            // UNBUCKETED. Both of those depend on current price, and the daily series'
            // close is stale in pre-market — so they belong on the chart side.
            nZ = array.size(zLo)
            if nZ > 0
                srt = array.sort_indices(zSc, order.descending)
                lim = math.min(nZ, 48)
                for q = 0 to lim - 1
                    i = array.get(srt, q)
                    array.push(oLo, array.get(zLo, i))
                    array.push(oHi, array.get(zHi, i))
                    array.push(oN,  array.get(zN,  i))
                    array.push(oXs, array.get(zXs, i))
                    array.push(oTl, array.get(zTl, i))
                    array.push(oGp, array.get(zGp, i))
                    array.push(oRt, array.get(zRt, i))
                    array.push(oSc, array.get(zSc, i))
 
    [oLo, oHi, oN, oXs, oTl, oGp, oRt, oSc, atrC, clsC]
 
// last confirmed daily close of whatever symbol it is called against — used on both
// sides of the basis so the two readings are taken at the same moment. Live prices
// would fold the overnight move into the basis and shift every zone by it.
f_confClose() =>
    var float v = na
    if barstate.isconfirmed
        v := close
    v
 
base = inSym == "" ? syminfo.tickerid : inSym
tkr  = inRTH ? ticker.modify(base, session = session.regular) : ticker.modify(base, session = session.extended)
// same session modification on the chart symbol, so a blank detection symbol gives
// an exactly-zero basis rather than an RTH-vs-ETH close difference
cTkr = inRTH ? ticker.modify(syminfo.tickerid, session = session.regular) : ticker.modify(syminfo.tickerid, session = session.extended)
 
[qLo, qHi, qN, qXs, qTl, qGp, qRt, qSc, dATR, dCls] = request.security(tkr, "D", f_zones(inPiv, inPiv, inFwd, inGap, inGapMin, inLB, inTol, inHL, inRate), lookahead = barmerge.lookahead_off)
cCls = request.security(cTkr, "D", f_confClose(), lookahead = barmerge.lookahead_off)
 
// ══════════════════════════ RENDER (chart context) ══════════════════════════
// spot is the CHART's live price, so pre-market and intraday moves re-centre the band
// and re-bucket the zones correctly.
var array<box>   bxs = array.new<box>()
var array<label> lbs = array.new<label>()
var table tbl = na
 
// Deliberately NOT gated on array.size(qLo) > 0 — a symbol with no qualifying zones
// at all must still report that, rather than rendering nothing and looking broken.
if barstate.islast and not na(dATR) and dATR > 0
    if array.size(bxs) > 0
        for bb in bxs
            box.delete(bb)
    array.clear(bxs)
    if array.size(lbs) > 0
        for ll in lbs
            label.delete(ll)
    array.clear(lbs)
    if not na(tbl)
        table.delete(tbl)
 
    spot = close
    reach = inBMode == "ATR" ? inBAtr * dATR : spot * inBPct / 100.0
 
    nTot = array.size(qLo)
 
    // ── basis translation ───────────────────────────────────────────────────
    // Zones come back in the DETECTION symbol's price space. Shift them once,
    // here, so every downstream step (banding, bucketing, boxes, table) works in
    // chart price space without each one having to remember to add it.
    bAuto = (na(cCls) or na(dCls)) ? 0.0 : cCls - dCls
    basis = inBasis == "Off" ? 0.0 : inBasis == "Manual" ? inBasisM : bAuto
 
    sLo = array.new_float()
    sHi = array.new_float()
    if nTot > 0
        for i = 0 to nTot - 1
            array.push(sLo, array.get(qLo, i) + basis)
            array.push(sHi, array.get(qHi, i) + basis)
 
    bA = array.new_int()
    bC = array.new_int()
    bB = array.new_int()
    if nTot > 0
        for i = 0 to nTot - 1
            lo = array.get(sLo, i)
            hi = array.get(sHi, i)
            md = (lo + hi) / 2.0
            if math.abs(md - spot) <= reach
                if lo > spot
                    array.push(bA, i)
                else if hi < spot
                    array.push(bB, i)
                else
                    array.push(bC, i)
 
    // Ranking score, proximity-adjusted. Raw score blends reaction magnitude, recency
    // decay and the chop penalty — none of which know how far away the zone is.
    adj = array.new_float()
    if nTot > 0
        for i = 0 to nTot - 1
            md2 = (array.get(sLo, i) + array.get(sHi, i)) / 2.0
            array.push(adj, array.get(qSc, i) / (1.0 + inProx * math.abs(md2 - spot) / dATR))
 
    rA = f_rankBy(bA, adj)
    rC = f_rankBy(bC, adj)
    rB = f_rankBy(bB, adj)
 
    // Nearest zone OUTSIDE the band on each side, used as a fallback so an empty
    // bucket reports "nearest is X, far away" instead of rendering nothing. Silence
    // is indistinguishable from the script being broken.
    nearA = -1
    nearB = -1
    nearAd = 1e18
    nearBd = 1e18
    if nTot > 0
        for i = 0 to nTot - 1
            lo3 = array.get(sLo, i)
            hi3 = array.get(sHi, i)
            md3 = (lo3 + hi3) / 2.0
            d3  = math.abs(md3 - spot)
            if d3 > reach
                if lo3 > spot and d3 < nearAd
                    nearAd := d3
                    nearA  := i
                if hi3 < spot and d3 < nearBd
                    nearBd := d3
                    nearB  := i
 
    // flatten the three ranked buckets into one draw order. An empty RES/SUP bucket
    // falls back to the nearest out-of-band zone (index -1 = none exists at all).
    ord = array.new_int()
    bkt = array.new_int()
    oob = array.new_bool()
    if array.size(rA) > 0
        for q = 0 to math.min(array.size(rA), inPer) - 1
            array.push(ord, array.get(rA, q))
            array.push(bkt, 0)
            array.push(oob, false)
    else
        array.push(ord, nearA)
        array.push(bkt, 0)
        array.push(oob, true)
    if array.size(rC) > 0
        for q = 0 to math.min(array.size(rC), inPer) - 1
            array.push(ord, array.get(rC, q))
            array.push(bkt, 1)
            array.push(oob, false)
    if array.size(rB) > 0
        for q = 0 to math.min(array.size(rB), inPer) - 1
            array.push(ord, array.get(rB, q))
            array.push(bkt, 2)
            array.push(oob, false)
    else
        array.push(ord, nearB)
        array.push(bkt, 2)
        array.push(oob, true)
 
    nShow = array.size(ord)
 
    if inTbl and nShow > 0
        tbl := table.new(position.top_right, 7, nShow + 2, border_width = 1)
        hdr = tHdrBg
        table.cell(tbl, 0, 0, "ZONE",  text_color = tTxt, bgcolor = hdr, text_size = txtSz)
        table.cell(tbl, 1, 0, "LO",    text_color = tTxt, bgcolor = hdr, text_size = txtSz)
        table.cell(tbl, 2, 0, "HI",    text_color = tTxt, bgcolor = hdr, text_size = txtSz)
        table.cell(tbl, 3, 0, "DIST%", text_color = tTxt, bgcolor = hdr, text_size = txtSz)
        table.cell(tbl, 4, 0, "N/X",   text_color = tTxt, bgcolor = hdr, text_size = txtSz)
        table.cell(tbl, 5, 0, "TAIL",  text_color = tTxt, bgcolor = hdr, text_size = txtSz)
        table.cell(tbl, 6, 0, "RATE",  text_color = tTxt, bgcolor = hdr, text_size = txtSz)
 
    if nShow > 0
        for q = 0 to nShow - 1
            i    = array.get(ord, q)
            bk   = array.get(bkt, q)
            far  = array.get(oob, q)
            col  = bk == 0 ? cRes : bk == 1 ? cCon : cSup
            tcol = bk == 0 ? tRes : bk == 1 ? tAt : tSup
            tag  = bk == 0 ? "RES" : bk == 1 ? "AT" : "SUP"
 
            if i < 0
                // nothing exists on this side anywhere in the lookback — usually
                // means price is at a 12-month extreme, which is itself the signal
                if inTbl
                    table.cell(tbl, 0, q + 1, tag, text_color = tcol, text_size = txtSz)
                    table.cell(tbl, 1, q + 1, "—", text_color = tDim, text_size = txtSz)
                    table.cell(tbl, 2, q + 1, "—", text_color = tDim, text_size = txtSz)
                    table.cell(tbl, 3, q + 1, "none in 12M", text_color = tDim, text_size = txtSz)
                    table.cell(tbl, 4, q + 1, "—", text_color = tDim, text_size = txtSz)
                    table.cell(tbl, 5, q + 1, "—", text_color = tDim, text_size = txtSz)
                    table.cell(tbl, 6, q + 1, "—", text_color = tDim, text_size = txtSz)
            else
                lo  = array.get(sLo, i)
                hi  = array.get(sHi, i)
                md  = (lo + hi) / 2.0
                dpc = 100 * (md - spot) / spot
 
                // out-of-band fallbacks are reported in the table only — drawing a box
                // several ATR away would defeat the point of having a band at all
                if not far
                    thin = hi - lo < dATR * 0.03
                    h2 = thin ? md + dATR * 0.015 : hi
                    l2 = thin ? md - dATR * 0.015 : lo
                    bb = box.new(bar_index - inBack, h2, bar_index + 30, l2, border_color = color.new(col, 40), bgcolor = col, xloc = xloc.bar_index)
                    array.push(bxs, bb)
                    txt = tag + "  n=" + str.tostring(array.get(qN, i)) + (array.get(qGp, i) == 1 ? " GAP" : "") + "  x=" + str.tostring(array.get(qXs, i))
                    ll = label.new(bar_index + 30, h2, txt, xloc = xloc.bar_index, style = label.style_label_left, color = color.new(col, 15), textcolor = f_on(col), size = txtSz)
                    array.push(lbs, ll)
 
                if inTbl
                    rtc = far ? tDim : tTxt
                    table.cell(tbl, 0, q + 1, tag + (array.get(qGp, i) == 1 ? "*" : "") + (far ? " »" : ""), text_color = tcol, text_size = txtSz)
                    table.cell(tbl, 1, q + 1, str.tostring(lo, format.mintick), text_color = rtc, text_size = txtSz)
                    table.cell(tbl, 2, q + 1, str.tostring(hi, format.mintick), text_color = rtc, text_size = txtSz)
                    table.cell(tbl, 3, q + 1, (dpc >= 0 ? "+" : "") + str.tostring(dpc, "#.##"), text_color = rtc, text_size = txtSz)
                    table.cell(tbl, 4, q + 1, str.tostring(array.get(qN, i)) + "/" + str.tostring(array.get(qXs, i)), text_color = rtc, text_size = txtSz)
                    table.cell(tbl, 5, q + 1, array.get(qTl, i) < 0 ? "never" : str.tostring(array.get(qTl, i)), text_color = rtc, text_size = txtSz)
                    table.cell(tbl, 6, q + 1, str.tostring(array.get(qRt, i), "#.#"), text_color = rtc, text_size = txtSz)
 
    // Basis footer — the applied shift is invisible otherwise, and a wrong basis
    // silently moves every level. Only shown when it is actually doing something.
    if inTbl and nShow > 0 and basis != 0
        table.cell(tbl, 0, nShow + 1, "BASIS", text_color = tDim, text_size = txtSz)
        table.cell(tbl, 1, nShow + 1, (basis >= 0 ? "+" : "") + str.tostring(basis, format.mintick), text_color = tDim, text_size = txtSz)
        table.cell(tbl, 3, nShow + 1, inBasis, text_color = tDim, text_size = txtSz)

← 返回列表