CA News Catalyst Event Map v1

Crypto_Andy_ · study · 260 行 · 点赞 6 · TradingView 原页

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

Pine Script

//@version=6
// CA News Catalyst Event Map v1
// Changelog: v1 - initial release.
//
// Chart-analysis indicator that pins dated news catalysts to the bars they happened on and measures
// how price reacted, so a news timeline and price structure can be read together on one chart.
//   - Events:   up to 8 user-defined timestamps (UTC) with a short label, a details tooltip and a type
//               (Upgrade / Risk / Market). The defaults are a Zcash NU7 timeline; replace them for any other asset.
//   - Marker:   drawn on the first bar whose time span contains the event timestamp.
//   - Reaction: change from the event-bar close to now (% and in ATR measured at the event), max run-up and
//               drawdown since the event, and the change after a fixed N-bar window. All computed from loaded OHLC data.
//   - Context:  anchored VWAPs from two selectable events, confirmed swing levels, optional manual zones.
// Event-bar values settle when that bar closes. The N-bar reaction is filled in N bars after the event.
// Nothing here is a trade signal; alerts fire only on confirmed closes across anchored VWAP A.
 
indicator("CA News Catalyst Event Map v1", shorttitle="CA News Map v1", overlay=true, max_labels_count=50, max_lines_count=50, max_boxes_count=10)
 
const int N_EV = 8
const string CAT_OPTS_HELP = "Upgrade = protocol / product milestone, Risk = negative or uncertain catalyst, Market = flows, price or macro event."
 
// ───────────── Inputs: events (time is UTC) ─────────────
string g1 = "Event 1"
bool   e1On  = input.bool(true, "Show", group=g1, inline="1")
string e1Cat = input.string("Risk", "Type", options=["Upgrade", "Risk", "Market"], group=g1, inline="1", tooltip=CAT_OPTS_HELP)
int    e1T   = input.time(timestamp("29 May 2026 00:00 +0000"), "Time", group=g1)
string e1Txt = input.string("Orchard bug / NU6.2", "Label", group=g1)
string e1Tip = input.string("Critical Orchard circuit bug reported on 29 May; emergency NU6.2 upgrade fixed it by 1 Jun. No evidence of exploitation was reported (CMC AI updates).", "Details", group=g1)
 
string g2 = "Event 2"
bool   e2On  = input.bool(true, "Show", group=g2, inline="2")
string e2Cat = input.string("Market", "Type", options=["Upgrade", "Risk", "Market"], group=g2, inline="2", tooltip=CAT_OPTS_HELP)
int    e2T   = input.time(timestamp("17 Sep 2026 00:00 +0000"), "Time", group=g2)
string e2Txt = input.string("+21.6% day / ETF flows", "Label", group=g2)
string e2Tip = input.string("Price rose about 21.6% in 24h (CMC AI). A three-week spot ETF inflow streak reportedly passed $358M as of 16 Sep. Core development orgs agreed the NU7 mainnet timeline in mid-September.", "Details", group=g2)
 
string g3 = "Event 3"
bool   e3On  = input.bool(true, "Show", group=g3, inline="3")
string e3Cat = input.string("Upgrade", "Type", options=["Upgrade", "Risk", "Market"], group=g3, inline="3", tooltip=CAT_OPTS_HELP)
int    e3T   = input.time(timestamp("30 Sep 2026 00:00 +0000"), "Time", group=g3)
string e3Txt = input.string("NU7 code complete", "Label", group=g3)
string e3Tip = input.string("NU7 code-completion deadline.", "Details", group=g3)
 
string g4 = "Event 4"
bool   e4On  = input.bool(true, "Show", group=g4, inline="4")
string e4Cat = input.string("Upgrade", "Type", options=["Upgrade", "Risk", "Market"], group=g4, inline="4", tooltip=CAT_OPTS_HELP)
int    e4T   = input.time(timestamp("06 Oct 2026 00:00 +0000"), "Time", group=g4)
string e4Txt = input.string("NU7 testnet", "Label", group=g4)
string e4Tip = input.string("NU7 activated on testnet ahead of mainnet: 25-second block target tested before the mainnet decision.", "Details", group=g4)
 
