Options IV Sigma Levels Lite [Strikeline]

strikeline · study · 323 行 · 点赞 14 · 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/
// © Strikeline
//@version=6
indicator("Options IV Sigma Levels Lite [Strikeline]", shorttitle = "IV Sigma Lite [Strikeline]", overlay = true, max_lines_count = 500, max_labels_count = 500)
G1 = "Levels"
horizon  = input.string("Daily", "Horizon", options = ["Daily", "Weekly", "Monthly"], group = G1, tooltip = "Levels are anchored to the previous period's close: yesterday, last week or last month.")
srcMode  = input.string("Auto", "Volatility source", options = ["Auto", "VIX family", "Historical volatility", "Manual"], group = G1, tooltip = "Auto: VIX / VXN / RVX for SPX-SPY, NDX-QQQ and RUT-IWM; historical volatility for everything else.")
useVix1d = input.bool(true, "Daily horizon: use VIX1D for SPX/SPY", group = G1)
hvLen    = input.int(20, "Historical volatility lookback (days)", minval = 5, maxval = 252, group = G1)
manualIv = input.float(20.0, "Manual IV (%)", minval = 1, maxval = 300, step = 0.5, group = G1)
midMode  = input.string("Off", "Midpoint levels", options = ["Off", "±0.5σ only", "All (±0.5σ, ±1.5σ, ±2.5σ)"], group = G1, tooltip = "Half-sigma levels drawn as thin dotted lines: nearby reaction zones between the main levels. ±2.5σ appears only when ±3σ is on.")
show3    = input.bool(true, "Show ±3σ", group = G1, tooltip = "The outer edge: useful around earnings and big events to see how far price can stretch.")
histN    = input.int(0, "Previous periods to keep", minval = 0, maxval = 20, group = G1)
showNext = input.bool(false, "Draw next session levels after the close", group = G1, tooltip = "Daily horizon: the dashboard always shows the next session's range once the session has closed. Turn this on to also draw those levels on the chart ahead of time from today's close and today's volatility close. They match the levels drawn at the next open. VIX1D settles about 15 minutes after the close.")
G2 = "Style"
upCol    = input.color(#2DD4BF, "Upper levels", group = G2)
dnCol    = input.color(#F59E5B, "Lower levels", group = G2)
midCol   = input.color(#8A94A3, "Anchor (previous close)", group = G2)
showLbl  = input.bool(true, "Show labels", group = G2)
lblPos   = input.string("Right edge", "Label position", options = ["Period start", "Right edge"], group = G2)
lblSz    = input.string("Normal", "Label size", options = ["Small", "Normal", "Large"], group = G2)
extMode  = input.string("Bars ahead", "Extend current levels", options = ["Bars ahead", "Session close", "Off"], group = G2, tooltip = "Session close: on intraday charts the Daily levels run ahead to today's 16:00 New York close, so the whole day's range is visible on the right. Bars ahead: a fixed number of bars.")
extBars  = input.int(15, "Bars ahead", minval = 0, maxval = 400, group = G2)
showDash = input.bool(false, "Show dashboard", group = G2, tooltip = "The full table of numbers. Off by default to keep the chart clean; the reading line below gives the short version.")
dashPos  = input.string("Top right", "Dashboard position", options = ["Top right", "Bottom right", "Top left", "Bottom left"], group = G2)
readOn   = input.bool(true, "Show reading", group = G2, tooltip = "One plain-language line on the chart: where price sits against the levels and how much of the expected move is used. A description of the chart, not a trade signal.")
readLang = input.string("English", "Reading language", options = ["English", "Arabic", "Spanish", "Turkish"], group = G2)
readPos  = input.string("Under the legend", "Reading position", options = ["Under the legend", "Bottom left", "Bottom right", "Top right"], group = G2)
readGap  = input.int(6, "Legend lines to skip", minval = 0, maxval = 20, group = G2, tooltip = "Under the legend: empty lines above the reading so it sits below the chart's indicator list. Raise it if the reading covers the legend, lower it if there is a gap.")
G3 = "0DTE mode (same-day options)"
zMode    = input.bool(false, "0DTE mode", group = G3, tooltip = "Daily horizon on an intraday chart: adds a theta clock (how much of today's time value is left), the move still priced in from now to the 16:00 New York close, and how far your strike is compared with it.")
zStrike  = input.float(0.0, "Strike (0 = off)", minval = 0, step = 0.5, group = G3, tooltip = "The same-day strike you are watching. Above price = call, below = put.")
zLate    = input.float(0.15, "Late: less than this share of the session left", minval = 0.05, maxval = 0.5, step = 0.05, group = G3)
tf   = horizon == "Daily" ? "D" : horizon == "Weekly" ? "W" : "M"
days = horizon == "Daily" ? 1.0 : horizon == "Weekly" ? 5.0 : 21.0
prevDayClose = request.security(syminfo.tickerid, "D", close[1], lookahead = barmerge.lookahead_on)
hvDaily      = request.security(syminfo.tickerid, "D", ta.stdev(math.log(close / close[1]), hvLen)[1] * math.sqrt(252) * 100, lookahead = barmerge.lookahead_on)
root  = syminfo.root
isSpx = root == "SPY" or root == "SPX" or root == "ES" or root == "MES" or root == "SPXW" or root == "SPX500"
isNdx = root == "QQQ" or root == "NDX" or root == "NQ" or root == "MNQ"
isRut = root == "IWM" or root == "RUT" or root == "RTY" or root == "M2K"
volSym  = isSpx ? (horizon == "Daily" and useVix1d ? "CBOE:VIX1D" : "CBOE:VIX") : isNdx ? "CBOE:VXN" : isRut ? "CBOE:RVX" : "CBOE:VIX"
volPrev = request.security(volSym, "D", close[1], lookahead = barmerge.lookahead_on, ignore_invalid_symbol = true)
vixPrev = request.security("CBOE:VIX", "D", close[1], lookahead = barmerge.lookahead_on)
familyIv = nz(volPrev, vixPrev)
hasFamily = isSpx or isNdx or isRut
float ivNow = switch srcMode
    "Manual"                => manualIv
    "Historical volatility" => hvDaily
    "VIX family"            => familyIv
    => hasFamily ? familyIv : hvDaily
string srcName = switch srcMode
    "Manual"                => "Manual IV"
    "Historical volatility" => "HV " + str.tostring(hvLen) + "d"
    "VIX family"            => (na(volPrev) ? "VIX" : str.replace(volSym, "CBOE:", ""))
    => hasFamily ? (na(volPrev) ? "VIX" : str.replace(volSym, "CBOE:", "")) : "HV " + str.tostring(hvLen) + "d"
newPeriod = timeframe.change(tf)
var float anchor = na
var float sigma  = na
var float ivUsed = na
var float pHigh  = na
var float pLow   = na
var array<line>  curLines = array.new<line>()
var array<label> curLbls  = array.new<label>()
var array<line>  oldLines = array.new<line>()
var array<float> curMults = array.new<float>()
var array<int>   oldCounts = array.new<int>()
var array<float> mults    = array.from(-3.0, -2.5, -2.0, -1.5, -1.0, -0.5, 0.0, 0.5, 1.0, 1.5, 2.0, 2.5, 3.0)
isMid(float m) => math.abs(m) == 0.5 or math.abs(m) == 1.5 or math.abs(m) == 2.5
mainSz = lblSz == "Large" ? size.large : lblSz == "Normal" ? size.normal : size.small
subSz  = lblSz == "Large" ? size.normal : lblSz == "Normal" ? size.small : size.tiny
lblSize(float m) => math.abs(m) == 1 ? mainSz : subSz
showLevel(float m) =>
    a = math.abs(m)
    a == 3.0 ? show3 : a == 2.5 ? (show3 and midMode != "Off" and midMode != "±0.5σ only") : a == 1.5 ? (midMode != "Off" and midMode != "±0.5σ only") : a == 0.5 ? midMode != "Off" : true
levelColor(float m) =>
    color base = m > 0 ? upCol : m < 0 ? dnCol : midCol
    isMid(m) ? color.new(base, 35) : base
levelText(float m) =>
    a = math.abs(m)
    string s = m == 0 ? "Prev close" : (m > 0 ? "+" : "−") + str.tostring(a, "#.#") + "σ"
    string p = a == 0.5 ? "  38%" : a == 1 ? "  68%" : a == 1.5 ? "  87%" : a == 2 ? "  95%" : a == 2.5 ? "  98.8%" : a == 3 ? "  99.7%" : ""
    s + p
if newPeriod and not na(prevDayClose) and not na(ivNow)
    // fade or remove the previous period's lines
    for [i, l] in curLines
        if histN > 0
            line.set_color(l, color.new(levelColor(curMults.get(i)), 65))
            oldLines.push(l)
        else
            line.delete(l)
    if histN > 0 and curLines.size() > 0
        oldCounts.push(curLines.size())
    curLines.clear()
    curMults.clear()
    for lb in curLbls
        label.delete(lb)
    curLbls.clear()
    while oldCounts.size() > histN
        n = oldCounts.shift()
        for k = 1 to n
            if oldLines.size() > 0
                line.delete(oldLines.shift())
    // new period levels
    anchor := prevDayClose
    ivUsed := ivNow
    sigma  := anchor * ivUsed / 100 * math.sqrt(days / 252)
    pHigh  := high
    pLow   := low
    for m in mults
        if not showLevel(m)
            continue
        a   = math.abs(m)
        lvl = anchor + m * sigma
        st  = m == 0 ? line.style_dashed : (a == 3 or isMid(m)) ? line.style_dotted : line.style_solid
        w   = a == 1 ? 2 : 1
        curLines.push(line.new(bar_index, lvl, bar_index + 1, lvl, color = levelColor(m), style = st, width = w))
        curMults.push(m)
        if showLbl
            lst = lblPos == "Period start" ? label.style_label_lower_left : label.style_label_left
            curLbls.push(label.new(bar_index, lvl, levelText(m) + "  " + str.tostring(lvl, format.mintick), style = lst, color = color.new(color.black, 100), textcolor = levelColor(m), size = lblSize(m)))
else if not na(anchor)
    pHigh := math.max(pHigh, high)
    pLow  := math.min(pLow, low)
for l in curLines
    line.set_x2(l, bar_index)
upH = anchor + 0.5 * sigma
up1 = anchor + sigma
up2 = anchor + 2 * sigma
dnH = anchor - 0.5 * sigma
dn1 = anchor - sigma
dn2 = anchor - 2 * sigma
// invisible ±1σ plots keep the main range inside the chart's auto-scale
plot(up1, "Scale +1σ", color.new(color.black, 100), editable = false, display = display.pane)
plot(dn1, "Scale −1σ", color.new(color.black, 100), editable = false, display = display.pane)
alertcondition(ta.crossover(high, upH), "Touched +0.5σ", "{{ticker}} touched +0.5σ (IV Sigma Lite)")
alertcondition(ta.crossover(high, up1), "Touched +1σ", "{{ticker}} touched +1σ (IV Sigma Lite)")
alertcondition(ta.crossover(high, up2), "Touched +2σ", "{{ticker}} touched +2σ (IV Sigma Lite)")
alertcondition(ta.crossunder(low, dnH), "Touched −0.5σ", "{{ticker}} touched −0.5σ (IV Sigma Lite)")
alertcondition(ta.crossunder(low, dn1), "Touched −1σ", "{{ticker}} touched −1σ (IV Sigma Lite)")
alertcondition(ta.crossunder(low, dn2), "Touched −2σ", "{{ticker}} touched −2σ (IV Sigma Lite)")
// ── Next session preview (Daily horizon): after the close, draw tomorrow's levels ahead of time ──
NYTZ = "America/New_York"
// lookahead_on returns the day's final values; safe here because they are only used after the session has closed.
// (Volatility indices keep printing ~15 min after the stock close, so without it Pine would hand back yesterday's value.)
dayCloseNow = request.security(syminfo.tickerid, "D", close, lookahead = barmerge.lookahead_on)
hvNowD      = request.security(syminfo.tickerid, "D", ta.stdev(math.log(close / close[1]), hvLen) * math.sqrt(252) * 100, lookahead = barmerge.lookahead_on)
volNow      = request.security(volSym, "D", close, lookahead = barmerge.lookahead_on, ignore_invalid_symbol = true)
volDay      = request.security(volSym, "D", time_tradingday, lookahead = barmerge.lookahead_on, ignore_invalid_symbol = true)
vixNowD     = request.security("CBOE:VIX", "D", close, lookahead = barmerge.lookahead_on)
famNext = nz(volNow, vixNowD)
float ivNext = switch srcMode
    "Manual"                => manualIv
    "Historical volatility" => hvNowD
    "VIX family"            => famNext
    => hasFamily ? famNext : hvNowD
tdy       = time_tradingday
// the volatility close must be from today's session; otherwise it is stale and we wait
volFresh  = srcMode == "Manual" or srcMode == "Historical volatility" or not hasFamily or (not na(volDay) and volDay == tdy)
sessClose = timestamp(NYTZ, year(tdy, "UTC"), month(tdy, "UTC"), dayofmonth(tdy, "UTC"), 16, 0)
sessOpen  = timestamp(NYTZ, year(tdy, "UTC"), month(tdy, "UTC"), dayofmonth(tdy, "UTC"), 9, 30)
nextSessionClose(int t) =>
    int d = t + 86400000
    while dayofweek(d, NYTZ) == dayofweek.saturday or dayofweek(d, NYTZ) == dayofweek.sunday
        d += 86400000
    timestamp(NYTZ, year(d, NYTZ), month(d, NYTZ), dayofmonth(d, NYTZ), 16, 0)
var array<line>  nxtLines = array.new<line>()
var array<label> nxtLbls  = array.new<label>()
float nxtSig  = na
int   nxtT    = na
bool  nxtWait = false
if barstate.islast
    for l in nxtLines
        line.delete(l)
    nxtLines.clear()
    for lb in nxtLbls
        label.delete(lb)
    nxtLbls.clear()
    nxtWait := horizon == "Daily" and timenow >= sessClose and not volFresh
    if horizon == "Daily" and timenow >= sessClose and volFresh and not na(dayCloseNow) and not na(ivNext)
        nxtSig := dayCloseNow * ivNext / 100 * math.sqrt(1 / 252.0)
        nxtT   := nextSessionClose(sessClose)
        for m in mults
            if not showNext or not showLevel(m)
                continue
            a   = math.abs(m)
            lvl = dayCloseNow + m * nxtSig
            st  = m == 0 ? line.style_dashed : (a == 3 or isMid(m)) ? line.style_dotted : line.style_solid
            nxtLines.push(line.new(time, lvl, nxtT, lvl, xloc = xloc.bar_time, color = color.new(levelColor(m), 25), style = st, width = a == 1 ? 2 : 1))
            if showLbl
                nxtLbls.push(label.new(nxtT, lvl, "Next  " + levelText(m) + "  " + str.tostring(lvl, format.mintick), xloc = xloc.bar_time, style = label.style_label_left, color = color.new(color.black, 100), textcolor = levelColor(m), size = lblSize(m)))
// run the current levels ahead of the last bar so the whole range is visible on the right
if barstate.islast
    int ahead = 0
    if extMode == "Bars ahead" or (extMode == "Session close" and (horizon != "Daily" or not timeframe.isintraday))
        ahead := extBars
    else if extMode == "Session close" and timenow < sessClose
        ahead := math.max(0, int(math.ceil((sessClose - time) / (timeframe.in_seconds() * 1000.0))) - 1)
    ahead := math.min(ahead, 400)
    for l in curLines
        line.set_x2(l, bar_index + ahead)
    if lblPos == "Right edge"
        for lb in curLbls
            label.set_x(lb, bar_index + ahead + 1)
            label.set_style(lb, label.style_label_left)
 
// ── 0DTE mode: theta clock, move left until the close, strike reach ──
zOn      = zMode and horizon == "Daily" and timeframe.isintraday
zInSess  = time >= sessOpen and time < sessClose
zNow     = barstate.islast ? math.max(time_close, math.min(timenow, sessClose)) : time_close
zRem     = math.max(0.0, math.min(1.0, (sessClose - zNow) / (sessClose - sessOpen)))
zValLeft = math.sqrt(zRem)
zNextHr  = zValLeft > 0 ? (zValLeft - math.sqrt(math.max(0.0, zRem - 60.0 / 390.0))) / zValLeft : na
zMove    = sigma * math.sqrt(zRem)
zIsCall  = zStrike > 0 and zStrike >= close
zNeed    = zStrike > 0 ? math.abs(zStrike - close) : na
zReach   = zStrike > 0 and zMove > 0 ? zNeed / zMove : na
zLateNow = zOn and zInSess and (zRem < zLate or (not na(zReach) and zReach > 1.0))
var line  zlUp = na
var line  zlDn = na
var line  zlK  = na
var label ztUp = na
var label ztDn = na
var label ztK  = na
if barstate.islast
    line.delete(zlUp)
    line.delete(zlDn)
    line.delete(zlK)
    label.delete(ztUp)
    label.delete(ztDn)
    label.delete(ztK)
    if zOn and zInSess and zMove > 0
        zlUp := line.new(time, close + zMove, sessClose, close + zMove, xloc.bar_time, color = color.new(upCol, 30), style = line.style_dashed, width = 1)
        zlDn := line.new(time, close - zMove, sessClose, close - zMove, xloc.bar_time, color = color.new(dnCol, 30), style = line.style_dashed, width = 1)
        ztUp := label.new(sessClose, close + zMove, "Move left +" + str.tostring(zMove, format.mintick), xloc.bar_time, style = label.style_label_left, color = color.new(color.black, 100), textcolor = upCol, size = subSz)
        ztDn := label.new(sessClose, close - zMove, "Move left −" + str.tostring(zMove, format.mintick), xloc.bar_time, style = label.style_label_left, color = color.new(color.black, 100), textcolor = dnCol, size = subSz)
        if zStrike > 0
            kc = zReach > 1.0 ? dnCol : #E6EAF0
            zlK := line.new(time, zStrike, sessClose, zStrike, xloc.bar_time, color = color.new(kc, 10), style = line.style_dotted, width = 2)
            ztK := label.new(sessClose, zStrike, str.tostring(zStrike) + (zIsCall ? " C" : " P"), xloc.bar_time, style = label.style_label_left, color = color.new(color.black, 100), textcolor = kc, size = mainSz)
fmtLeft(int ms) =>
    m = int(ms / 60000)
    (m >= 60 ? str.tostring(int(m / 60)) + "h " : "") + str.tostring(m % 60) + "m"
alertcondition(zLateNow and not zLateNow[1], "0DTE: late / strike out of reach", "{{ticker}}: 0DTE is late — decay fast or strike beyond the move left (IV Sigma Lite)")
 
// ── Reading: one plain-language line describing where price sits ──
iso(string t) => "⁦" + t + "⁩"
tx(string en, string ar, string es, string tr) => readLang == "Arabic" ? "‏" + ar : readLang == "Spanish" ? es : readLang == "Turkish" ? tr : en
readingLine(float ps, float used, float mxUp, float mxDn) =>
    bool   up  = ps >= 0
    float  a   = math.abs(ps)
    string sg  = up ? "+" : "−"
    string pw  = horizon == "Daily" ? tx("day", "يوم", "día", "gün") : horizon == "Weekly" ? tx("week", "أسبوع", "semana", "hafta") : tx("month", "شهر", "mes", "ay")
    string esC = horizon == "Daily" ? "Día" : horizon == "Weekly" ? "Semana" : "Mes"
    string u   = str.tostring(math.min(used, 999), "#") + "%"
    string l2  = str.tostring(anchor + (up ? 2 : -2) * sigma, format.mintick)
    string l3  = str.tostring(anchor + (up ? 3 : -3) * sigma, format.mintick)
    string l1  = str.tostring(anchor + (up ? 1 : -1) * sigma, format.mintick)
    string trW = up ? "üstünde" : "altında"
    string rd  = ""
    color  rc  = #E6EAF0
    if a >= 3
        rd := tx((up ? "Above " : "Below ") + sg + "3σ: an extreme move, very rare.", (up ? "فوق " : "تحت ") + iso(sg + "3σ") + ": حركة متطرفة ونادرة جداً.", (up ? "Por encima de " : "Por debajo de ") + sg + "3σ: un movimiento extremo, muy raro.", sg + "3σ " + trW + ": aşırı ve çok nadir bir hareket.")
        rc := #F87171
    else if a >= 2
        rd := tx((up ? "Above " : "Below ") + sg + "2σ: a rare move. Outer edge " + sg + "3σ at " + l3 + ".", (up ? "فوق " : "تحت ") + iso(sg + "2σ") + ": حركة نادرة. الحد الأقصى " + iso(sg + "3σ") + " عند " + iso(l3) + ".", (up ? "Por encima de " : "Por debajo de ") + sg + "2σ: un movimiento raro. Borde exterior " + sg + "3σ en " + l3 + ".", sg + "2σ " + trW + ": nadir bir hareket. Dış sınır " + sg + "3σ: " + l3 + ".")
        rc := #E8C547
    else if a >= 1
        rd := tx("Outside the normal range (" + sg + "1σ). Stretched; next edge " + sg + "2σ at " + l2 + ".", "برا النطاق الطبيعي (" + iso(sg + "1σ") + "). السعر ممتد، والحد التالي " + iso(sg + "2σ") + " عند " + iso(l2) + ".", "Fuera del rango normal (" + sg + "1σ). Estirado; siguiente borde " + sg + "2σ en " + l2 + ".", "Normal aralığın dışında (" + sg + "1σ). Gerilmiş; sonraki sınır " + sg + "2σ: " + l2 + ".")
        rc := #E8C547
    else if a >= 0.8
        rd := tx("Near the edge of a normal " + pw + ": " + sg + "1σ at " + l1 + ".", "قريب من حد النطاق الطبيعي: " + iso(sg + "1σ") + " عند " + iso(l1) + ".", "Cerca del borde de un " + pw + " normal: " + sg + "1σ en " + l1 + ".", "Normal bir " + pw + " sınırına yakın: " + sg + "1σ: " + l1 + ".")
    else if used >= 100
        rd := tx("Inside the range, but the full expected move is used: a wide " + pw + ".", "داخل النطاق، بس الحركة المتوقعة انستهلكت كاملة: " + pw + " واسع.", "Dentro del rango, pero el movimiento esperado ya se usó entero: un " + pw + " amplio.", "Aralık içinde, ama beklenen hareketin tamamı kullanıldı: geniş bir " + pw + ".")
    else if used < 40
        rd := tx("Quiet " + pw + ": inside the normal range, " + u + " of the expected move used.", pw + " هادي: داخل النطاق الطبيعي، وانستهلك " + iso(u) + " من الحركة المتوقعة.", esC + " tranquilo: dentro del rango normal, " + u + " del movimiento esperado usado.", "Sakin bir " + pw + ": normal aralık içinde, beklenen hareketin " + u + " kullanıldı.")
    else
        rd := tx("Normal " + pw + ": inside ±1σ, " + u + " of the expected move used.", pw + " طبيعي: داخل " + iso("±1σ") + "، وانستهلك " + iso(u) + " من الحركة المتوقعة.", esC + " normal: dentro de ±1σ, " + u + " del movimiento esperado usado.", "Normal bir " + pw + ": ±1σ içinde, beklenen hareketin " + u + " kullanıldı.")
    if a < 1 and (mxUp >= 1 or mxDn >= 1)
        rd += tx(" It touched the edge earlier and came back.", " لمس حد النطاق ورجع.", " Tocó el borde antes y volvió.", " Daha önce sınıra dokunup geri döndü.")
    [rd, rc]
 
pos = dashPos == "Top right" ? position.top_right : dashPos == "Bottom right" ? position.bottom_right : dashPos == "Top left" ? position.top_left : position.bottom_left
var table dash = table.new(pos, 2, 10, bgcolor = color.new(#0B0E11, 5), border_color = color.new(#1F2630, 0), border_width = 1)
cell(int r, string k, string v, color c) =>
    table.cell(dash, 0, r, k, text_color = #8A94A3, text_size = size.small, text_halign = text.align_left)
    table.cell(dash, 1, r, v, text_color = c, text_size = size.small, text_halign = text.align_right)
if showDash and barstate.islast and not na(sigma)
    posSig   = (close - anchor) / sigma
    usedPct  = (pHigh - pLow) / (2 * sigma) * 100
    table.cell(dash, 0, 0, "IV Sigma Lite · " + horizon, text_color = #E6EAF0, text_size = size.small, text_halign = text.align_left)
    table.cell(dash, 1, 0, "[Strikeline]", text_color = upCol, text_size = size.small, text_halign = text.align_right)
    cell(1, "Volatility", srcName + "  " + str.tostring(ivUsed, "0.0") + "%", #E6EAF0)
    cell(2, "Expected move (1σ)", "±" + str.tostring(sigma, format.mintick) + "  (" + str.tostring(sigma / anchor * 100, "0.00") + "%)", #E6EAF0)
    cell(3, "Price now", (posSig >= 0 ? "+" : "") + str.tostring(posSig, "0.00") + "σ", posSig >= 0 ? upCol : dnCol)
    cell(4, "Range so far", str.tostring(pHigh - pLow, format.mintick) + "  (" + str.tostring(usedPct, "#") + "% of ±1σ)", usedPct >= 100 ? dnCol : #E6EAF0)
    cell(5, "Anchor", "Prev close " + str.tostring(anchor, format.mintick), #8A94A3)
    if nxtWait
        cell(6, "Next session", "waiting for today's " + str.replace(volSym, "CBOE:", "") + " close", #8A94A3)
    else if not na(nxtSig)
        cell(6, "Next · " + str.format_time(nxtT, "EEE dd MMM", NYTZ), "±" + str.tostring(nxtSig, format.mintick) + "  " + str.tostring(dayCloseNow - nxtSig, format.mintick) + " – " + str.tostring(dayCloseNow + nxtSig, format.mintick), upCol)
    else
        table.clear(dash, 0, 6, 1, 6)
    if zOn and zInSess
        cell(7, "0DTE · time left", fmtLeft(sessClose - zNow) + "  ·  value left ≈" + str.tostring(zValLeft * 100, "#") + "%", zRem < zLate ? dnCol : #E6EAF0)
        cell(8, "Move left · next hour", "±" + str.tostring(zMove, format.mintick) + "  ·  " + (na(zNextHr) ? "—" : zNextHr >= 0.999 ? "all of it" : "−" + str.tostring(zNextHr * 100, "#") + "%"), #E6EAF0)
        cell(9, "Strike", zStrike > 0 ? str.tostring(zStrike) + (zIsCall ? " C" : " P") + "  needs " + (zIsCall ? "+" : "−") + str.tostring(zNeed, format.mintick) + "  (" + str.tostring(zReach, "0.0") + "× move left)" : "set one in settings", na(zReach) ? #8A94A3 : zReach > 1.0 ? dnCol : zReach > 0.5 ? #E8C547 : upCol)
    else if zMode
        cell(7, "0DTE mode", horizon != "Daily" or not timeframe.isintraday ? "needs Daily horizon, intraday chart" : "session closed", #8A94A3)
        table.clear(dash, 0, 8, 1, 9)
    else
        table.clear(dash, 0, 7, 1, 9)
 
// reading line: its own small box, shown even when the dashboard is off
rpos = readPos == "Bottom left" ? position.bottom_left : readPos == "Bottom right" ? position.bottom_right : readPos == "Top right" ? position.top_right : position.top_left
rgap = readPos == "Under the legend" ? readGap : 0
var table rtab = table.new(rpos, 1, 21)
if readOn and barstate.islast and not na(sigma)
    [rd, rc] = readingLine((close - anchor) / sigma, (pHigh - pLow) / (2 * sigma) * 100, (pHigh - anchor) / sigma, (anchor - pLow) / sigma)
    if rgap > 0
        for r = 0 to rgap - 1
            table.cell(rtab, 0, r, " ", text_size = size.normal)
    table.cell(rtab, 0, rgap, readLang == "Arabic" ? "‏" + iso("IV Sigma") + " · " + rd : "IV Sigma · " + rd, text_color = rc, text_size = size.normal, text_halign = text.align_left, bgcolor = color.new(#0B0E11, 10))

← 返回列表