Trend Stack + Williams %R Pullback Signals (MTF)

OlympusCipher · study · 390 行 · 点赞 245 · TradingView 原页

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

Pine Script

// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//Olympus Cipher
 
//  ◇━━━━━━━━━━━━━━━━━━  C R E A T E D    B Y  ━━━━━━━━━━━━━━━━━━◇
//
//     ████   ██      ██  ██  ██      ██  █████   ██  ██   █████
//    ██  ██  ██      ██  ██  ███    ███  ██  ██  ██  ██  ██
//    ██  ██  ██       ████   ████  ████  ██  ██  ██  ██  ██
//    ██  ██  ██        ██    ██ ████ ██  █████   ██  ██   ████
//    ██  ██  ██        ██    ██  ██  ██  ██      ██  ██      ██
//    ██  ██  ██        ██    ██      ██  ██      ██  ██      ██
//     ████   ██████    ██    ██      ██  ██       ████   █████
//
//           █████  ██████  █████   ██  ██  ██████  █████
//          ██        ██    ██  ██  ██  ██  ██      ██  ██
//          ██        ██    ██  ██  ██  ██  ██      ██  ██
//          ██        ██    █████   ██████  █████   █████
//          ██        ██    ██      ██  ██  ██      ██  ██
//          ██        ██    ██      ██  ██  ██      ██  ██
//           █████  ██████  ██      ██  ██  ██████  ██  ██
//
//  ◇━━━━━━━━━━━━ Ω  O L Y M P U S    C I P H E R  Ω ━━━━━━━━━━━━◇
 
//@version=6
indicator("Trend Stack + Williams %R Pullback Signals (MTF)", shorttitle="TSW", overlay=true, max_labels_count=500)
 
// ─────────────────────────── HELPERS ───────────────────────────
f_size(s) =>
    s == "Tiny" ? size.tiny : s == "Small" ? size.small : s == "Normal" ? size.normal : s == "Large" ? size.large : size.huge
 
f_pos(s) =>
    s == "Top Left" ? position.top_left : s == "Top Right" ? position.top_right : s == "Bottom Left" ? position.bottom_left : position.bottom_right
 
// Turns "240" into "4h", "D" into "1D", etc.
f_tfLabel(t) =>
    s = timeframe.in_seconds(t)
    s >= 2419200 ? str.tostring(math.round(s / 2629800.0)) + "M" : s >= 604800 ? str.tostring(s / 604800.0, "#.#") + "W" : s >= 86400 ? str.tostring(s / 86400.0, "#.#") + "D" : s >= 3600 ? str.tostring(s / 3600.0, "#.#") + "h" : s >= 60 ? str.tostring(s / 60.0, "#.#") + "m" : str.tostring(s) + "s"
 
// Number to text, showing "—" instead of NaN
f_num(x, fmt) =>
    na(x) ? "—" : str.tostring(x, fmt)
 
// Quality mask: 1 = pullback touched EMA, 2 = close beyond EMA 1, 4 = strong trend, 8 = hidden divergence
f_bit(m, k) =>
    math.floor(m / k) % 2 == 1
 
f_score(m) =>
    (f_bit(m, 1) ? 1 : 0) + (f_bit(m, 2) ? 1 : 0) + (f_bit(m, 4) ? 1 : 0) + (f_bit(m, 8) ? 1 : 0)
 
f_grade(s) =>
    s >= 3 ? "A" : s >= 2 ? "B" : "C"
 
f_chk(m, k) =>
    f_bit(m, k) ? "✓" : "✗"
 
// ─────────────────────────── INPUTS ───────────────────────────
grpTf = "Timeframe"
tfIn      = input.timeframe("", "Signal Timeframe (blank = chart)", group=grpTf, tooltip="Select e.g. 4 hours and then view a lower chart such as 5 min. All EMA / Williams %R calculations use this timeframe.")
waitClose = input.bool(true, "Wait for Timeframe Bar Close (no repaint)", group=grpTf, tooltip="ON: signals, EMAs and trend colours use the last CLOSED timeframe bar, so nothing repaints. OFF: everything updates live and signals may disappear before the candle closes.")
 