string g5 = "Event 5"
bool   e5On  = input.bool(true, "Show", group=g5, inline="5")
string e5Cat = input.string("Upgrade", "Type", options=["Upgrade", "Risk", "Market"], group=g5, inline="5", tooltip=CAT_OPTS_HELP)
int    e5T   = input.time(timestamp("20 Oct 2026 00:00 +0000"), "Time", group=g5)
string e5Txt = input.string("NU7 mainnet decision", "Label", group=g5)
string e5Tip = input.string("Scheduled go / no-go decision on the NU7 mainnet rollout (as reported by FXStreet and FXEmpire).", "Details", group=g5)
 
string g6 = "Event 6"
bool   e6On  = input.bool(true, "Show", group=g6, inline="6")
string e6Cat = input.string("Risk", "Type", options=["Upgrade", "Risk", "Market"], group=g6, inline="6", tooltip=CAT_OPTS_HELP)
int    e6T   = input.time(timestamp("05 Nov 2026 00:00 +0000"), "Time", group=g6)
string e6Txt = input.string("Sprout pool freeze", "Label", group=g6)
string e6Tip = input.string("About 12,224 coins (~$16M) left in the original 2016 Sprout pool become unspendable as NU7 retires Sprout / v4 transactions. A recovery mechanism has been outlined but not approved (CoinDesk).", "Details", group=g6)
 
string g7 = "Event 7"
bool   e7On  = input.bool(true, "Show", group=g7, inline="7")
string e7Cat = input.string("Upgrade", "Type", options=["Upgrade", "Risk", "Market"], group=g7, inline="7", tooltip=CAT_OPTS_HELP)
int    e7T   = input.time(timestamp("06 Nov 2026 02:34 +0000"), "Time", group=g7)
string e7Txt = input.string("NU7 LIVE", "Label", group=g7)
string e7Tip = input.string("NU7 mainnet activation at block 3,543,405 (02:34 UTC). Block target 75s -> 25s, about 3x faster first confirmation. Miners receive 40% of fees; 60% goes to a reserve that feeds block rewards from about Feb 2031 (CoinDesk).", "Details", group=g7)
 
string g8 = "Event 8"
bool   e8On  = input.bool(false, "Show", group=g8, inline="8")
string e8Cat = input.string("Market", "Type", options=["Upgrade", "Risk", "Market"], group=g8, inline="8", tooltip=CAT_OPTS_HELP)
int    e8T   = input.time(timestamp("01 Dec 2026 00:00 +0000"), "Time", group=g8)
string e8Txt = input.string("Custom event", "Label", group=g8)
string e8Tip = input.string("Free slot for the next catalyst.", "Details", group=g8)
 
// ───────────── Inputs: analysis ─────────────
string gA = "Analysis"
int   atrLen   = input.int(14, "ATR length", minval=1, group=gA)
int   rxBars   = input.int(6, "Reaction window (bars)", minval=1, maxval=500, group=gA, tooltip="Change measured exactly this many bars after each event bar. 6 bars = 1 day on 4H.")
int   anchorA  = input.int(7, "AVWAP A anchor (event #)", options=[1, 2, 3, 4, 5, 6, 7, 8], group=gA)
int   anchorB  = input.int(4, "AVWAP B anchor (event #)", options=[1, 2, 3, 4, 5, 6, 7, 8], group=gA)
int   pivotLen = input.int(5, "Swing pivot length (bars each side)", minval=2, maxval=50, group=gA, tooltip="A swing level appears only after it is confirmed, this many bars after the pivot bar.")
 
