Range Fan: Future Price Projection

a.b · study · 399 行 · 点赞 18 · TradingView 原页

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

Pine Script

// This Pine Script® code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// a.b 
 
//@version=6
indicator(
     title = "Range Fan: Future Price Projection",
     shorttitle = "Range Fan",
     overlay = true,
     max_bars_back = 300,
     max_lines_count = 20,
     max_labels_count = 30,
     max_polylines_count = 40)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
//  INPUTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
const string G_CORE = "Core Logic"
const string G_DISP = "Display"
const string G_STOP = "Historical Stop Ruler"
const string G_ADV  = "Advanced"
 
// ── Core Logic
int horizon = input.int(20, "Horizon (bars)", minval = 6, maxval = 100, group = G_CORE,
     tooltip = "How many bars ahead the fan reaches. Larger = a wider, longer fan. 20 bars is roughly one trading day on 1h charts and one trading month on daily charts.")
int atrLen = input.int(14, "ATR length (scale)", minval = 2, maxval = 100, group = G_CORE,
     tooltip = "ATR is only used to scale past moves to today's volatility. Higher = smoother scale, slower to react.")
int sampleCap = input.int(1000, "History samples", minval = 100, maxval = 1000, step = 50, group = G_CORE,
     tooltip = "How many completed past windows the fan is built from. More = steadier bands, slower to adapt to a new volatility regime.")
float pCoreIn = input.float(50.0, "Core band (%)", minval = 20.0, maxval = 70.0, step = 5.0, group = G_CORE,
     tooltip = "Inner band: price stayed inside this range in this share of past windows.")
float pWideIn = input.float(80.0, "Wide band (%)", minval = 60.0, maxval = 95.0, step = 5.0, group = G_CORE,
     tooltip = "Main band. Also the target used by the Fan Check. Kept at least 5 points above the core band.")
float pExtIn = input.float(95.0, "Extreme band (%)", minval = 80.0, maxval = 99.0, step = 1.0, group = G_CORE,
     tooltip = "Outer band for rare, stretched moves. Kept above the wide band.")
 
// ── Display
bool showExt = input.bool(true, "Extreme band", group = G_DISP)
bool showGhost = input.bool(true, "Previous fan (reality check)", group = G_DISP,
     tooltip = "Draws the fan from one horizon ago as a faint outline, so you can see how price actually behaved inside it.")
bool showGlow = input.bool(true, "Edge glow", group = G_DISP)
bool showLabels = input.bool(true, "End labels", group = G_DISP)
bool showChip = input.bool(true, "Fan Check chip", group = G_DISP,
     tooltip = "Small panel that reports how often price really stayed inside the bands in recent history.")
