OPEN-SOURCE SCRIPT

Macro Risk Dashboard (TNX/DXY/HYG/TLT) [TradeCore]

47
//version=5
indicator("Macro Risk Dashboard (TNX/DXY/HYG/TLT) [TradeCore]",
shorttitle="MacroRiskDash",
overlay=false)

// ===== Inputs
symTNX = input.symbol("CBOE:TNX", "TNX (10Y yield)")
symDXY = input.symbol("TVC:DXY", "DXY (US Dollar)")
symHYG = input.symbol("AMEX:HYG", "HYG (High Yield)")
symTLT = input.symbol("NASDAQ:TLT","TLT (20Y Bonds)")
tf = input.timeframe("", "Timeframe (vacío = del gráfico)")
showLbl = input.bool(true, "Mostrar etiqueta en la última vela")

// ===== Utilidades
f_close(sym) => request.security(sym, tf == "" ? timeframe.period : tf, close)
f_prev(sym) => request.security(sym, tf == "" ? timeframe.period : tf, close[1])
f_pct(sym) =>
c = f_close(sym)
p = f_prev(sym)
p == 0.0 ? na : (c - p) / p

// % cambios (vs. cierre previo del mismo TF)
tnxPct = f_pct(symTNX)
dxyPct = f_pct(symDXY)
hygPct = f_pct(symHYG)
tltPct = f_pct(symTLT)

// Señales (+1 / -1) según tu lógica:
// Risk-On = TNX↓, DXY↓, HYG↑, TLT↑
tnxSig = na(tnxPct) ? 0 : (tnxPct < 0 ? 1 : -1)
dxySig = na(dxyPct) ? 0 : (dxyPct < 0 ? 1 : -1)
hygSig = na(hygPct) ? 0 : (hygPct > 0 ? 1 : -1)
tltSig = na(tltPct) ? 0 : (tltPct > 0 ? 1 : -1)

riskScore = tnxSig + dxySig + hygSig + tltSig
riskText = riskScore >= 2 ? "RISK-ON" : riskScore <= -2 ? "RISK-OFF" : "MIXED"
riskCol = riskScore >= 2 ? color.lime : riskScore <= -2 ? color.red : color.yellow

// ===== Plots (para Watchlist usa estos como columnas)
plot(riskScore, title="RiskScore", color=riskCol, linewidth=2,
display=display.all)
plot(tnxPct, title="TNX_%", display=display.status_line + display.data_window)
plot(dxyPct, title="DXY_%", display=display.status_line + display.data_window)
plot(hygPct, title="HYG_%", display=display.status_line + display.data_window)
plot(tltPct, title="TLT_%", display=display.status_line + display.data_window)

// ===== Etiqueta opcional (sin errores de sintaxis)
var label tag = na
if barstate.islast and showLbl
if not na(tag)
label.delete(tag)
txt = "Macro: " + riskText +
"\nScore: " + str.tostring(riskScore) +
"\nTNX: " + str.tostring(tnxPct, format.percent) +
"\nDXY: " + str.tostring(dxyPct, format.percent) +
"\nHYG: " + str.tostring(hygPct, format.percent) +
"\nTLT: " + str.tostring(tltPct, format.percent)
tag := label.new(x=bar_index, y=high, text=txt,
style=label.style_label_left,
color=riskCol, textcolor=color.black, size=size.small)

// Fondo suave según régimen
bgcolor(color.new(riskCol, 90))

כתב ויתור

The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.