// ───────────── Inputs: manual zones (0 = off) ─────────────
string gZ = "Manual zones (0 = off)"
float supLo = input.float(0.0, "Support zone low", minval=0.0, group=gZ, inline="s")
float supHi = input.float(0.0, "Support zone high", minval=0.0, group=gZ, inline="s")
float resLo = input.float(0.0, "Resistance zone low", minval=0.0, group=gZ, inline="r")
float resHi = input.float(0.0, "Resistance zone high", minval=0.0, group=gZ, inline="r")
int   zoneBars = input.int(120, "Zone width (bars back)", minval=10, maxval=1000, group=gZ)
 
// ───────────── Inputs: visuals ─────────────
string gV = "Visuals"
bool   showMarkers = input.bool(true, "Show event markers", group=gV)
bool   showVwapA   = input.bool(true, "Show AVWAP A", group=gV)
bool   showVwapB   = input.bool(true, "Show AVWAP B", group=gV)
bool   showSwings  = input.bool(true, "Show swing levels", group=gV)
bool   showPost    = input.bool(false, "Shade bars after AVWAP A anchor event", group=gV)
bool   showFar     = input.bool(false, "Show levels far from price", group=gV)
float  nearAtr     = input.float(10.0, "Far level threshold (ATR)", minval=1.0, maxval=100.0, step=0.5, group=gV)
bool   showTable   = input.bool(true, "Show reaction table", group=gV)
string tablePos    = input.string("Bottom right", "Table position", options=["Top right", "Bottom right", "Top left", "Bottom left"], group=gV)
 
// ───────────── Event arrays ─────────────
var array<bool>   evOn  = array.from(e1On, e2On, e3On, e4On, e5On, e6On, e7On, e8On)
var array<int>    evT   = array.from(e1T, e2T, e3T, e4T, e5T, e6T, e7T, e8T)
var array<string> evTxt = array.from(e1Txt, e2Txt, e3Txt, e4Txt, e5Txt, e6Txt, e7Txt, e8Txt)
var array<string> evTip = array.from(e1Tip, e2Tip, e3Tip, e4Tip, e5Tip, e6Tip, e7Tip, e8Tip)
var array<string> evCat = array.from(e1Cat, e2Cat, e3Cat, e4Cat, e5Cat, e6Cat, e7Cat, e8Cat)
 
// Per-event state, filled when the event bar is found on the chart
var array<int>   evBar = array.new<int>(N_EV, na)
var array<float> evPx  = array.new<float>(N_EV, na)
var array<float> evAtr = array.new<float>(N_EV, na)
var array<float> evHi  = array.new<float>(N_EV, na)
var array<float> evLo  = array.new<float>(N_EV, na)
var array<float> evRx  = array.new<float>(N_EV, na)
 
// ───────────── Helpers ─────────────
float atr = ta.atr(atrLen)
 
catColor(string c) => c == "Upgrade" ? color.teal : c == "Risk" ? color.red : color.blue
nearPrice(float x) => not na(x) and not na(atr) and (showFar or math.abs(x - close) <= nearAtr * atr)
breakOnChange(float x) => x != x[1] ? na : x
fmtPct(float x) => na(x) ? "-" : (x >= 0 ? "+" : "") + str.tostring(x, "#.##") + "%"
fmtNum(float x) => na(x) ? "-" : (x >= 0 ? "+" : "") + str.tostring(x, "#.##")
pctChg(float a, float b) => na(a) or na(b) or b == 0 ? na : (a - b) / b * 100.0
 