grpEma = "EMA Stack"
src         = input.source(close, "Source", group=grpEma)
len1        = input.int(21,  "EMA 1 (fastest)", minval=1, group=grpEma)
len2        = input.int(50,  "EMA 2", minval=1, group=grpEma)
len3        = input.int(100, "EMA 3", minval=1, group=grpEma)
len4        = input.int(200, "EMA 4 (slowest)", minval=1, group=grpEma)
noCrossBars = input.int(3, "No-Cross Lookback (bars, 0 = off)", minval=0, maxval=100, group=grpEma, tooltip="Trend is valid only if none of the EMAs crossed each other in the last N bars of the selected timeframe.")
 
grpWpr = "Williams %R"
wprLen    = input.int(14, "Length", minval=1, group=grpWpr)
wprSmooth = input.int(1, "Smoothing (1 = none)", minval=1, maxval=20, group=grpWpr)
upperBand = input.float(-20.0, "Upper Band", minval=-100, maxval=0, step=1, group=grpWpr)
lowerBand = input.float(-80.0, "Lower Band", minval=-100, maxval=0, step=1, group=grpWpr)
 
grpStr = "Trend Strength"
strMode    = input.string("ADX", "Strength Measure", options=["ADX", "EMA Spread", "Both"], group=grpStr, tooltip="ADX: trend is strong when ADX is above the minimum. EMA Spread: strong when the gap between EMA 1 and EMA 4 is at least N × ATR. Both: both must pass.")
adxLen     = input.int(14, "ADX Length", minval=1, group=grpStr)
adxMin     = input.float(20.0, "ADX Minimum", minval=0, step=1, group=grpStr)
atrLen     = input.int(14, "ATR Length (for spread)", minval=1, group=grpStr)
sprMin     = input.float(1.0, "Min EMA 1–4 Gap (× ATR)", minval=0, step=0.1, group=grpStr)
useStrFilt = input.bool(false, "Block Signals in Weak Trends", group=grpStr, tooltip="OFF: weak-trend signals still show but get a lower grade. ON: they are removed.")
 
grpDiv = "Hidden Divergence"
divMax     = input.int(60, "Max Bars Between Pullbacks", minval=5, maxval=300, group=grpDiv, tooltip="Each pullback into the %R zone is compared to the previous one. Buy: price made a higher low while %R made a lower low. Sell: price made a lower high while %R made a higher high. Pullbacks further apart than this are not compared.")
useDivFilt = input.bool(false, "Require Hidden Divergence", group=grpDiv, tooltip="OFF: divergence only raises the grade. ON: signals without it are removed.")
 
grpFlt = "Other Filters"
useCloseConf = input.bool(false, "Require Close Beyond EMA 1", group=grpFlt, tooltip="Buy only when the timeframe close is back above EMA 1 (sell: below).")
usePb        = input.bool(false, "Require Pullback Into EMA Zone", group=grpFlt, tooltip="Buy only if price actually dipped to the chosen EMA recently (sell: rallied up to it).")
pbRef        = input.string("EMA 2", "Pullback Must Touch", options=["EMA 1", "EMA 2"], group=grpFlt)
pbBars       = input.int(5, "Pullback Lookback (TF bars)", minval=1, maxval=50, group=grpFlt)
 
grpGrd = "Signal Grading"
showGrade = input.bool(true, "Show Grade on Label", group=grpGrd, tooltip="Each signal scores 1 point for: pullback touched the EMA, close beyond EMA 1, strong trend, hidden divergence. A = 3–4, B = 2, C = 0–1.")
minGrade  = input.string("C", "Minimum Grade to Show", options=["A", "B", "C"], group=grpGrd)
fadeLow   = input.bool(true, "Fade Lower Grades", group=grpGrd, tooltip="B signals are drawn slightly transparent, C signals more so.")
 