string chipPos = input.string("Top right", "Chip position", options = ["Top right", "Top left", "Bottom right", "Bottom left"], group = G_DISP)
string txtSize = input.string("Small", "Text size", options = ["Tiny", "Small", "Normal"], group = G_DISP)
color fanCol = input.color(#3D8BFF, "Fan color", group = G_DISP)
color accCol = input.color(#B16CFF, "Outer band color", group = G_DISP)
 
// ── Historical Stop Ruler
bool stopOn = input.bool(true, "Show historical stop ruler", group = G_STOP,
     tooltip = "Draws the distance beyond which price went against a position in only (100 - survival)% of past windows. A statistical noise distance, not a recommendation.")
string stopSide = input.string("Both", "Sides", options = ["Both", "Long only", "Short only"], group = G_STOP)
float stopPct = input.float(70.0, "Survival (%)", minval = 60.0, maxval = 99.0, step = 1.0, group = G_STOP,
     tooltip = "Higher = stop sits farther away and was reached less often in the past, but risks more per trade.")
float entryIn = input.float(0.0, "Entry price (0 = last close)", minval = 0.0, group = G_STOP,
     tooltip = "Optional. Distances are measured from this price as if past windows had started there.")
color longCol = input.color(#19C2A0, "Long stop color", group = G_STOP)
color shortCol = input.color(#FF6B7A, "Short stop color", group = G_STOP)
 
// ── Advanced
string updMode = input.string("Bar close", "Fan updates", options = ["Bar close", "Every tick"], group = G_ADV,
     tooltip = "Bar close: the fan is anchored on the last closed bar and does not move while a bar is forming. Every tick: anchored on the live price (moves intrabar).")
int span = input.int(300, "Fan Check windows", minval = 50, maxval = 500, step = 50, group = G_ADV,
     tooltip = "How many recent completed windows the Fan Check evaluates.")
int minSamples = input.int(60, "Minimum samples", minval = 30, maxval = 300, group = G_ADV,
     tooltip = "The fan stays hidden until this many completed windows exist.")
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
//  DERIVED CONSTANTS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
int   k3 = horizon
int   k1 = math.max(1, math.round(horizon / 3.0))
int   k2 = math.max(k1 + 1, math.round(horizon * 2.0 / 3.0))
float sx1 = math.sqrt(k1)
float sx2 = math.sqrt(k2)
float sx3 = math.sqrt(k3)
 
float pCore = pCoreIn
float pWide = math.max(pWideIn, pCoreIn + 5.0)
float pExt  = math.min(99.5, math.max(pExtIn, pWide + 1.0))
 
string szTxt = txtSize == "Tiny" ? size.tiny : txtSize == "Normal" ? size.normal : size.small
string chipPosC = chipPos == "Top left" ? position.top_left : chipPos == "Bottom right" ? position.bottom_right : chipPos == "Bottom left" ? position.bottom_left : position.top_right
 
color cChipBg = color.new(#0E1424, 6)
color cText   = #E7ECFF
color cDim    = #8E98BD
color cGood   = #3DDC97
color cWarn   = #F5B84C
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
//  STATE
//  Samples are ATR-normalised maximum favourable / adverse excursions of
//  COMPLETED windows only, measured at three checkpoints (k1, k2, horizon).
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
var array<float> upK1 = array.new<float>()
var array<float> upK2 = array.new<float>()
var array<float> upKN = array.new<float>()
var array<float> dnK1 = array.new<float>()
var array<float> dnK2 = array.new<float>()
var array<float> dnKN = array.new<float>()
 
var array<float> heldU  = array.new<float>()   // wide band, upper side: 1 = held
var array<float> heldD  = array.new<float>()   // wide band, lower side: 1 = held
var array<float> heldSU = array.new<float>()   // short-stop distance held
var array<float> heldSD = array.new<float>()   // long-stop distance held
 
var array<polyline> polys = array.new<polyline>()
var array<label>    lbls  = array.new<label>()
var array<line>     lnObj = array.new<line>()
 
var int   aBar   = na
var float aClose = na
var float aAtr   = na
 
var table chip = table.new(chipPosC, 1, 4, bgcolor = cChipBg, frame_color = color.new(fanCol, 55), frame_width = 1)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
//  HELPERS
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
pushCap(array<float> arr, float v, int cap) =>
    if not na(v)
        array.push(arr, v)
        if array.size(arr) > cap
            array.shift(arr)
 
pctl(array<float> arr, float p) =>
    array.size(arr) >= minSamples ? array.percentile_linear_interpolation(arr, p) : na
 
// Band quantiles at the three checkpoints; widths forced to be non-decreasing in time.
bandSet(float p) =>
    float u1 = pctl(upK1, p)
    float u2 = math.max(u1, pctl(upK2, p))
    float u3 = math.max(u2, pctl(upKN, p))
    float d1 = pctl(dnK1, p)
    float d2 = math.max(d1, pctl(dnK2, p))
    float d3 = math.max(d2, pctl(dnKN, p))
    [u1, u2, u3, d1, d2, d3]
 
// Width (in ATR) at step k: linear in sqrt(time) between the empirical checkpoints.
fanW(float w1, float w2, float w3, int k) =>
    float x = math.sqrt(k)
    float r = 0.0
    if k <= 0
        r := 0.0
    else if k <= k1
        r := w1 * x / sx1
    else if k <= k2
        r := w1 + (w2 - w1) * (x - sx1) / (sx2 - sx1)
    else
        r := w2 + (w3 - w2) * (x - sx2) / (sx3 - sx2)
    r
 
buildEdge(int startBar, float base, float sc, float w1, float w2, float w3, int dir) =>
    array<chart.point> pts = array.new<chart.point>()
    for k = 0 to horizon
        array.push(pts, chart.point.from_index(startBar + k, base + dir * sc * fanW(w1, w2, w3, k)))
    pts
 
buildPoly(int startBar, float base, float sc, float u1, float u2, float u3, float d1, float d2, float d3) =>
    array<chart.point> pts = array.new<chart.point>()
    for k = 0 to horizon
        array.push(pts, chart.point.from_index(startBar + k, base + sc * fanW(u1, u2, u3, k)))
    for k = horizon to 0
        array.push(pts, chart.point.from_index(startBar + k, base - sc * fanW(d1, d2, d3, k)))
    pts
 
mkPoly(array<chart.point> pts, color fillC) =>
    polyline.new(pts, closed = true, fill_color = fillC, line_color = color.new(fillC, 100))
 
mkEdge(array<chart.point> pts, color lineC, int w, string sty) =>
    polyline.new(pts, closed = false, line_color = lineC, line_width = w, line_style = sty)
 
mkLabel(int x, float y, string txt, color c, string sz, string tip, string sty) =>
    label.new(x, y, txt, xloc = xloc.bar_index, style = sty, color = color.new(c, 100), textcolor = c, size = sz, tooltip = tip)
 
fmtPct(float x) =>
    (x >= 0 ? "+" : "-") + str.tostring(math.abs(x) * 100.0, "0.0") + "%"
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
//  1) COMPLETED-WINDOW SAMPLES  (no future data: window = bars t+1 .. t+k,
//     sample is stored at bar t+k, when that window has fully closed)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
float atrV = ta.atr(atrLen)
 
float hi1 = ta.highest(high, k1)
float lo1 = ta.lowest(low, k1)
float hi2 = ta.highest(high, k2)
float lo2 = ta.lowest(low, k2)
float hi3 = ta.highest(high, k3)
float lo3 = ta.lowest(low, k3)
 
float a1 = atrV[k1]
float a2 = atrV[k2]
float a3 = atrV[k3]
 
float upS1 = a1 > 0 ? math.max(0.0, (hi1 - close[k1]) / a1) : na
float dnS1 = a1 > 0 ? math.max(0.0, (close[k1] - lo1) / a1) : na
float upS2 = a2 > 0 ? math.max(0.0, (hi2 - close[k2]) / a2) : na
float dnS2 = a2 > 0 ? math.max(0.0, (close[k2] - lo2) / a2) : na
float upS3 = a3 > 0 ? math.max(0.0, (hi3 - close[k3]) / a3) : na
float dnS3 = a3 > 0 ? math.max(0.0, (close[k3] - lo3) / a3) : na
 
// Store once per bar (at bar close) so realtime ticks never duplicate samples.
if barstate.isconfirmed
    pushCap(upK1, upS1, sampleCap)
    pushCap(dnK1, dnS1, sampleCap)
    pushCap(upK2, upS2, sampleCap)
    pushCap(dnK2, dnS2, sampleCap)
    pushCap(upKN, upS3, sampleCap)
    pushCap(dnKN, dnS3, sampleCap)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
//  2) BOUNDS AT EVERY BAR OF THE RECENT ZONE  (used by Fan Check, previous
//     fan and alerts). Each bound only uses windows completed at that bar.
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
bool inZone = bar_index >= last_bar_index - span - horizon - 1
 
float wU1 = na
float wU2 = na
float wUN = na
float wD1 = na
float wD2 = na
float wDN = na
float sUN = na
float sDN = na
 
if inZone
    [t1, t2, t3, t4, t5, t6] = bandSet(pWide)
    wU1 := t1
    wU2 := t2
    wUN := t3
    wD1 := t4
    wD2 := t5
    wDN := t6
    if stopOn
        sUN := pctl(upKN, stopPct)
        sDN := pctl(dnKN, stopPct)
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
//  3) OUT-OF-SAMPLE CHECK: compare the window that just ended with the
//     bound that was computed when that window began (horizon bars ago).
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
float bUp = wUN[horizon]
float bDn = wDN[horizon]
bool canEval = not na(bUp) and not na(bDn) and not na(upS3) and not na(dnS3)
 
if barstate.isconfirmed and canEval
    pushCap(heldU, upS3 <= bUp ? 1.0 : 0.0, span)
    pushCap(heldD, dnS3 <= bDn ? 1.0 : 0.0, span)
    if stopOn
        float bsU = sUN[horizon]
        float bsD = sDN[horizon]
        if not na(bsU) and not na(bsD)
            pushCap(heldSU, upS3 <= bsU ? 1.0 : 0.0, span)
            pushCap(heldSD, dnS3 <= bsD ? 1.0 : 0.0, span)
 
bool upX = barstate.isconfirmed and canEval and upS3 > bUp
bool dnX = barstate.isconfirmed and canEval and dnS3 > bDn
 
alertcondition(upX and not upX[1], "Range Fan: up-move beyond wide range",
     "Range Fan: over the last window, price travelled farther up than the wide band drawn when that window began ({{ticker}}, {{interval}}).")
alertcondition(dnX and not dnX[1], "Range Fan: down-move beyond wide range",
     "Range Fan: over the last window, price travelled farther down than the wide band drawn when that window began ({{ticker}}, {{interval}}).")
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
//  4) ANCHOR  (last closed bar, or live price in "Every tick" mode)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
if barstate.isconfirmed
    aBar := bar_index
    aClose := close
    aAtr := atrV
 
bool  liveMode = updMode == "Every tick"
int   fBar   = liveMode ? bar_index : aBar
float fClose = liveMode ? close : aClose
float fAtr   = liveMode ? atrV : aAtr
 
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
//  5) DRAWING  (last bar only; objects are rebuilt every update)
//━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━
if barstate.islast
    for pl in polys
        polyline.delete(pl)
    array.clear(polys)
    for lb in lbls
        label.delete(lb)
    array.clear(lbls)
    for lo in lnObj
        line.delete(lo)
    array.clear(lnObj)
 
    bool ready = not na(fBar) and not na(fClose) and fAtr > 0
 
    [c1, c2, c3, c4, c5, c6] = bandSet(pCore)
    [w1, w2, w3, w4, w5, w6] = bandSet(pWide)
    [e1, e2, e3, e4, e5, e6] = bandSet(pExt)
 
    bool haveFan = ready and not na(c3) and not na(c6) and not na(w3) and not na(w6) and not na(e3) and not na(e6)
 
    // Held rates from the out-of-sample check
    float rateU  = array.size(heldU)  >= 20 ? array.avg(heldU)  * 100.0 : na
    float rateD  = array.size(heldD)  >= 20 ? array.avg(heldD)  * 100.0 : na
    float rateSU = array.size(heldSU) >= 20 ? array.avg(heldSU) * 100.0 : na
    float rateSD = array.size(heldSD) >= 20 ? array.avg(heldSD) * 100.0 : na
 
    if haveFan
        // Layered bands: outer to inner so the centre is brightest
        if showExt
            array.push(polys, mkPoly(buildPoly(fBar, fClose, fAtr, e1, e2, e3, e4, e5, e6), color.new(accCol, 92)))
        array.push(polys, mkPoly(buildPoly(fBar, fClose, fAtr, w1, w2, w3, w4, w5, w6), color.new(fanCol, 85)))
        array.push(polys, mkPoly(buildPoly(fBar, fClose, fAtr, c1, c2, c3, c4, c5, c6), color.new(fanCol, 68)))
 
        if showExt
            array.push(polys, mkEdge(buildEdge(fBar, fClose, fAtr, e1, e2, e3, 1), color.new(accCol, 55), 1, line.style_dotted))
            array.push(polys, mkEdge(buildEdge(fBar, fClose, fAtr, e4, e5, e6, -1), color.new(accCol, 55), 1, line.style_dotted))
        if showGlow
            array.push(polys, mkEdge(buildEdge(fBar, fClose, fAtr, w1, w2, w3, 1), color.new(fanCol, 88), 5, line.style_solid))
            array.push(polys, mkEdge(buildEdge(fBar, fClose, fAtr, w4, w5, w6, -1), color.new(fanCol, 88), 5, line.style_solid))
        array.push(polys, mkEdge(buildEdge(fBar, fClose, fAtr, w1, w2, w3, 1), color.new(fanCol, 15), 1, line.style_solid))
        array.push(polys, mkEdge(buildEdge(fBar, fClose, fAtr, w4, w5, w6, -1), color.new(fanCol, 15), 1, line.style_solid))
        array.push(polys, mkEdge(buildEdge(fBar, fClose, fAtr, c1, c2, c3, 1), color.new(fanCol, 50), 1, line.style_solid))
        array.push(polys, mkEdge(buildEdge(fBar, fClose, fAtr, c4, c5, c6, -1), color.new(fanCol, 50), 1, line.style_solid))
 
        // Start-price reference
        array.push(lnObj, line.new(fBar, fClose, fBar + horizon, fClose, xloc = xloc.bar_index, color = color.new(fanCol, 40), style = line.style_dotted, width = 1))
 
        // Previous fan: the fan drawn one horizon ago, outline only
        if showGhost
            int   gOff = bar_index - fBar + horizon
            int   gBar = fBar - horizon
            float gc   = close[gOff]
            float ga   = atrV[gOff]
            float gu1  = wU1[gOff]
            float gu2  = wU2[gOff]
            float gu3  = wUN[gOff]
            float gd1  = wD1[gOff]
            float gd2  = wD2[gOff]
            float gd3  = wDN[gOff]
            if not na(gc) and ga > 0 and not na(gu3) and not na(gd3)
                array.push(polys, mkEdge(buildEdge(gBar, gc, ga, gu1, gu2, gu3, 1), color.new(fanCol, 72), 1, line.style_dotted))
                array.push(polys, mkEdge(buildEdge(gBar, gc, ga, gd1, gd2, gd3, -1), color.new(fanCol, 72), 1, line.style_dotted))
                if showLabels
                    array.push(lbls, mkLabel(gBar, gc, "previous fan", color.new(fanCol, 35), szTxt, "The wide band as it looked one horizon ago. Compare it with what price actually did.", label.style_label_down))
 
        // End labels on the wide band
        if showLabels
            float topP = fClose + fAtr * w3
            float botP = fClose - fAtr * w6
            string tipW = str.tostring(pWide, "0") + "% of comparable past " + str.tostring(horizon) + "-bar windows stayed inside this level. A historical range, not a forecast or a target."
            array.push(lbls, mkLabel(fBar + horizon, topP, "▲ " + str.tostring(topP, format.mintick) + "  " + fmtPct(topP / fClose - 1.0), fanCol, szTxt, tipW, label.style_label_left))
            array.push(lbls, mkLabel(fBar + horizon, botP, "▼ " + str.tostring(botP, format.mintick) + "  " + fmtPct(botP / fClose - 1.0), fanCol, szTxt, tipW, label.style_label_left))
 
        // Optional historical stop ruler
        if stopOn
            float sdD = pctl(dnKN, stopPct)
            float suD = pctl(upKN, stopPct)
            float entry = entryIn > 0 ? entryIn : fClose
            bool showL = stopSide != "Short only"
            bool showS = stopSide != "Long only"
            if showL and not na(sdD)
                float lvl = entry - sdD * fAtr
                array.push(lnObj, line.new(fBar, lvl, fBar + horizon, lvl, xloc = xloc.bar_index, color = color.new(longCol, 10), style = line.style_dashed, width = 1))
                string tipL = "Price moved farther than this against a long in only " + str.tostring(100.0 - stopPct, "0") + "% of past " + str.tostring(horizon) + "-bar windows." + (na(rateSD) ? "" : " Held " + str.tostring(rateSD, "0") + "% in recent out-of-sample windows.") + " A noise distance, not a recommendation."
                array.push(lbls, mkLabel(fBar + horizon, lvl, "Long stop " + str.tostring(lvl, format.mintick) + "  " + fmtPct(lvl / entry - 1.0) + " · " + str.tostring(sdD, "0.0") + " ATR", longCol, szTxt, tipL, label.style_label_left))
            if showS and not na(suD)
                float lvs = entry + suD * fAtr
                array.push(lnObj, line.new(fBar, lvs, fBar + horizon, lvs, xloc = xloc.bar_index, color = color.new(shortCol, 10), style = line.style_dashed, width = 1))
                string tipS = "Price moved farther than this against a short in only " + str.tostring(100.0 - stopPct, "0") + "% of past " + str.tostring(horizon) + "-bar windows." + (na(rateSU) ? "" : " Held " + str.tostring(rateSU, "0") + "% in recent out-of-sample windows.") + " A noise distance, not a recommendation."
                array.push(lbls, mkLabel(fBar + horizon, lvs, "Short stop " + str.tostring(lvs, format.mintick) + "  " + fmtPct(lvs / entry - 1.0) + " · " + str.tostring(suD, "0.0") + " ATR", shortCol, szTxt, tipS, label.style_label_left))
 
    // Fan Check chip
    if showChip
        string stTxt = "Collecting history…"
        color  stCol = cDim
        string heldTxt = "Needs " + str.tostring(minSamples) + "+ completed windows"
        if not na(rateU) and not na(rateD)
            heldTxt := "Held  ▲ " + str.tostring(rateU, "0") + "%   ▼ " + str.tostring(rateD, "0") + "%   (target " + str.tostring(pWide, "0") + "%)"
            float avgRate = (rateU + rateD) / 2.0
            if avgRate < pWide - 8.0
                stTxt := "Bands running tight"
                stCol := cWarn
            else if avgRate > pWide + 8.0
                stTxt := "Bands running wide"
                stCol := cWarn
            else
                stTxt := "On target"
                stCol := cGood
        if not chart.is_standard
            stTxt := "Use standard candles"
            stCol := cWarn
        string tipChip = "Out-of-sample check. For each recent window, the band drawn when it began is compared with how far price really travelled. 'Held' = share of windows that stayed inside. Meaningful when close to the target."
        table.cell(chip, 0, 0, "RANGE FAN  ·  " + str.tostring(horizon) + " bars", text_color = cDim, text_size = szTxt, text_halign = text.align_left, bgcolor = cChipBg, tooltip = tipChip)
        table.cell(chip, 0, 1, heldTxt, text_color = cText, text_size = szTxt, text_halign = text.align_left, bgcolor = cChipBg, tooltip = tipChip)
        table.cell(chip, 0, 2, stTxt, text_color = stCol, text_size = szTxt, text_halign = text.align_left, bgcolor = cChipBg, tooltip = tipChip)
        string stopTxt = ""
        if stopOn and not na(rateSU) and not na(rateSD)
            stopTxt := "Stops held  long " + str.tostring(rateSD, "0") + "%   short " + str.tostring(rateSU, "0") + "%   (target " + str.tostring(stopPct, "0") + "%)"
        table.cell(chip, 0, 3, stopTxt, text_color = cText, text_size = szTxt, text_halign = text.align_left, bgcolor = cChipBg, tooltip = tipChip)

← 返回列表