// ───────────── Event detection, markers and reaction tracking ─────────────
for i = 0 to N_EV - 1
    int t = evT.get(i)
    if evOn.get(i) and na(evBar.get(i)) and time <= t and time_close > t
        evBar.set(i, bar_index)
        evPx.set(i, close)
        evAtr.set(i, atr)
        evHi.set(i, high)
        evLo.set(i, low)
        if showMarkers
            color  c     = catColor(evCat.get(i))
            bool   below = evCat.get(i) == "Risk"
            string dt    = str.format_time(t, "dd MMM yyyy HH:mm", "UTC") + " UTC"
            line.new(bar_index, low, bar_index, high, extend=extend.both, color=color.new(c, 55), style=line.style_dashed, width=1)
            label.new(bar_index, below ? low : high, str.tostring(i + 1) + ". " + evTxt.get(i), yloc=below ? yloc.belowbar : yloc.abovebar, style=below ? label.style_label_up : label.style_label_down, color=color.new(c, 15), textcolor=color.white, size=size.small, tooltip=dt + "\n" + evTip.get(i))
    else if not na(evBar.get(i)) and bar_index > evBar.get(i)
        evHi.set(i, math.max(evHi.get(i), high))
        evLo.set(i, math.min(evLo.get(i), low))
        if bar_index - evBar.get(i) == rxBars
            evRx.set(i, pctChg(close, evPx.get(i)))
 
// ───────────── Anchored VWAPs from event bars ─────────────
anchoredVwap(int idx) =>
    var float sPV = na
    var float sV  = na
    int ab = evBar.get(idx)
    float v = nz(volume)
    if not na(ab) and bar_index == ab
        sPV := hlc3 * v
        sV  := v
    else if not na(sPV)
        sPV += hlc3 * v
        sV  += v
    na(sV) or sV <= 0 ? na : sPV / sV
 
float vwapA = anchoredVwap(anchorA - 1)
float vwapB = anchoredVwap(anchorB - 1)
 
// ───────────── Confirmed swing levels (retired when closed through) ─────────────
float ph = ta.pivothigh(high, pivotLen, pivotLen)
float pl = ta.pivotlow(low, pivotLen, pivotLen)
var float resLvl = na
var float supLvl = na
if not na(ph)
    resLvl := ph
if not na(pl)
    supLvl := pl
if barstate.isconfirmed and not na(resLvl) and close > resLvl
    resLvl := na
if barstate.isconfirmed and not na(supLvl) and close < supLvl
    supLvl := na
 
// ───────────── Plots ─────────────
plot(showVwapA ? vwapA : na, "AVWAP A (event anchor)", color=color.new(color.teal, 0), linewidth=2, style=plot.style_linebr)
plot(showVwapB ? vwapB : na, "AVWAP B (event anchor)", color=color.new(color.gray, 0), linewidth=1, style=plot.style_linebr)
float resPl = breakOnChange(nearPrice(resLvl) ? resLvl : na)
float supPl = breakOnChange(nearPrice(supLvl) ? supLvl : na)
plot(showSwings ? resPl : na, "Swing resistance", color=color.new(color.orange, 20), style=plot.style_linebr, display=display.pane)
plot(showSwings ? supPl : na, "Swing support", color=color.new(color.yellow, 20), style=plot.style_linebr, display=display.pane)
 
int postBar = evBar.get(anchorA - 1)
bgcolor(showPost and not na(postBar) and bar_index >= postBar ? color.new(color.teal, 93) : na, title="After anchor A event")
 
// ───────────── Manual zones (drawn on the last bar) ─────────────
var box supBox = na
var box resBox = na
zoneOk(float lo, float hi) => lo > 0 and hi > lo and (showFar or (nearPrice(lo) or nearPrice(hi)))
 
if barstate.islast
    if not na(supBox)
        supBox.delete()
    if not na(resBox)
        resBox.delete()
    if zoneOk(supLo, supHi)
        supBox := box.new(bar_index - zoneBars, supHi, bar_index + 10, supLo, border_color=color.new(color.teal, 60), bgcolor=color.new(color.teal, 88), text="Support zone", text_color=color.new(color.teal, 20), text_size=size.small, text_halign=text.align_right)
    if zoneOk(resLo, resHi)
        resBox := box.new(bar_index - zoneBars, resHi, bar_index + 10, resLo, border_color=color.new(color.red, 60), bgcolor=color.new(color.red, 88), text="Resistance zone", text_color=color.new(color.red, 20), text_size=size.small, text_halign=text.align_right)
 
