10Cent NEWS - Economic Calendar and Release Reaction

Techtrade10Cent · study · 807 行 · 点赞 1 · TradingView 原页

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

Pine Script

//@version=6
// ═══════════════════════════════════════════════════════════════
//  10¢ NEWS v1 — by 10Cent
//  World economic calendar on the chart: 🔴 / 🟠 / 🟡 news windows
//  for 9 currencies, heads-up alerts before release, and a one-line
//  trade direction after release (data vs previous + price reaction).
//  Calendar feed: Forex Factory via toodegrees' public Pine Seeds feed
//  and libraries (MPL-2.0). Released figures: TradingView economic data.
// ═══════════════════════════════════════════════════════════════
indicator("10¢ NEWS v1", shorttitle="10¢ NEWS", overlay=true, max_boxes_count=500, max_labels_count=500)
import toodegrees/forex_factory_utility/17 as ffUtil
import toodegrees/forex_factory_decoding/46 as ffDec
 
// ── suite palette ─────────────────────────────────────────────
color BR_BULL = #1E8E7E
color BR_BEAR = #D9453A
color T_NONE  = color.new(color.black, 100)
color C_HI    = #E53935
color C_MD    = #FB8C00
color C_LO    = #FBC02D
color C_HOL   = #9E9E9E
PHDR = color.new(chart.fg_color, 84)
PVAL = color.new(chart.fg_color, 0)
PSEC = color.new(chart.fg_color, 55)
PGRN = color.new(BR_BULL, 0)
PRED = color.new(BR_BEAR, 0)
PAMB = color.new(#ffb74d, 0)
 
// ═══════════════════════════════════════════════════════════════
//  INPUTS
// ═══════════════════════════════════════════════════════════════
grpU = "⓪ Display"
showBoard = input.bool(false, "📊 Show Dashboard", group=grpU, tooltip="Master switch for the news board, off by default. Windows on the chart, the guard export and alerts keep working without it.")
showLine  = input.bool(true, "  One-line status when the dashboard is off", group=grpU, tooltip="With the board off, the call or the next red-folder event stays as one line on the chart.")
lnPosIn   = input.string("Top right", "  …status line position", options=["Top right", "Top center", "Bottom right", "Bottom center", "Bottom left"], group=grpU)
lnRow = input.int(11, "  …row in the stack", minval=1, maxval=16, group=grpU, tooltip="One-liners that share a corner stack by this row (row 1 = closest to the corner). Give each indicator its own row and 4+ can be read at once.")
lnR0 = str.startswith(lnPosIn, "Top") ? lnRow - 1 : 0
boardPos  = input.string("Top right", "  …board position", options=["Top right", "Top left", "Bottom right", "Bottom left"], group=grpU)
boardRows = input.int(6, "  …rows per section", minval=1, maxval=15, group=grpU)
boardFocus = input.string("Session", "  …focus", options=["Session", "All"], group=grpU, tooltip="Session: the live session's own currencies first (New York clock — Asia 18:00–02:00 JPY AUD NZD CNY · London 02:00–08:00 EUR GBP CHF · New York 08:00–17:00 USD CAD), then everything else coming up. Windows and alerts always cover every currency you switched on.")
panelSize = input.string("Small", "Panel text", options=["Tiny", "Small", "Normal"], group=grpU)
 
grpN = "① News feed"
showHi  = input.bool(true,  "🔴 High",    inline="imp", group=grpN)
showMd  = input.bool(true,  "🟠 Medium",  inline="imp", group=grpN)
showLo  = input.bool(true,  "🟡 Low",     inline="imp", group=grpN)
showHol = input.bool(false, "⚪ Holiday", inline="imp", group=grpN, tooltip="Forex Factory impact folders: red = high, orange = medium, yellow = low.")
curMode = input.string("All currencies", "Currencies", options=["All currencies", "Chart symbol only", "Pick below"], group=grpN)
cUSD = input.bool(true, "USD", inline="c1", group=grpN)
cEUR = input.bool(true, "EUR", inline="c1", group=grpN)
cGBP = input.bool(true, "GBP", inline="c1", group=grpN)
cJPY = input.bool(true, "JPY", inline="c2", group=grpN)
cCHF = input.bool(true, "CHF", inline="c2", group=grpN)
cCAD = input.bool(true, "CAD", inline="c2", group=grpN)
cAUD = input.bool(true, "AUD", inline="c3", group=grpN)
cNZD = input.bool(true, "NZD", inline="c3", group=grpN)
cCNY = input.bool(true, "CNY", inline="c3", group=grpN)
grpT = "① News types"
tInf  = input.bool(true, "Inflation",        inline="t1", group=grpT, tooltip="CPI · PPI · PCE · inflation")
tJob  = input.bool(true, "Jobs",             inline="t1", group=grpT, tooltip="NFP · employment · unemployment · claims · earnings · ADP · JOLTS")
tCB   = input.bool(true, "Central banks",    inline="t2", group=grpT, tooltip="Rate decisions · statements · minutes · speeches · press conferences")
tGro  = input.bool(true, "Growth & sentiment", inline="t2", group=grpT, tooltip="GDP · PMI / ISM · retail sales · production · confidence · sentiment")
tHou  = input.bool(true, "Housing",          inline="t3", group=grpT)
tTrd  = input.bool(true, "Trade & current account", inline="t3", group=grpT)
tAuc  = input.bool(true, "Bond auctions",    inline="t4", group=grpT)
tOth  = input.bool(true, "Other",            inline="t4", group=grpT)
tzSel = input.string("New York", "Show times in", options=["New York", "London", "Dubai", "Tokyo", "Sydney", "Chart time zone"], group=grpN)
 
grpW = "② Windows on chart"
drawMin = input.string("Medium", "Draw windows from", options=["High", "Medium", "Low"], group=grpW)
preHi  = input.int(15, "🔴 minutes before", inline="wh", group=grpW, minval=0)
postHi = input.int(30, "after",             inline="wh", group=grpW, minval=0)
preMd  = input.int(10, "🟠 minutes before", inline="wm", group=grpW, minval=0)
postMd = input.int(15, "after",             inline="wm", group=grpW, minval=0)
preLo  = input.int(5,  "🟡 minutes before", inline="wl", group=grpW, minval=0)
postLo = input.int(5,  "after",             inline="wl", group=grpW, minval=0)
lblTier = input.string("Normal", "Chart label size", options=["Small", "Normal", "Large"], group=grpW, tooltip="Same three-level sizing as the rest of the 10¢ suite. Large = one step up for phones.")
string SZ_D = lblTier == "Small" ? size.tiny : lblTier == "Large" ? size.normal : size.small
string SZ_C = lblTier == "Large" ? size.small : size.tiny
 
grpD = "③ Direction after release"
dirMin   = input.string("Medium", "Call direction for", options=["High", "Medium"], group=grpD)
preRange = input.int(15, "Pre-news range (minutes)", minval=1, group=grpD, tooltip="The high/low of the minutes just before the release. The price call needs closes beyond it.")
confBars = input.int(2, "Closes beyond the range to confirm", minval=1, maxval=5, group=grpD)
expMin   = input.int(60, "Call window after release (minutes)", minval=5, group=grpD, tooltip="A break must confirm inside this window. One flip is allowed if the first break fails and price confirms the other side (fake-out).")
mvMin    = input.int(15, "Measure each release's move after (minutes)", minval=1, group=grpD, tooltip="Every released event, low impact included, shows how far price moved this many minutes after the release, on the board.")
holdMin  = input.int(120, "Keep the call on screen (minutes)", minval=5, group=grpD)
useData  = input.bool(true, "Use released data vs previous", group=grpD, tooltip="Compares the new released value with the previous one (TradingView economic data). Forecast/consensus is not available inside Pine, so this is 'higher or lower than last time', not 'beat or miss'. Covered: USD CPI, core CPI, NFP, ADP, unemployment, claims, AHE, retail sales, GDP, Fed rate; EUR/GBP CPI, core CPI, rates, GDP, unemployment; CAD CPI, rate, unemployment; AUD rate, unemployment; JPY rate, CPI; NZD, CHF rates.")
fcIn     = input.text_area("", "Forecasts (optional)", group=grpD, tooltip="One per line:  CUR event = value   e.g.\nUSD CPI m/m = 0.3\nUSD Core CPI m/m = 0.3\nUSD Non-Farm = 150\nGBP CPI y/y = 2.1\nThe event text only needs to be part of the Forex Factory title. % and K are ignored — type numbers in the same units as the board's 'prev'. With a forecast the call is beat / miss; without one it is actual vs previous.")
dataMap  = input.string("Auto", "Strong data for a currency means chart…", options=["Auto", "UP", "DOWN"], group=grpD, tooltip="Auto: strong data for the chart's base currency = chart UP, for its quote currency (USD on XAUUSD, NQ, ES) = chart DOWN. Currencies not in the chart symbol don't vote.")
 
grpA = "④ Alerts"
alMin  = input.string("High", "Heads-up alerts for", options=["High", "Medium"], group=grpA)
lead1  = input.int(30, "First heads-up (minutes before)", minval=1, group=grpA)
lead2  = input.int(5,  "Final heads-up (minutes before)", minval=1, group=grpA)
alCall = input.bool(true, "Alert when the direction is called", group=grpA, tooltip="Create ONE TradingView alert on this script with condition 'Any alert() function call'.")
 
if timeframe.in_seconds() > 14400
    runtime.error("10¢ NEWS: use 4H or lower.")
 
// ═══════════════════════════════════════════════════════════════
//  HELPERS
// ═══════════════════════════════════════════════════════════════
f_rk(color c) => c == color.red ? 3 : c == color.orange ? 2 : c == color.yellow ? 1 : 0
f_rkMin(string s) => s == "High" ? 3 : s == "Medium" ? 2 : 1
int DRAW_RK  = f_rkMin(drawMin)
int DIR_RK   = f_rkMin(dirMin)
int ALERT_RK = f_rkMin(alMin)
f_on(int rk) => rk == 3 ? showHi : rk == 2 ? showMd : rk == 1 ? showLo : showHol
f_dot(int rk) => rk == 3 ? "🔴" : rk == 2 ? "🟠" : rk == 1 ? "🟡" : "⚪"
f_icol(int rk) => rk == 3 ? C_HI : rk == 2 ? C_MD : rk == 1 ? C_LO : C_HOL
f_pre(int rk) => (rk == 3 ? preHi : rk == 2 ? preMd : preLo) * 60000
f_post(int rk) => (rk == 3 ? postHi : rk == 2 ? postMd : postLo) * 60000
f_curOn(string c) =>
    bool picked = switch c
        "USD" => cUSD
        "EUR" => cEUR
        "GBP" => cGBP
        "JPY" => cJPY
        "CHF" => cCHF
        "CAD" => cCAD
        "AUD" => cAUD
        "NZD" => cNZD
        "CNY" => cCNY
        => false
    curMode == "All currencies" ? true : curMode == "Chart symbol only" ? (c == syminfo.basecurrency or c == syminfo.currency) : picked
 
f_has(string t, string k) => str.contains(t, k)
f_cat(string ttl) =>
    string t = str.lower(ttl)
    f_has(t, "auction") ? "AUC" :
     f_has(t, "cpi") or f_has(t, "ppi") or f_has(t, "pce") or f_has(t, "inflation") or f_has(t, "price index") ? "INF" :
     f_has(t, "employment") or f_has(t, "non-farm") or f_has(t, "payroll") or f_has(t, "claims") or f_has(t, "earnings") or f_has(t, "jolts") or f_has(t, "job") or f_has(t, "claimant") or f_has(t, "wage") ? "JOB" :
     f_has(t, "rate") and not f_has(t, "mortgage") or f_has(t, "fomc") or f_has(t, "statement") or f_has(t, "minutes") or f_has(t, "speaks") or f_has(t, "press conference") or f_has(t, "monetary") or f_has(t, "policy") or f_has(t, "summary of opinions") or f_has(t, "testifies") ? "CB" :
     f_has(t, "housing") or f_has(t, "home") or f_has(t, "building") or f_has(t, "permits") or f_has(t, "mortgage") or f_has(t, "hpi") ? "HOU" :
     f_has(t, "trade balance") or f_has(t, "current account") or f_has(t, "exports") or f_has(t, "imports") ? "TRD" :
     f_has(t, "gdp") or f_has(t, "pmi") or f_has(t, "ism") or f_has(t, "retail") or f_has(t, "production") or f_has(t, "sentiment") or f_has(t, "confidence") or f_has(t, "spending") or f_has(t, "orders") or f_has(t, "business") or f_has(t, "lending") or f_has(t, "economy") ? "GRO" : "OTH"
f_catOn(string ttl) =>
    switch f_cat(ttl)
        "INF" => tInf
        "JOB" => tJob
        "CB"  => tCB
        "GRO" => tGro
        "HOU" => tHou
        "TRD" => tTrd
        "AUC" => tAuc
        => tOth
 
string TZ = switch tzSel
    "New York" => "America/New_York"
    "London"   => "Europe/London"
    "Dubai"    => "Asia/Dubai"
    "Tokyo"    => "Asia/Tokyo"
    "Sydney"   => "Australia/Sydney"
    => syminfo.timezone
string TZTAG = switch tzSel
    "New York" => "NY"
    "London"   => "LDN"
    "Dubai"    => "DXB"
    "Tokyo"    => "TYO"
    "Sydney"   => "SYD"
    => ""
f_hm(int t)  => str.format_time(t, "HH:mm", TZ) + (TZTAG == "" ? "" : " " + TZTAG)
f_dhm(int t) => str.format_time(t, "EEE HH:mm", TZ)
f_dur(int ms) =>
    int m = int(math.max(0, math.round(ms / 60000.0)))
    m >= 1440 ? str.tostring(math.floor(m / 1440)) + "d " + str.tostring(math.floor((m % 1440) / 60)) + "h" : m >= 60 ? str.tostring(math.floor(m / 60)) + "h " + str.tostring(m % 60) + "m" : str.tostring(m) + "m"
f_cut(string s, int n) => str.length(s) > n ? str.substring(s, 0, n - 1) + "…" : s
f_num(float v) => math.abs(v) >= 1000 ? str.tostring(v, "#,###") : str.tostring(v, "#.##")
f_arw(int d) => d > 0 ? "▲" : d < 0 ? "▼" : "·"
 
// ═══════════════════════════════════════════════════════════════
//  CALENDAR FEED  (toodegrees · Forex Factory · Pine Seeds)
// ═══════════════════════════════════════════════════════════════
requestData() =>
    [request.seed("seed_toodegrees_toogit","TOODEGREES_FOREX_FACTORY_SLOT_1",str.tostring(open)+","+str.tostring(high)+","+str.tostring(low)+","+str.tostring(close)+","+str.tostring(volume)),
     request.seed("seed_toodegrees_toogit","TOODEGREES_FOREX_FACTORY_SLOT_2",str.tostring(open)+","+str.tostring(high)+","+str.tostring(low)+","+str.tostring(close)+","+str.tostring(volume)),
     request.seed("seed_toodegrees_toogit","TOODEGREES_FOREX_FACTORY_SLOT_3",str.tostring(open)+","+str.tostring(high)+","+str.tostring(low)+","+str.tostring(close)+","+str.tostring(volume)),
     request.seed("seed_toodegrees_toogit","TOODEGREES_FOREX_FACTORY_SLOT_4",str.tostring(open)+","+str.tostring(high)+","+str.tostring(low)+","+str.tostring(close)+","+str.tostring(volume)),
     request.seed("seed_toodegrees_toogit","TOODEGREES_FOREX_FACTORY_SLOT_5",str.tostring(open)+","+str.tostring(high)+","+str.tostring(low)+","+str.tostring(close)+","+str.tostring(volume)),
     request.seed("seed_toodegrees_toogit","TOODEGREES_FOREX_FACTORY_SLOT_6",str.tostring(open)+","+str.tostring(high)+","+str.tostring(low)+","+str.tostring(close)+","+str.tostring(volume)),
     request.seed("seed_toodegrees_toogit","TOODEGREES_FOREX_FACTORY_SLOT_7",str.tostring(open)+","+str.tostring(high)+","+str.tostring(low)+","+str.tostring(close)+","+str.tostring(volume)),
     request.seed("seed_toodegrees_toogit","TOODEGREES_FOREX_FACTORY_SLOT_8",str.tostring(open)+","+str.tostring(high)+","+str.tostring(low)+","+str.tostring(close)+","+str.tostring(volume)),
     request.seed("seed_toodegrees_toogit","TOODEGREES_FOREX_FACTORY_SLOT_9",str.tostring(open)+","+str.tostring(high)+","+str.tostring(low)+","+str.tostring(close)+","+str.tostring(volume))]
 
method processData(ffUtil.News[] N, string S1, string S2, string S3, string S4, string S5, string S6, string S7, string S8, string S9) =>
    ffDec.readNews(N,S1), ffDec.readNews(N,S2), ffDec.readNews(N,S3)
    ffDec.readNews(N,S4), ffDec.readNews(N,S5), ffDec.readNews(N,S6)
    ffDec.readNews(N,S7), ffDec.readNews(N,S8), ffDec.readNews(N,S9)
 
// ═══════════════════════════════════════════════════════════════
//  RELEASED DATA  (TradingView economic data · last 3 distinct values)
// ═══════════════════════════════════════════════════════════════
f_eco(string ctry, string fld) =>
    v = request.economic(ctry, fld, gaps=barmerge.gaps_off, ignore_invalid_symbol=true)
    var float c0 = na
    var float c1 = na
    var float c2 = na
    var int   ct = na
    if not na(v) and (na(c0) or v != c0)
        c2 := c1
        c1 := c0
        c0 := v
        ct := time
    [c0, c1, c2, ct]
 
var ecoK  = array.new_string()
var ecoV0 = array.new_float()
var ecoV1 = array.new_float()
var ecoV2 = array.new_float()
var ecoT  = array.new_int()
f_put(string k, float v0, float v1, float v2, int t) =>
    i = ecoK.indexof(k)
    if i < 0
        ecoK.push(k), ecoV0.push(v0), ecoV1.push(v1), ecoV2.push(v2), ecoT.push(t)
    else
        ecoV0.set(i, v0), ecoV1.set(i, v1), ecoV2.set(i, v2), ecoT.set(i, t)
 
[u1a, u1b, u1c, u1t] = f_eco("US", "CIR")
f_put("US|CIR", u1a, u1b, u1c, u1t)
[u2a, u2b, u2c, u2t] = f_eco("US", "IRMM")
f_put("US|IRMM", u2a, u2b, u2c, u2t)
[u3a, u3b, u3c, u3t] = f_eco("US", "IRYY")
f_put("US|IRYY", u3a, u3b, u3c, u3t)
[u4a, u4b, u4c, u4t] = f_eco("US", "EC")
f_put("US|EC", u4a, u4b, u4c, u4t)
[u5a, u5b, u5c, u5t] = f_eco("US", "NFP")
f_put("US|NFP", u5a, u5b, u5c, u5t)
[u6a, u6b, u6c, u6t] = f_eco("US", "UR")
f_put("US|UR", u6a, u6b, u6c, u6t)
[u7a, u7b, u7c, u7t] = f_eco("US", "IJC")
f_put("US|IJC", u7a, u7b, u7c, u7t)
[u8a, u8b, u8c, u8t] = f_eco("US", "AHE")
f_put("US|AHE", u8a, u8b, u8c, u8t)
[u9a, u9b, u9c, u9t] = f_eco("US", "INTR")
f_put("US|INTR", u9a, u9b, u9c, u9t)
[uAa, uAb, uAc, uAt] = f_eco("US", "RSMM")
f_put("US|RSMM", uAa, uAb, uAc, uAt)
[uBa, uBb, uBc, uBt] = f_eco("US", "GDPGA")
f_put("US|GDPGA", uBa, uBb, uBc, uBt)
[e1a, e1b, e1c, e1t] = f_eco("EU", "IRYY")
f_put("EU|IRYY", e1a, e1b, e1c, e1t)
[e2a, e2b, e2c, e2t] = f_eco("EU", "CIR")
f_put("EU|CIR", e2a, e2b, e2c, e2t)
[e3a, e3b, e3c, e3t] = f_eco("EU", "INTR")
f_put("EU|INTR", e3a, e3b, e3c, e3t)
[e4a, e4b, e4c, e4t] = f_eco("EU", "GDPQQ")
f_put("EU|GDPQQ", e4a, e4b, e4c, e4t)
[e5a, e5b, e5c, e5t] = f_eco("EU", "UR")
f_put("EU|UR", e5a, e5b, e5c, e5t)
[g1a, g1b, g1c, g1t] = f_eco("GB", "IRYY")
f_put("GB|IRYY", g1a, g1b, g1c, g1t)
[g2a, g2b, g2c, g2t] = f_eco("GB", "CIR")
f_put("GB|CIR", g2a, g2b, g2c, g2t)
[g3a, g3b, g3c, g3t] = f_eco("GB", "INTR")
f_put("GB|INTR", g3a, g3b, g3c, g3t)
[g4a, g4b, g4c, g4t] = f_eco("GB", "GDPQQ")
f_put("GB|GDPQQ", g4a, g4b, g4c, g4t)
[g5a, g5b, g5c, g5t] = f_eco("GB", "UR")
f_put("GB|UR", g5a, g5b, g5c, g5t)
[k1a, k1b, k1c, k1t] = f_eco("CA", "IRYY")
f_put("CA|IRYY", k1a, k1b, k1c, k1t)
[k2a, k2b, k2c, k2t] = f_eco("CA", "INTR")
f_put("CA|INTR", k2a, k2b, k2c, k2t)
[k3a, k3b, k3c, k3t] = f_eco("CA", "UR")
f_put("CA|UR", k3a, k3b, k3c, k3t)
[a1a, a1b, a1c, a1t] = f_eco("AU", "INTR")
f_put("AU|INTR", a1a, a1b, a1c, a1t)
[a2a, a2b, a2c, a2t] = f_eco("AU", "UR")
f_put("AU|UR", a2a, a2b, a2c, a2t)
[j1a, j1b, j1c, j1t] = f_eco("JP", "INTR")
f_put("JP|INTR", j1a, j1b, j1c, j1t)
[j2a, j2b, j2c, j2t] = f_eco("JP", "IRYY")
f_put("JP|IRYY", j2a, j2b, j2c, j2t)
[n1a, n1b, n1c, n1t] = f_eco("NZ", "INTR")
f_put("NZ|INTR", n1a, n1b, n1c, n1t)
[s1a, s1b, s1c, s1t] = f_eco("CH", "INTR")
f_put("CH|INTR", s1a, s1b, s1c, s1t)
 
// forecasts typed by the trader → [currency, title part, value]
var fcCur = array.new_string()
var fcKey = array.new_string()
var fcVal = array.new_float()
if barstate.isfirst and str.length(fcIn) > 0
    for ln in str.split(fcIn, "\n")
        parts = str.split(ln, "=")
        if parts.size() == 2
            string lft = str.trim(parts.get(0))
            float  v   = str.tonumber(str.trim(str.replace_all(str.replace_all(str.replace_all(parts.get(1), "%", ""), "K", ""), "k", "")))
            if str.length(lft) > 4 and not na(v)
                fcCur.push(str.upper(str.substring(lft, 0, 3)))
                fcKey.push(str.lower(str.trim(str.substring(lft, 3))))
                fcVal.push(v)
f_fc(string cur, string ttl) =>
    float r = na
    int   best = 0
    string tl = str.lower(ttl)
    if fcCur.size() > 0
        for j = 0 to fcCur.size() - 1
            string kj = fcKey.get(j)
            if fcCur.get(j) == cur and str.contains(tl, kj) and str.length(kj) > best
                r    := fcVal.get(j)
                best := str.length(kj)
    r
 
// Forex Factory title → economic series · polarity (−1 = higher is weaker) · acc (compare change vs previous change)
f_map(string cur, string ttl) =>
    string k = ""
    int    p = 1
    bool   a = false
    if cur == "USD"
        if str.contains(ttl, "Core CPI")
            k := "US|CIR"
        else if str.contains(ttl, "CPI m/m")
            k := "US|IRMM"
        else if str.contains(ttl, "CPI y/y")
            k := "US|IRYY"
        else if str.contains(ttl, "ADP")
            k := "US|EC"
        else if str.contains(ttl, "Non-Farm")
            k := "US|NFP"
        else if str.contains(ttl, "Unemployment Rate")
            k := "US|UR", p := -1
        else if str.contains(ttl, "Unemployment Claims")
            k := "US|IJC", p := -1
        else if str.contains(ttl, "Average Hourly Earnings")
            k := "US|AHE", a := true
        else if str.contains(ttl, "Federal Funds Rate") or str.contains(ttl, "FOMC Statement")
            k := "US|INTR"
        else if str.contains(ttl, "Retail Sales")
            k := "US|RSMM"
        else if str.contains(ttl, "GDP")
            k := "US|GDPGA"
    else if cur == "EUR" or cur == "GBP"
        cc = cur == "EUR" ? "EU|" : "GB|"
        if str.contains(ttl, "Core CPI")
            k := cc + "CIR"
        else if str.contains(ttl, "CPI")
            k := cc + "IRYY"
        else if str.contains(ttl, "Refinancing Rate") or str.contains(ttl, "Monetary Policy Statement") or str.contains(ttl, "Official Bank Rate") or str.contains(ttl, "Deposit Rate")
            k := cc + "INTR"
        else if str.contains(ttl, "GDP")
            k := cc + "GDPQQ"
        else if str.contains(ttl, "Unemployment Rate") or str.contains(ttl, "Claimant Count")
            k := cc + "UR", p := -1
    else if cur == "CAD"
        if str.contains(ttl, "CPI")
            k := "CA|IRYY"
        else if str.contains(ttl, "Overnight Rate")
            k := "CA|INTR"
        else if str.contains(ttl, "Unemployment Rate")
            k := "CA|UR", p := -1
    else if cur == "AUD"
        if str.contains(ttl, "Cash Rate")
            k := "AU|INTR"
        else if str.contains(ttl, "Unemployment Rate")
            k := "AU|UR", p := -1
    else if cur == "JPY"
        if str.contains(ttl, "Policy Rate")
            k := "JP|INTR"
        else if str.contains(ttl, "CPI")
            k := "JP|IRYY"
    else if cur == "NZD"
        if str.contains(ttl, "Cash Rate")
            k := "NZ|INTR"
    else if cur == "CHF"
        if str.contains(ttl, "Policy Rate")
            k := "CH|INTR"
    [k, p, a]
 
// strong data for a currency → chart direction (0 = currency not in this symbol)
f_cs(string cur) =>
    bool isBase  = cur == syminfo.basecurrency
    bool isQuote = cur == syminfo.currency
    not (isBase or isQuote) ? 0 : dataMap == "UP" ? 1 : dataMap == "DOWN" ? -1 : isBase ? 1 : -1
 
// ═══════════════════════════════════════════════════════════════
//  EVENTS & CLUSTERS  (events at the same minute = one cluster)
// ═══════════════════════════════════════════════════════════════
type Ev
    int    t
    string cur
    string ttl
    int    rk
 
type Cl
    int       t
    int       rk
    string    cur
    array<Ev> evs
    box       bx
    label     lb
    bool      frozen = false
    float     preH
    float     preL
    float     wH
    float     wL
    int       upN = 0
    int       dnN = 0
    int       pDir = 0
    bool      pFake = false
    bool      dDone = false
    bool      dAny = false
    int       dDir = 0
    string    dTxt = ""
    float     px0
    float     mv
 
f_head(Cl c, bool withCur = true) =>
    Ev best = c.evs.get(0)
    for e in c.evs
        if e.rk > best.rk
            best := e
    (withCur ? best.cur + " " : "") + best.ttl + (c.evs.size() > 1 ? " +" + str.tostring(c.evs.size() - 1) : "")
 
// ── track record on THIS chart's symbol (auto per asset) ─────────
var stN   = map.new<string, int>()     // releases seen
var stUp  = map.new<string, int>()     // moved up after release
var stPts = map.new<string, float>()   // sum of |move| in price
var stDC  = map.new<string, int>()     // releases with a known data sign
var stDS  = map.new<string, int>()     // …where price moved the same way as the currency-strength sign
 
// currency-strength sign of one released event (+1 stronger, −1 weaker, 0 unknown)
f_evSign(Ev e, int ct) =>
    int r = 0
    [k, p, a] = f_map(e.cur, e.ttl)
    int i = k == "" ? -1 : ecoK.indexof(k)
    if i >= 0
        t0 = ecoT.get(i)
        v0 = ecoV0.get(i)
        v1 = ecoV1.get(i)
        v2 = ecoV2.get(i)
        float fc = f_fc(e.cur, e.ttl)
        if not na(t0) and t0 >= ct - 20 * 3600000 and not na(v1) and (not na(fc) or not a or not na(v2))
            d = not na(fc) ? v0 - fc : a ? (v0 - v1) - (v1 - v2) : v0 - v1
            r := int(math.sign(d)) * p
    r
 
// learned link: does stronger data move this symbol up (+1), down (−1), or no link (0)? na = not enough history
f_learn(string key) =>
    int dc = stDC.get(key)
    int ds = stDS.get(key)
    float sh = na(dc) or dc < 8 ? na : nz(ds) / dc
    na(sh) ? int(na) : sh >= 0.6 ? 1 : sh <= 0.4 ? -1 : 0
f_csL(Ev e) =>
    int l = f_learn(e.cur + " " + e.ttl)
    na(l) ? f_cs(e.cur) : l
 
f_vote(Cl c) =>
    int    sum = 0
    bool   any = false
    string tx  = ""
    for e in c.evs
        [k, p, a] = f_map(e.cur, e.ttl)
        if k != ""
            i = ecoK.indexof(k)
            if i >= 0
                t0 = ecoT.get(i)
                v0 = ecoV0.get(i)
                v1 = ecoV1.get(i)
                v2 = ecoV2.get(i)
                float fc = f_fc(e.cur, e.ttl)
                if not na(t0) and t0 >= c.t - 20 * 3600000 and not na(v1) and (not na(fc) or not a or not na(v2))
                    d  = not na(fc) ? v0 - fc : a ? (v0 - v1) - (v1 - v2) : v0 - v1
                    s  = int(math.sign(d)) * p
                    sum += s * f_csL(e)
                    any := true
                    if tx == ""
                        tx := e.cur + " " + f_cut(e.ttl, 18) + " " + (not na(fc) ? f_num(v0) + " vs fcst " + f_num(fc) + (s > 0 ? " beat" : s < 0 ? " miss" : " in line") : f_num(v1) + "→" + f_num(v0) + " vs prev") + (s > 0 ? " (" + e.cur + " ▲)" : s < 0 ? " (" + e.cur + " ▼)" : "")
    [any, int(math.sign(sum)), tx]
 
f_record(Cl c) =>
    for e in c.evs
        string key = e.cur + " " + e.ttl
        stN.put(key, nz(stN.get(key)) + 1)
        stUp.put(key, nz(stUp.get(key)) + (c.mv > 0 ? 1 : 0))
        stPts.put(key, nz(stPts.get(key)) + math.abs(c.mv))
        int sg = f_evSign(e, c.t)
        if sg != 0 and c.mv != 0
            stDC.put(key, nz(stDC.get(key)) + 1)
            stDS.put(key, nz(stDS.get(key)) + (math.sign(c.mv) == sg ? 1 : 0))
 
f_hist(Cl c) =>
    string bk = ""
    int    bn = 0
    for e in c.evs
        string key = e.cur + " " + e.ttl
        int n = nz(stN.get(key))
        if n > bn
            bn := n
            bk := key
    string tx  = "·"
    string tip = "No releases of this event in the chart's loaded history yet."
    if bn > 0
        float avg = stPts.get(bk) / bn
        float upP = nz(stUp.get(bk)) * 100.0 / bn
        tx  := str.tostring(avg, format.mintick) + " " + (upP >= 50 ? "▲" + str.tostring(upP, "#") : "▼" + str.tostring(100 - upP, "#")) + "% n" + str.tostring(bn)
        int dc = nz(stDC.get(bk))
        int l  = f_learn(bk)
        tip := bk + " on " + syminfo.ticker + ": avg move " + str.tostring(avg, format.mintick) + " in " + str.tostring(mvMin) + "m · up " + str.tostring(upP, "#") + "% of " + str.tostring(bn) + " releases" + (dc > 0 ? "\nWith released data (" + str.tostring(dc) + "): price followed the stronger currency " + str.tostring(nz(stDS.get(bk)) * 100.0 / dc, "#") + "% → " + (na(l) ? "needs 8+ to learn" : l == 1 ? "strong data = " + syminfo.ticker + " UP" : l == -1 ? "strong data = " + syminfo.ticker + " DOWN" : "no reliable link") : "")
    [tx, tip]
 
// board · forecast, previous → actual for the cluster's first mapped release
f_dataCells(table bd, int row, Cl c, int nowT, string ts) =>
    float fcV = na
    float pv  = na
    float ac  = na
    int   pol = 1
    for e in c.evs
        float fc0 = f_fc(e.cur, e.ttl)
        [k, p, a] = f_map(e.cur, e.ttl)
        int i = k == "" ? -1 : ecoK.indexof(k)
        if not na(fc0) or i >= 0
            fcV := fc0
            pol := p
            if i >= 0
                t0 = ecoT.get(i)
                bool rel = c.t <= nowT and not na(t0) and t0 >= c.t - 20 * 3600000
                pv := rel ? ecoV1.get(i) : ecoV0.get(i)
                ac := rel ? ecoV0.get(i) : na
            break
    color acCol = na(ac) ? PSEC : not na(fcV) ? (math.sign(ac - fcV) * pol > 0 ? PGRN : math.sign(ac - fcV) * pol < 0 ? PRED : PVAL) : (math.sign(ac - pv) * pol > 0 ? PGRN : math.sign(ac - pv) * pol < 0 ? PRED : PVAL)
    bd.cell(4, row, na(fcV) ? "·" : f_num(fcV), text_color=PSEC, text_size=ts)
    bd.cell(5, row, na(pv) and na(ac) ? "·" : (na(pv) ? "·" : f_num(pv)) + " → " + (na(ac) ? "…" : f_num(ac)), text_color=acCol, text_size=ts, tooltip="TradingView economic data. Type forecasts in the same units as 'prev'.")
    [hT, hTip] = f_hist(c)
    bd.cell(7, row, hT, text_color=PSEC, text_size=ts, tooltip=hTip)
 
f_call(Cl c, int nowT) =>
    p = c.pDir
    d = c.dDir
    string pT = p == 1 ? "price ▲ held above pre-range" : p == -1 ? "price ▼ held below pre-range" : nowT < c.t + expMin * 60000 ? "price: waiting for a break" : "price: no break"
    if c.pFake
        pT += " (fake-out flip)"
    string dT = not useData ? "" : c.dAny ? "data " + c.dTxt + (d == 1 ? " → chart ▲" : d == -1 ? " → chart ▼" : " → no chart vote") : nowT >= c.t ? "data n/a" : ""
    string cT = p != 0 and d != 0 ? (p == d ? "✅ BOTH " + f_arw(p) + " — " + (p == 1 ? "LONG" : "SHORT") + " bias" : "⚠ MIXED — follow price or wait") : p != 0 ? f_arw(p) + " " + (p == 1 ? "LONG" : "SHORT") + " bias (price only)" : d != 0 ? "data leans " + f_arw(d) + " — wait for price" : "no call yet"
    int dir = p != 0 and (d == 0 or d == p) ? p : 0
    [cT, (dT == "" ? "" : dT + " · ") + pT, dir]
 
// ═══════════════════════════════════════════════════════════════
//  LOAD THE WEEK
// ═══════════════════════════════════════════════════════════════
var currWeek = array.new<ffUtil.News>()
var nextWeek = array.new<ffUtil.News>()
var cls      = array.new<Cl>()
var int ptr  = 0
[sd1, sd2, sd3, sd4, sd5, sd6, sd7, sd8, sd9] = requestData()
 
if timeframe.change("W")
    nextWeek := ffUtil.bubbleSort_News(nextWeek)
    currWeek := nextWeek.copy()
    nextWeek.clear()
    cls.clear()
    ptr := 0
    for n in currWeek
        int rk = f_rk(n.imp)
        if f_on(rk) and f_curOn(n.cur) and f_catOn(n.ttl) and not na(n.tmst)
            Ev e = Ev.new(n.tmst, n.cur, n.ttl, rk)
            if cls.size() > 0 and cls.last().t == n.tmst
                Cl c = cls.last()
                c.evs.push(e)
                if rk > c.rk
                    c.rk  := rk
                    c.cur := n.cur
            else
                cls.push(Cl.new(t=n.tmst, rk=rk, cur=n.cur, evs=array.from(e)))
nextWeek.processData(sd1, sd2, sd3, sd4, sd5, sd6, sd7, sd8, sd9)
 
// ═══════════════════════════════════════════════════════════════
//  PER BAR · windows, pre-range, reaction, data vote, drawings
// ═══════════════════════════════════════════════════════════════
int   tfms = timeframe.in_seconds() * 1000
float hiR  = ta.highest(high, 120)
float loR  = ta.lowest(low, 120)
float atrV = ta.atr(14)
int   nowT = barstate.islast ? math.max(timenow, time) : time
 
bool nwRed = false   // 🔴 window for the 10¢ Guard: 30 min before → 15 min after a red-folder release
if cls.size() > ptr
    for i = ptr to cls.size() - 1
        Cl c = cls.get(i)
        int wS = c.t - f_pre(c.rk)
        int wE = c.t + f_post(c.rk)
        if c.rk >= 3 and time_close > c.t - 30 * 60000 and time < c.t + 15 * 60000
            nwRed := true
        // drawings: one box + label per window
        if na(c.bx) and c.rk >= DRAW_RK and c.rk > 0
            col = f_icol(c.rk)
            c.bx := box.new(wS, hiR + atrV * 0.3, wE, loR - atrV * 0.3, xloc=xloc.bar_time, border_color=color.new(col, 35), border_style=line.style_dashed, bgcolor=color.new(col, 88))
            c.lb := label.new(c.t, hiR + atrV * 0.3, f_dot(c.rk) + " " + f_cut(f_head(c), 26), xloc=xloc.bar_time, style=label.style_label_down, color=T_NONE, textcolor=col, size=c.rk == 3 ? SZ_D : SZ_C, tooltip=f_dhm(c.t) + " " + TZTAG)
        // window high/low
        if time_close > wS and time < wE
            c.wH := na(c.wH) ? high : math.max(c.wH, high)
            c.wL := na(c.wL) ? low : math.min(c.wL, low)
        // pre-news range
        if time_close <= c.t and time_close > c.t - math.max(preRange * 60000, tfms)
            c.preH := na(c.preH) ? high : math.max(c.preH, high)
            c.preL := na(c.preL) ? low : math.min(c.preL, low)
        // measured move after release (all impacts)
        if time_close <= c.t
            c.px0 := close
        if na(c.mv) and not na(c.px0) and time_close >= c.t + mvMin * 60000 and barstate.isconfirmed
            c.mv := close - c.px0
            f_record(c)
        // price reaction (confirmed closes beyond the pre-range)
        if c.rk >= DIR_RK and time_close > c.t and time < c.t + expMin * 60000 and barstate.isconfirmed and not na(c.preH)
            c.upN := close > c.preH ? c.upN + 1 : 0
            c.dnN := close < c.preL ? c.dnN + 1 : 0
            if c.pDir == 0
                c.pDir := c.upN >= confBars ? 1 : c.dnN >= confBars ? -1 : 0
            else if not c.pFake and ((c.pDir == 1 and c.dnN >= confBars) or (c.pDir == -1 and c.upN >= confBars))
                c.pDir  := -c.pDir
                c.pFake := true
        // data vote
        if useData and c.rk >= DIR_RK and not c.dDone and time_close > c.t and time < c.t + expMin * 60000
            [any, dd, tx] = f_vote(c)
            if any
                c.dAny  := true
                c.dDir  := dd
                c.dTxt  := tx
                c.dDone := true
        // freeze the window once it has passed
        if not na(c.bx) and not c.frozen
            if time >= wE and not na(c.wH)
                c.frozen := true
                col = f_icol(c.rk)
                c.bx.set_top(c.wH + atrV * 0.15)
                c.bx.set_bottom(c.wL - atrV * 0.15)
                c.bx.set_bgcolor(color.new(col, 93))
                c.bx.set_border_color(color.new(col, 65))
                c.lb.set_y(c.wH + atrV * 0.15)
            else if barstate.islast
                c.bx.set_top(hiR + atrV * 0.3)
                c.bx.set_bottom(loR - atrV * 0.3)
                c.lb.set_y(hiR + atrV * 0.3)
        // result on the label
        if not na(c.lb) and c.rk >= DIR_RK and time_close > c.t
            [cT, dT, dir] = f_call(c, time)
            c.lb.set_text(f_dot(c.rk) + " " + f_cut(f_head(c), 26) + (dir != 0 ? "  → " + f_arw(dir) : ""))
            c.lb.set_tooltip(f_dhm(c.t) + " " + TZTAG + "\n" + cT + "\n" + dT)
        // advance the start pointer past finished clusters
        if i == ptr and time > c.t + math.max(f_post(c.rk), math.max(expMin, holdMin) * 60000) and (na(c.bx) or c.frozen)
            ptr := i + 1
 
// ═══════════════════════════════════════════════════════════════
//  ALERTS  (create one alert: "Any alert() function call")
// ═══════════════════════════════════════════════════════════════
varip alDone = array.new_string()
f_once(string k) =>
    bool fresh = alDone.indexof(k) < 0
    if fresh
        alDone.push(k)
        if alDone.size() > 300
            alDone.shift()
    fresh
 
if barstate.isrealtime and cls.size() > ptr
    for i = ptr to cls.size() - 1
        Cl c = cls.get(i)
        if c.t - timenow > lead1 * 60000 + 60000
            break
        string id = str.tostring(c.t) + c.cur
        if c.rk >= ALERT_RK
            if timenow >= c.t - lead1 * 60000 and timenow < c.t - lead2 * 60000 and f_once(id + "a1")
                alert("10¢ NEWS · " + f_dot(c.rk) + " " + f_head(c) + " in " + f_dur(c.t - timenow) + " (" + f_hm(c.t) + ") on " + syminfo.ticker, alert.freq_once_per_bar)
            if timenow >= c.t - lead2 * 60000 and timenow < c.t and f_once(id + "a2")
                alert("10¢ NEWS · ⚠ " + f_dot(c.rk) + " " + f_head(c) + " in " + f_dur(c.t - timenow) + " — stand aside · " + syminfo.ticker, alert.freq_once_per_bar)
        if alCall and c.rk >= DIR_RK and c.pDir != 0 and timenow < c.t + expMin * 60000
            [cT, dT, dir] = f_call(c, timenow)
            if f_once(id + "call" + str.tostring(c.pDir))
                alert("10¢ NEWS · " + f_head(c) + " → " + cT + " · " + dT + " · " + syminfo.ticker, alert.freq_once_per_bar)
 
// ═══════════════════════════════════════════════════════════════
//  ONE-LINER & BOARD
// ═══════════════════════════════════════════════════════════════
pTxt = panelSize == "Tiny" ? size.tiny : panelSize == "Small" ? size.small : size.normal
f_lnPos(string p) => p == "Top right" ? position.top_right : p == "Top center" ? position.top_center : p == "Bottom right" ? position.bottom_right : p == "Bottom center" ? position.bottom_center : position.bottom_left
f_bdPos(string p) => p == "Top right" ? position.top_right : p == "Top left" ? position.top_left : p == "Bottom right" ? position.bottom_right : position.bottom_left
 
if barstate.islast
    Cl nxt = na
    Cl pre = na
    Cl rec = na
    if cls.size() > 0
        for c in cls
            if c.rk == 0
                continue
            if na(nxt) and c.t > nowT
                nxt := c
            if na(pre) and c.t > nowT and nowT >= c.t - f_pre(c.rk) and c.rk >= DRAW_RK
                pre := c
            if c.t <= nowT and c.rk >= DIR_RK and nowT < c.t + holdMin * 60000
                rec := c
    string nxtTxt = na(nxt) ? (currWeek.size() == 0 ? "calendar loads at the next weekly open" : "no more news this week") : "next " + f_dot(nxt.rk) + " " + f_cut(f_head(nxt), 24) + " · " + f_dhm(nxt.t) + " " + TZTAG + " · in " + f_dur(nxt.t - nowT)
    string head = "10¢ NEWS"
    string body = nxtTxt
    color  hc   = PSEC
    color  bc   = PSEC
    string tip  = "Times in " + (TZTAG == "" ? syminfo.timezone : TZ)
    if not na(pre)
        head := "10¢ NEWS ⚠"
        hc   := f_icol(pre.rk)
        body := f_dot(pre.rk) + " " + f_cut(f_head(pre), 28) + " in " + f_dur(pre.t - nowT) + " (" + f_hm(pre.t) + ") — stand aside"
        bc   := f_icol(pre.rk)
    else if not na(rec)
        [cT, dT, dir] = f_call(rec, nowT)
        head := "10¢ NEWS " + f_arw(dir)
        hc   := dir == 1 ? PGRN : dir == -1 ? PRED : PAMB
        body := f_dot(rec.rk) + " " + f_cut(f_head(rec), 22) + " │ " + cT + " │ " + nxtTxt
        bc   := dir == 1 ? PGRN : dir == -1 ? PRED : PVAL
        tip  := cT + "\n" + dT + "\n" + tip
    if showLine and not showBoard
        var table lineT = table.new(f_lnPos(lnPosIn), 2, lnRow, frame_width=0)
        if lnRow > 1
            for _i = 0 to lnRow - 1
                if _i != lnR0
                    table.cell(lineT, 0, _i, " ", text_size=size.tiny)
        table.cell(lineT, 0, lnR0, head, text_color=hc, text_size=size.tiny, bgcolor=PHDR, text_halign=text.align_left)
        table.cell(lineT, 1, lnR0, body, text_color=bc, text_size=size.tiny, bgcolor=PHDR, text_halign=text.align_left, tooltip=tip)
    if showBoard
        var table bd = table.new(f_bdPos(boardPos), 8, 26, frame_color=color.new(chart.fg_color, 70), frame_width=1, border_color=color.new(chart.fg_color, 88), border_width=1)
        bd.clear(0, 0, 7, 25)
        // row 0 · the one-line call
        bd.cell(0, 0, head, text_color=hc, text_size=pTxt, bgcolor=PHDR, text_halign=text.align_left)
        bd.cell(1, 0, not na(pre) or not na(rec) ? body : na(nxt) ? body : "quiet · next " + f_dot(nxt.rk) + " in " + f_dur(nxt.t - nowT), text_color=bc, text_size=pTxt, bgcolor=PHDR, text_halign=text.align_left, tooltip=tip)
        bd.merge_cells(1, 0, 7, 0)
        // row 1 · column heads
        bd.cell(0, 1, "", text_size=pTxt)
        bd.cell(1, 1, TZTAG == "" ? "chart tz" : TZTAG, text_color=PSEC, text_size=pTxt)
        bd.cell(2, 1, "", text_size=pTxt)
        bd.cell(3, 1, "event", text_color=PSEC, text_size=pTxt, text_halign=text.align_left)
        bd.cell(4, 1, "fcst", text_color=PSEC, text_size=pTxt)
        bd.cell(5, 1, "prev → act", text_color=PSEC, text_size=pTxt)
        bd.cell(6, 1, "in / move", text_color=PSEC, text_size=pTxt)
        bd.cell(7, 1, "history " + syminfo.ticker, text_color=PSEC, text_size=pTxt)
        int row = 2
        if not na(rec)
            [cT, dT, dir] = f_call(rec, nowT)
            bd.cell(0, row, f_dot(rec.rk), text_size=pTxt)
            bd.cell(1, row, f_dhm(rec.t), text_color=PSEC, text_size=pTxt)
            bd.cell(2, row, rec.cur, text_color=PVAL, text_size=pTxt)
            bd.cell(3, row, f_cut(f_head(rec, false), 30), text_color=PSEC, text_size=pTxt, text_halign=text.align_left)
            bd.cell(6, row, dir != 0 ? f_arw(dir) + (dir == 1 ? " LONG" : " SHORT") : "…", text_color=dir == 1 ? PGRN : dir == -1 ? PRED : PAMB, text_size=pTxt, tooltip=cT + "\n" + dT)
            f_dataCells(bd, row, rec, nowT, pTxt)
            row += 1
        // session focus (New York clock): Asia 18–02 · London 02–08 · New York 08–17
        int    nyH   = hour(nowT, "America/New_York")
        string sesNm = nyH >= 2 and nyH < 8 ? "LONDON" : nyH >= 8 and nyH < 17 ? "NEW YORK" : "ASIA"
        string sesCur = sesNm == "LONDON" ? "EUR GBP CHF" : sesNm == "NEW YORK" ? "USD CAD" : "JPY AUD NZD CNY"
        int    endH  = sesNm == "LONDON" ? 8 : sesNm == "NEW YORK" ? 17 : 2
        int    sesEnd = timestamp("America/New_York", year(nowT, "America/New_York"), month(nowT, "America/New_York"), dayofmonth(nowT, "America/New_York"), endH, 0) + (sesNm == "ASIA" and nyH >= 17 ? 86400000 : 0)
        int    stH   = sesNm == "LONDON" ? 2 : sesNm == "NEW YORK" ? 8 : 18
        int    sesStart = timestamp("America/New_York", year(nowT, "America/New_York"), month(nowT, "America/New_York"), dayofmonth(nowT, "America/New_York"), stH, 0) - (sesNm == "ASIA" and nyH < 17 ? 86400000 : 0)
        bool   focusOn = boardFocus == "Session"
        int    maxRow = boardRows + row + (focusOn ? 2 : 0)
        int    firstOther = row
        if focusOn
            bd.cell(0, row, sesNm + " now", text_color=PAMB, text_size=pTxt, text_halign=text.align_left)
            bd.cell(1, row, sesCur + " · until " + f_hm(sesEnd), text_color=PSEC, text_size=pTxt, text_halign=text.align_left)
            bd.merge_cells(1, row, 7, row)
            row += 1
            int n0 = row
            if cls.size() > 0
                for c in cls
                    if c.t >= sesEnd or row >= n0 + boardRows
                        break
                    if c.t >= sesStart and str.contains(sesCur, c.cur)
                        bool done = c.t <= nowT
                        color tc = done ? PSEC : PVAL
                        bd.cell(0, row, f_dot(c.rk), text_size=pTxt)
                        bd.cell(1, row, f_dhm(c.t), text_color=tc, text_size=pTxt)
                        bd.cell(2, row, c.cur, text_color=tc, text_size=pTxt)
                        bd.cell(3, row, f_cut(f_head(c, false), 30), text_color=tc, text_size=pTxt, text_halign=text.align_left)
                        bd.cell(6, row, done ? (na(c.mv) ? (na(c.px0) ? "out" : "live " + f_arw(int(math.sign(close - c.px0))) + " " + str.tostring(math.abs(close - c.px0), format.mintick)) : f_arw(int(math.sign(c.mv))) + " " + str.tostring(math.abs(c.mv), format.mintick)) : f_dur(c.t - nowT), text_color=done ? (na(c.px0) ? PSEC : math.sign(na(c.mv) ? close - c.px0 : c.mv) > 0 ? PGRN : math.sign(na(c.mv) ? close - c.px0 : c.mv) < 0 ? PRED : PSEC) : c.t - nowT <= lead1 * 60000 ? f_icol(c.rk) : PSEC, text_size=pTxt)
                        f_dataCells(bd, row, c, nowT, pTxt)
                        row += 1
            if row == n0
                bd.cell(0, row, "", text_size=pTxt)
                bd.cell(1, row, "no " + str.lower(sesNm) + " news this session", text_color=PSEC, text_size=pTxt, text_halign=text.align_left)
                bd.merge_cells(1, row, 7, row)
                row += 1
            bd.cell(0, row, "coming up", text_color=PSEC, text_size=pTxt, text_halign=text.align_left)
            bd.cell(1, row, "", text_size=pTxt)
            bd.merge_cells(1, row, 7, row)
            row += 1
            firstOther := row
            maxRow := row + boardRows
        if cls.size() > 0
            for c in cls
                if row >= maxRow
                    break
                bool shownAbove = focusOn and c.t < sesEnd and str.contains(sesCur, c.cur)
                if c.t > nowT and not shownAbove
                    bd.cell(0, row, f_dot(c.rk), text_size=pTxt)
                    bd.cell(1, row, f_dhm(c.t), text_color=PVAL, text_size=pTxt)
                    bd.cell(2, row, c.cur, text_color=PVAL, text_size=pTxt)
                    bd.cell(3, row, f_cut(f_head(c, false), 30), text_color=PVAL, text_size=pTxt, text_halign=text.align_left, tooltip=str.tostring(c.evs.size()) + " release(s) at this time")
                    bd.cell(6, row, f_dur(c.t - nowT), text_color=c.t - nowT <= lead1 * 60000 ? f_icol(c.rk) : PSEC, text_size=pTxt)
                    f_dataCells(bd, row, c, nowT, pTxt)
                    row += 1
        if row == firstOther
            bd.cell(0, row, "", text_size=pTxt)
            bd.cell(3, row, currWeek.size() == 0 ? "calendar loads at the next weekly open" : "no more news this week", text_color=PSEC, text_size=pTxt, text_halign=text.align_left)
 
// 10¢ Guard link: other 10¢ scripts read this as "News window" (7777 inside a red-folder window)
plot(nwRed ? 7777 : 0, "News window", display=display.none, editable=false)
// one-liner default 12-11
// one-liner stack 20 Nov 2026 · row input: one-liners sharing a corner stack instead of overlapping

← 返回列表