grpSig = "Signals"
showBuy   = input.bool(true, "Show Buy Signals", group=grpSig)
showSell  = input.bool(true, "Show Sell Signals", group=grpSig)
sigStyle  = input.string("Pro Labels", "Signal Style", options=["Pro Labels", "Triangles", "Arrows", "Dots"], group=grpSig)
showBox   = input.bool(true, "Show Label Box (Pro Labels)", group=grpSig, tooltip="OFF removes the filled rectangle and shows coloured text only.")
lblSizeIn = input.string("Normal", "Label Size (Pro Labels)", options=["Tiny", "Small", "Normal", "Large", "Huge"], group=grpSig)
buyText   = input.string("", "Buy Label Text", group=grpSig)
sellText  = input.string("", "Sell Label Text", group=grpSig)
showGlow  = input.bool(false, "Glow Effect", group=grpSig)
showHl    = input.bool(false, "Highlight Signal Bar", group=grpSig)
cooldown  = input.int(0, "Min Chart Bars Between Signals", minval=0, maxval=500, group=grpSig)
 
grpSty = "Style"
bullCol      = input.color(#00e676, "Bullish Colour", group=grpSty)
bearCol      = input.color(#ff1744, "Bearish Colour", group=grpSty)
neutCol      = input.color(#9e9e9e, "No-Trend Colour", group=grpSty)
colorByTrend = input.bool(true, "Colour EMAs by Trend", group=grpSty)
ema1Col      = input.color(#00e5ff, "EMA 1 Colour", group=grpSty)
ema2Col      = input.color(#2979ff, "EMA 2 Colour", group=grpSty)
ema3Col      = input.color(#d500f9, "EMA 3 Colour", group=grpSty)
ema4Col      = input.color(#ff9100, "EMA 4 Colour", group=grpSty)
lineW        = input.int(2, "EMA Line Width", minval=1, maxval=5, group=grpSty)
showFill     = input.bool(true, "Show Ribbon Fill", group=grpSty)
fillTr       = input.int(85, "Ribbon Transparency", minval=0, maxval=100, group=grpSty)
showBg       = input.bool(false, "Tint Background by Trend", group=grpSty)
showBars     = input.bool(false, "Colour Candles by Trend", group=grpSty)
 
grpDash = "Dashboard"
showDash    = input.bool(true, "Show Dashboard", group=grpDash)
dashPosIn   = input.string("Top Right", "Position", options=["Top Left", "Top Right", "Bottom Left", "Bottom Right"], group=grpDash)
dashSizeIn  = input.string("Normal", "Text Size", options=["Tiny", "Small", "Normal", "Large", "Huge"], group=grpDash)
dashTextCol = input.color(color.white, "Text Colour", group=grpDash)
dashBgCol   = input.color(color.new(#131722, 10), "Background Colour", group=grpDash)
 
// ─────────────────────────── INPUT CHECKS ───────────────────────────
if lowerBand >= upperBand
    runtime.error("Williams %R: Lower Band must be below Upper Band.")
if not (len1 < len2 and len2 < len3 and len3 < len4)
    runtime.error("EMA Stack: lengths must increase from EMA 1 (fastest) to EMA 4 (slowest).")
 
minScore = minGrade == "A" ? 3 : minGrade == "B" ? 2 : 0
 
// ─────────────────────────── CORE LOGIC (runs on selected TF) ───────────────────────────
// Returns [ema1, ema2, ema3, ema4, trend, %R, signal, quality mask, ADX, EMA spread in ATR, bar time]
f_core() =>
    a = ta.ema(src, len1)
    b = ta.ema(src, len2)
    c = ta.ema(src, len3)
    d = ta.ema(src, len4)
 
    // Trend: full stack in order, and no EMA crosses in the last N bars
    x1 = ta.cross(a, b)
    x2 = ta.cross(b, c)
    x3 = ta.cross(c, d)
    crossN   = (x1 ? 1 : 0) + (x2 ? 1 : 0) + (x3 ? 1 : 0)
    crossSum = math.sum(crossN, math.max(noCrossBars, 1))
    recent   = noCrossBars > 0 and crossSum > 0
    bull  = a > b and b > c and c > d
    bear  = a < b and b < c and c < d
    trend = bull and not recent ? 1 : bear and not recent ? -1 : 0
 
    // Williams %R trigger
    w  = ta.sma(ta.wpr(wprLen), wprSmooth)
    up = ta.crossover(w, lowerBand)
    dn = ta.crossunder(w, upperBand)
 
    // Trend strength
    [diPlus, diMinus, adx] = ta.dmi(adxLen, adxLen)
    atr    = ta.atr(atrLen)
    spread = atr > 0 ? math.abs(a - d) / atr : 0.0
    adxOk  = adx >= adxMin
    sprOk  = spread >= sprMin
    strong = strMode == "ADX" ? adxOk : strMode == "EMA Spread" ? sprOk : adxOk and sprOk
 
    // Hidden divergence — bullish: compare this oversold dip with the previous one
    var float bCurW  = na
    var float bCurL  = na
    var float bPrevW = na
    var float bPrevL = na
    var int   bPrevI = na
    if w <= lowerBand
        bCurW := na(bCurW) ? w : math.min(bCurW, w)
        bCurL := na(bCurL) ? low : math.min(bCurL, low)
    hdB = false
    if up and not na(bCurW)
        hdB    := not na(bPrevW) and bar_index - bPrevI <= divMax and bCurL > bPrevL and bCurW < bPrevW
        bPrevW := bCurW
        bPrevL := bCurL
        bPrevI := bar_index
        bCurW  := na
        bCurL  := na
 
    // Hidden divergence — bearish: compare this overbought rally with the previous one
    var float sCurW  = na
    var float sCurH  = na
    var float sPrevW = na
    var float sPrevH = na
    var int   sPrevI = na
    if w >= upperBand
        sCurW := na(sCurW) ? w : math.max(sCurW, w)
        sCurH := na(sCurH) ? high : math.max(sCurH, high)
    hdS = false
    if dn and not na(sCurW)
        hdS    := not na(sPrevW) and bar_index - sPrevI <= divMax and sCurH < sPrevH and sCurW > sPrevW
        sPrevW := sCurW
        sPrevH := sCurH
        sPrevI := bar_index
        sCurW  := na
        sCurH  := na
 
    // Pullback and close conditions
    pbLevel = pbRef == "EMA 1" ? a : b
    bsBull  = ta.barssince(low <= pbLevel)
    bsBear  = ta.barssince(high >= pbLevel)
    pbB = not na(bsBull) and bsBull < pbBars
    pbS = not na(bsBear) and bsBear < pbBars
    cfB = close > a
    cfS = close < a
 
    // Quality mask and score per side
    mB  = (pbB ? 1 : 0) + (cfB ? 2 : 0) + (strong ? 4 : 0) + (hdB ? 8 : 0)
    mS  = (pbS ? 1 : 0) + (cfS ? 2 : 0) + (strong ? 4 : 0) + (hdS ? 8 : 0)
    scB = (pbB ? 1 : 0) + (cfB ? 1 : 0) + (strong ? 1 : 0) + (hdB ? 1 : 0)
    scS = (pbS ? 1 : 0) + (cfS ? 1 : 0) + (strong ? 1 : 0) + (hdS ? 1 : 0)
 
    okB = (not usePb or pbB) and (not useCloseConf or cfB) and (not useStrFilt or strong) and (not useDivFilt or hdB) and scB >= minScore
    okS = (not usePb or pbS) and (not useCloseConf or cfS) and (not useStrFilt or strong) and (not useDivFilt or hdS) and scS >= minScore
 
    sig  = trend == 1 and up and okB ? 1 : trend == -1 and dn and okS ? -1 : 0
    mask = sig == 1 ? mB : sig == -1 ? mS : 0
    [a, b, c, d, trend, w, sig, mask, adx, spread, time]
 
// Same values from the previous (closed) bar — used with lookahead_on for a non-repainting read
f_coreConf() =>
    [a, b, c, d, t, w, s, m, ax, sp, tm] = f_core()
    [a[1], b[1], c[1], d[1], t[1], w[1], s[1], m[1], ax[1], sp[1], tm[1]]
 
tf      = tfIn == "" ? timeframe.period : tfIn
tfSec   = timeframe.in_seconds(tf)
chSec   = timeframe.in_seconds(timeframe.period)
tfValid = tfSec >= chSec
sameTf  = tfSec == chSec
tfLbl   = f_tfLabel(tf)
 
[e1L, e2L, e3L, e4L, trL, wL, sgL, mkL, axL, spL, tmL] = request.security(syminfo.tickerid, tf, f_core(), lookahead=barmerge.lookahead_off)
[e1C, e2C, e3C, e4C, trC, wC, sgC, mkC, axC, spC, tmC] = request.security(syminfo.tickerid, tf, f_coreConf(), lookahead=barmerge.lookahead_on)
 
// Pick one consistent data set for everything
useLive = not waitClose or sameTf
e1     = useLive ? e1L : e1C
e2     = useLive ? e2L : e2C
e3     = useLive ? e3L : e3C
e4     = useLive ? e4L : e4C
trendR = useLive ? trL : trC
wprV   = useLive ? wL  : wC
sg     = useLive ? sgL : sgC
maskV  = int(nz(useLive ? mkL : mkC))
adxV   = useLive ? axL : axC
sprV   = useLive ? spL : spC
tm     = useLive ? tmL : tmC
 
// ─────────────────────────── SIGNAL GATING ───────────────────────────
barOk = not waitClose or not sameTf or barstate.isconfirmed
 
var float lastSigTm  = na
var int   lastSigBar = na
newTfSig = na(lastSigTm) or tm != lastSigTm
cdOk     = na(lastSigBar) or bar_index - lastSigBar >= cooldown
canFire  = tfValid and barOk and newTfSig and cdOk
 
buySig  = showBuy  and sg == 1  and canFire
sellSig = showSell and sg == -1 and canFire
 
scoreV = f_score(maskV)
gradeV = f_grade(scoreV)
 
var string lastSig = "-"
if buySig or sellSig
    lastSigTm  := tm
    lastSigBar := bar_index
    lastSig    := (buySig ? "BUY " : "SELL ") + gradeV
 
bullTrend = tfValid and trendR == 1
bearTrend = tfValid and trendR == -1
trendCol  = bullTrend ? bullCol : bearTrend ? bearCol : neutCol
 
// Grade-based transparency for signal markers
gradeTr = not fadeLow ? 0 : scoreV >= 3 ? 0 : scoreV >= 2 ? 35 : 65
sBull   = color.new(bullCol, gradeTr)
sBear   = color.new(bearCol, gradeTr)
 
f_msg(side, sep) =>
    side + " · Grade " + gradeV + " (" + str.tostring(scoreV) + "/4)" + sep + syminfo.ticker + " · TF " + tfLbl + sep + "Price " + str.tostring(close, format.mintick) + sep + "%R " + f_num(wprV, "0.0")
 
f_checklist() =>
    "\n\nPullback to EMA " + f_chk(maskV, 1) + "\nClose beyond EMA 1 " + f_chk(maskV, 2) + "\nStrong trend " + f_chk(maskV, 4) + "\nHidden divergence " + f_chk(maskV, 8)
 
// ─────────────────────────── PLOTS ───────────────────────────
c1 = colorByTrend ? trendCol : ema1Col
c2 = colorByTrend ? trendCol : ema2Col
c3 = colorByTrend ? trendCol : ema3Col
c4 = colorByTrend ? trendCol : ema4Col
 
p1 = plot(tfValid ? e1 : na, "EMA 1", color=c1, linewidth=lineW)
p2 = plot(tfValid ? e2 : na, "EMA 2", color=c2, linewidth=lineW)
p3 = plot(tfValid ? e3 : na, "EMA 3", color=c3, linewidth=lineW)
p4 = plot(tfValid ? e4 : na, "EMA 4", color=c4, linewidth=lineW)
 
fillCol = showFill ? color.new(trendCol, fillTr) : na
fill(p1, p2, color=fillCol, title="Fill 1-2")
fill(p2, p3, color=fillCol, title="Fill 2-3")
fill(p3, p4, color=fillCol, title="Fill 3-4")
 
bgcolor(showBg ? color.new(trendCol, 92) : na, title="Trend Background")
barcolor(showBars ? trendCol : na, title="Trend Candles")
bgcolor(showHl and buySig ? color.new(bullCol, 85) : showHl and sellSig ? color.new(bearCol, 85) : na, title="Signal Bar Highlight")
 
// ─────────────────────────── SIGNAL VISUALS ───────────────────────────
lblSize = f_size(lblSizeIn)
 
plotshape(showGlow and buySig,  "Buy Glow Outer",  shape.circle, location.belowbar, color=color.new(bullCol, 90), size=size.huge,  display=display.pane)
plotshape(showGlow and buySig,  "Buy Glow Inner",  shape.circle, location.belowbar, color=color.new(bullCol, 75), size=size.large, display=display.pane)
plotshape(showGlow and sellSig, "Sell Glow Outer", shape.circle, location.abovebar, color=color.new(bearCol, 90), size=size.huge,  display=display.pane)
plotshape(showGlow and sellSig, "Sell Glow Inner", shape.circle, location.abovebar, color=color.new(bearCol, 75), size=size.large, display=display.pane)
 
isTri = sigStyle == "Triangles"
isArr = sigStyle == "Arrows"
isDot = sigStyle == "Dots"
 
plotshape(isTri and buySig,  "Buy Triangle",  shape.triangleup,   location.belowbar, color=sBull, size=size.small,  display=display.pane)
plotshape(isTri and sellSig, "Sell Triangle", shape.triangledown, location.abovebar, color=sBear, size=size.small,  display=display.pane)
plotshape(isArr and buySig,  "Buy Arrow",     shape.arrowup,      location.belowbar, color=sBull, size=size.normal, display=display.pane)
plotshape(isArr and sellSig, "Sell Arrow",    shape.arrowdown,    location.abovebar, color=sBear, size=size.normal, display=display.pane)
plotshape(isDot and buySig,  "Buy Dot",       shape.circle,       location.belowbar, color=sBull, size=size.tiny,   display=display.pane)
plotshape(isDot and sellSig, "Sell Dot",      shape.circle,       location.abovebar, color=sBear, size=size.tiny,   display=display.pane)
 
buyLblStyle  = showBox ? label.style_label_up   : label.style_none
sellLblStyle = showBox ? label.style_label_down : label.style_none
buyLblBg     = showBox ? sBull : color.new(bullCol, 100)
sellLblBg    = showBox ? sBear : color.new(bearCol, 100)
buyLblTxt    = showBox ? color.black : sBull
sellLblTxt   = showBox ? color.white : sBear
gradeSuffix  = showGrade ? " · " + gradeV : ""
 
if sigStyle == "Pro Labels" and buySig
    label.new(bar_index, low, "▲ " + buyText + gradeSuffix, xloc=xloc.bar_index, yloc=yloc.belowbar, style=buyLblStyle, color=buyLblBg, textcolor=buyLblTxt, size=lblSize, tooltip=f_msg("BUY", "\n") + f_checklist())
 
if sigStyle == "Pro Labels" and sellSig
    label.new(bar_index, high, sellText + gradeSuffix + " ▼", xloc=xloc.bar_index, yloc=yloc.abovebar, style=sellLblStyle, color=sellLblBg, textcolor=sellLblTxt, size=lblSize, tooltip=f_msg("SELL", "\n") + f_checklist())
 
// ─────────────────────────── ALERTS ───────────────────────────
alertcondition(buySig,  "TSW Buy",  "TSW BUY on {{ticker}} at {{close}}")
alertcondition(sellSig, "TSW Sell", "TSW SELL on {{ticker}} at {{close}}")
alertcondition(buySig or sellSig, "TSW Any Signal", "TSW signal on {{ticker}} at {{close}}")
alertcondition((buySig or sellSig) and scoreV >= 3, "TSW A-Grade Signal", "TSW A-grade signal on {{ticker}} at {{close}}")
 
// "Any alert() function call" — includes grade, TF, price and %R
if buySig
    alert(f_msg("TSW BUY", " | "), alert.freq_once_per_bar)
if sellSig
    alert(f_msg("TSW SELL", " | "), alert.freq_once_per_bar)
 
// ─────────────────────────── DASHBOARD ───────────────────────────
var table dash = table.new(f_pos(dashPosIn), 2, 6, bgcolor=dashBgCol, border_width=1, border_color=color.new(color.gray, 60))
 
if showDash and barstate.islast
    dSize    = f_size(dashSizeIn)
    modeTxt  = useLive ? "live" : "closed bar"
    trendTxt = not tfValid ? "TF TOO LOW" : bullTrend ? "BULLISH" : bearTrend ? "BEARISH" : "NO TREND"
    adxOkD   = not na(adxV) and adxV >= adxMin
    sprOkD   = not na(sprV) and sprV >= sprMin
    strongD  = strMode == "ADX" ? adxOkD : strMode == "EMA Spread" ? sprOkD : adxOkD and sprOkD
    strTxt   = not tfValid ? "—" : "ADX " + f_num(adxV, "0.0") + " · Gap " + f_num(sprV, "0.0") + " ATR" + (strongD ? " · Strong" : " · Weak")
    strCol   = strongD ? trendCol : neutCol
    zoneTxt  = na(wprV) ? "—" : wprV >= upperBand ? "Overbought" : wprV <= lowerBand ? "Oversold" : "Neutral"
    zoneCol  = na(wprV) ? neutCol : wprV >= upperBand ? bearCol : wprV <= lowerBand ? bullCol : neutCol
    setupTxt = not tfValid ? "—" : bullTrend and wprV <= lowerBand ? "Buy armed" : bearTrend and wprV >= upperBand ? "Sell armed" : bullTrend ? "Wait for dip" : bearTrend ? "Wait for rally" : "Stand aside"
    setupCol = bullTrend and wprV <= lowerBand ? bullCol : bearTrend and wprV >= upperBand ? bearCol : neutCol
    agoTxt   = na(lastSigBar) ? "" : " (" + str.tostring(bar_index - lastSigBar) + " bars)"
    lastCol  = str.startswith(lastSig, "BUY") ? bullCol : str.startswith(lastSig, "SELL") ? bearCol : neutCol
 
    table.cell(dash, 0, 0, "Timeframe",   text_color=dashTextCol, text_size=dSize, text_halign=text.align_left)
    table.cell(dash, 1, 0, tfLbl + " · " + modeTxt, text_color=dashTextCol, text_size=dSize)
    table.cell(dash, 0, 1, "Trend",       text_color=dashTextCol, text_size=dSize, text_halign=text.align_left)
    table.cell(dash, 1, 1, trendTxt,      text_color=trendCol, text_size=dSize)
    table.cell(dash, 0, 2, "Strength",    text_color=dashTextCol, text_size=dSize, text_halign=text.align_left)
    table.cell(dash, 1, 2, strTxt,        text_color=strCol, text_size=dSize)
    table.cell(dash, 0, 3, "Williams %R", text_color=dashTextCol, text_size=dSize, text_halign=text.align_left)
    table.cell(dash, 1, 3, f_num(wprV, "0.0") + " · " + zoneTxt, text_color=zoneCol, text_size=dSize)
    table.cell(dash, 0, 4, "Setup",       text_color=dashTextCol, text_size=dSize, text_halign=text.align_left)
    table.cell(dash, 1, 4, setupTxt,      text_color=setupCol, text_size=dSize)
    table.cell(dash, 0, 5, "Last Signal", text_color=dashTextCol, text_size=dSize, text_halign=text.align_left)
    table.cell(dash, 1, 5, lastSig + agoTxt, text_color=lastCol, text_size=dSize)

← 返回列表