// ───────────── Reaction table ─────────────
string tPos = tablePos == "Top right" ? position.top_right : tablePos == "Bottom right" ? position.bottom_right : tablePos == "Top left" ? position.top_left : position.bottom_left
var table tbl = table.new(tPos, 7, N_EV + 2, bgcolor=color.new(color.gray, 85), border_width=1, border_color=color.new(color.gray, 60))
 
cell(int c, int r, string t, color tc, string tip = "") =>
    table.cell(tbl, c, r, t, text_color=tc, text_size=size.small, text_halign=c == 0 ? text.align_left : text.align_right, tooltip=tip)
 
if barstate.islast and showTable
    table.clear(tbl, 0, 0, 6, N_EV + 1)
    cell(0, 0, "Event (" + syminfo.ticker + ")", color.white)
    cell(1, 0, "Date (UTC)", color.white)
    cell(2, 0, "Close at event", color.white)
    cell(3, 0, "Now vs event", color.white)
    cell(4, 0, "In ATR", color.white)
    cell(5, 0, "Max up / down", color.white)
    cell(6, 0, "After " + str.tostring(rxBars) + " bars", color.white)
    int r = 1
    for i = 0 to N_EV - 1
        if evOn.get(i)
            int   b  = evBar.get(i)
            float px = evPx.get(i)
            color cc = catColor(evCat.get(i))
            cell(0, r, str.tostring(i + 1) + ". " + evTxt.get(i), cc, evTip.get(i))
            cell(1, r, str.format_time(evT.get(i), "dd MMM yyyy", "UTC"), color.gray)
            if na(b)
                string st = evT.get(i) >= time_close ? "upcoming" : "not in loaded history"
                cell(2, r, st, color.gray)
                cell(3, r, "-", color.gray)
                cell(4, r, "-", color.gray)
                cell(5, r, "-", color.gray)
                cell(6, r, "-", color.gray)
            else
                float chg  = pctChg(close, px)
                float ea   = evAtr.get(i)
                float inAtr = na(ea) or ea == 0 ? na : (close - px) / ea
                float up   = pctChg(evHi.get(i), px)
                float dn   = pctChg(evLo.get(i), px)
                float rx   = evRx.get(i)
                cell(2, r, str.tostring(math.round_to_mintick(px), format.mintick), color.white)
                cell(3, r, fmtPct(chg), na(chg) ? color.gray : chg >= 0 ? color.teal : color.red)
                cell(4, r, fmtNum(inAtr), color.white)
                cell(5, r, fmtPct(up) + " / " + fmtPct(dn), color.white)
                cell(6, r, bar_index - b < rxBars ? "pending" : fmtPct(rx), na(rx) ? color.gray : rx >= 0 ? color.teal : color.red)
            r += 1
    cell(0, r, "Measured from the close of the bar containing each event. Event-bar values settle at bar close. Past reactions only, not a forecast. Educational, not financial advice.", color.gray)
    table.merge_cells(tbl, 0, r, 6, r)
 
// ───────────── Alerts (confirmed closes only) ─────────────
bool crossUpA = barstate.isconfirmed and not na(vwapA) and not na(vwapA[1]) and close > vwapA and close[1] <= vwapA[1]
bool crossDnA = barstate.isconfirmed and not na(vwapA) and not na(vwapA[1]) and close < vwapA and close[1] >= vwapA[1]
alertcondition(crossUpA, "Close above AVWAP A", "{{ticker}} {{interval}}: confirmed close above the event-anchored VWAP A")
alertcondition(crossDnA, "Close below AVWAP A", "{{ticker}} {{interval}}: confirmed close below the event-anchored VWAP A")

← 返回列表