本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
// This Pine Script code is subject to the terms of the
// Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//
// SPY Daily Hedge Dashboard with 1SD adn 2SD Bollinger
// Designed for SPY on a 1-day chart and evaluated after the close.
//
//@version=6
indicator(
"SPY Daily Hedge",
overlay=true)
// ============================================================
// USER INPUTS
// ============================================================
// The hedge model parameters are intentionally fixed so users
// only control chart presentation.
showTrend = input.bool(true, "Show 4W Low Marker")
showBackground = input.bool(false, "Shade Risk Background")
showBollingerBands = input.bool(true, "Show Bollinger 1SD / 2SD")
showBollingerShading = input.bool(true, "Shade Bollinger Bands")
// ============================================================
// FIXED MODEL PARAMETERS
// ============================================================
int vixWindow = 30
int vixMomentumLength = 3
int spyVolWindow = 10
int spyVolDirectionLength = 1
int bollingerLength = 20
float vixWarningDistancePercent = 5.0
float termStressThreshold = 1.00
float skewThreshold = 130.0
int warningConfirmationDays = 2
int hedgeConfirmationDays = 2
int recoveryConfirmationDays = 2
int hedgeOffConfirmationDays = 3
int immediateHedgeRiskScore = 4
int maximumRecoveryRiskScore = 2
int maximumHedgeOffRiskScore = 1
float hindenburgThresholdPercent = 2.2
int hindenburgClusterLookback = 30
int hindenburgClusterMinimum = 2
int hindenburgUptrendLength = 50
bool showDashboard = true
// ============================================================
// COLORS
// ============================================================
hedgeOffColor = color.rgb(100, 255, 100)
warningColor = color.orange
hedgeOnColor = color.rgb(249, 57, 106)
increaseHedgeColor = color.rgb(180, 0, 0)
recoveringColor = color.rgb(255, 215, 0)
neutralColor = color.rgb(90, 90, 90)
headerColor = color.rgb(41, 47, 54)
fastTrendColor = color.aqua
// ============================================================
// CHART VALIDATION
// ============================================================
isSPYChart = syminfo.ticker == "SPY"
isDailyChart = timeframe.isdaily and timeframe.multiplier == 1
validChart = isSPYChart and isDailyChart
// ============================================================
// SYMBOLS
// ============================================================
vixTicker = ticker.new("CBOE", "VIX", session.regular)
vix3mTicker = ticker.new("CBOE", "VIX3M", session.regular)
skewTicker = ticker.new("CBOE", "SKEW", session.regular)
// TradingView breadth symbols. Availability can depend on account/data access.
string nyseNewHighsTicker = "INDEX:HIGN"
string nyseNewLowsTicker = "INDEX:LOWN"
string nyseAdvanceTicker = "USI:ADV"
string nyseDeclineTicker = "USI:DECL"
string nyseUnchangedTicker = "USI:UNCH.NY"
string nyseCompositeTicker = "NYSE:NYA"
// ============================================================
// DAILY VOLATILITY DATA
// ============================================================
vix = request.security(vixTicker, "D", close, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
vixMean = request.security(vixTicker, "D", ta.sma(close, vixWindow), gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
vixRising = request.security(vixTicker, "D", ta.change(close, vixMomentumLength) > 0, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
vixFalling = request.security(vixTicker, "D", ta.change(close, vixMomentumLength) < 0, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
vix3m = request.security(vix3mTicker, "D", close, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
skew = request.security(skewTicker, "D", close, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off)
// ============================================================
// SPY REALIZED VOLATILITY
// ============================================================
spyLogReturn = math.log(close / close[1])
spyRealizedVolatility = ta.stdev(spyLogReturn, spyVolWindow) * math.sqrt(252.0) * 100.0
spyVolRising = spyRealizedVolatility > spyRealizedVolatility[spyVolDirectionLength]
spyVolFalling = spyRealizedVolatility < spyRealizedVolatility[spyVolDirectionLength]
// ============================================================
// BOLLINGER 1SD / 2SD VISUAL
// ============================================================
// Visual context only. Bollinger Bands do not affect the hedge
// state, risk score, SH suggestion, Hindenburg, or 4W structure.
bbBasis = ta.sma(close, bollingerLength)
bbDeviation = ta.stdev(close, bollingerLength)
bbUpper1 = bbBasis + bbDeviation
bbLower1 = bbBasis - bbDeviation
bbUpper2 = bbBasis + (2.0 * bbDeviation)
bbLower2 = bbBasis - (2.0 * bbDeviation)
bbBasisPlot = plot(
showBollingerBands ? bbBasis : na,
title="BB Basis",
color=color.new(color.gray, 45),
linewidth=1)
bbUpper1Plot = plot(
showBollingerBands ? bbUpper1 : na,
title="BB +1SD",
color=color.new(color.aqua, 30),
linewidth=1)
bbLower1Plot = plot(
showBollingerBands ? bbLower1 : na,
title="BB -1SD",
color=color.new(color.aqua, 30),
linewidth=1)
bbUpper2Plot = plot(
showBollingerBands ? bbUpper2 : na,
title="BB +2SD",
color=color.new(color.blue, 5),
linewidth=2)
bbLower2Plot = plot(
showBollingerBands ? bbLower2 : na,
title="BB -2SD",
color=color.new(color.blue, 5),
linewidth=2)
// Shade the inner 1SD zone lightly and the outer 1SD-to-2SD
// zones more faintly. Shading appears only when both switches are on.
fill(
bbUpper1Plot,
bbLower1Plot,
color=showBollingerBands and showBollingerShading ? color.new(color.aqua, 93) : na,
title="BB 1SD Shade")
fill(
bbUpper2Plot,
bbUpper1Plot,
color=showBollingerBands and showBollingerShading ? color.new(color.blue, 95) : na,
title="BB Upper 2SD Shade")
fill(
bbLower1Plot,
bbLower2Plot,
color=showBollingerBands and showBollingerShading ? color.new(color.blue, 95) : na,
title="BB Lower 2SD Shade")
// ============================================================
// 4-WEEK STRUCTURAL LOW
// ============================================================
// The only price-structure level used is the lowest low of the
// prior four completed weekly bars. The developing current week
// is excluded by [1].
priorFourWeekLow = request.security(
syminfo.tickerid,
"W",
ta.lowest(low, 4)[1],
gaps=barmerge.gaps_off,
lookahead=barmerge.lookahead_off)
structureBroken = close < priorFourWeekLow
string spyTrendText = "STRUCTURE INTACT"
color spyTrendColor = hedgeOffColor
color spyTrendTextColor = color.black
if structureBroken
spyTrendText := "STRUCTURE BROKEN"
spyTrendColor := increaseHedgeColor
spyTrendTextColor := color.white
else
spyTrendText := "STRUCTURE INTACT"
spyTrendColor := hedgeOffColor
spyTrendTextColor := color.black
// ============================================================
// RIGHT-SIDE 4-WEEK LOW MARKER
// ============================================================
markerStartBars = 1
markerEndBars = 7
var line fourWeekLowMarker = na
var label fourWeekLowLabel = na
if barstate.islast
line.delete(fourWeekLowMarker)
label.delete(fourWeekLowLabel)
if showTrend and not na(priorFourWeekLow)
fourWeekLowMarker := line.new(
bar_index + markerStartBars,
priorFourWeekLow,
bar_index + markerEndBars,
priorFourWeekLow,
xloc=xloc.bar_index,
extend=extend.none,
color=increaseHedgeColor,
width=4)
fourWeekLowLabel := label.new(
bar_index + markerEndBars,
priorFourWeekLow,
"4W LOW " + str.tostring(priorFourWeekLow, format.mintick),
xloc=xloc.bar_index,
style=label.style_label_left,
color=increaseHedgeColor,
textcolor=color.white,
size=size.small)
// ============================================================
// DERIVED VOLATILITY VALUES
// ============================================================
vixDistancePercent = not na(vixMean) and vixMean != 0.0 ? ((vix / vixMean) - 1.0) * 100.0 : na
vixTermRatio = not na(vix3m) and vix3m != 0.0 ? vix / vix3m : na
vixAboveMean = not na(vixMean) and vix > vixMean
vixBelowMean = not na(vixMean) and vix < vixMean
vixNearMean = not na(vixDistancePercent) and math.abs(vixDistancePercent) <= vixWarningDistancePercent
termStress = not na(vixTermRatio) and vixTermRatio >= termStressThreshold
elevatedSkew = not na(skew) and skew >= skewThreshold
// ============================================================
// HINDENBURG-STYLE BREADTH ENGINE
// ============================================================
nyseNewHighs = request.security(nyseNewHighsTicker, "D", close, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off, ignore_invalid_symbol=true)
nyseNewLows = request.security(nyseNewLowsTicker, "D", close, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off, ignore_invalid_symbol=true)
nyseAdvances = request.security(nyseAdvanceTicker, "D", close, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off, ignore_invalid_symbol=true)
nyseDeclines = request.security(nyseDeclineTicker, "D", close, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off, ignore_invalid_symbol=true)
nyseUnchanged = request.security(nyseUnchangedTicker, "D", close, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off, ignore_invalid_symbol=true)
nyseComposite = request.security(nyseCompositeTicker, "D", close, gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off, ignore_invalid_symbol=true)
nyseCompositePast = request.security(nyseCompositeTicker, "D", close[hindenburgUptrendLength], gaps=barmerge.gaps_off, lookahead=barmerge.lookahead_off, ignore_invalid_symbol=true)
nyseTotalIssues = nyseAdvances + nyseDeclines + nz(nyseUnchanged, 0.0)
breadthDataAvailable = not na(nyseNewHighs) and not na(nyseNewLows) and not na(nyseAdvances) and not na(nyseDeclines) and not na(nyseComposite) and nyseTotalIssues > 0
newHighPercent = breadthDataAvailable ? nyseNewHighs / nyseTotalIssues * 100.0 : na
newLowPercent = breadthDataAvailable ? nyseNewLows / nyseTotalIssues * 100.0 : na
// Ratio-adjusted McClellan-style oscillator using NYSE advancing and declining issues.
advanceDeclineTotal = nyseAdvances + nyseDeclines
ratioAdjustedNetAdvances = advanceDeclineTotal > 0 ? ((nyseAdvances - nyseDeclines) / advanceDeclineTotal) * 1000.0 : na
mcclellanOscillator = ta.ema(ratioAdjustedNetAdvances, 19) - ta.ema(ratioAdjustedNetAdvances, 39)
hindenburgSplitMarket = breadthDataAvailable and newHighPercent >= hindenburgThresholdPercent and newLowPercent >= hindenburgThresholdPercent
hindenburgUptrend = breadthDataAvailable and not na(nyseCompositePast) and nyseComposite > nyseCompositePast
hindenburgWeakBreadth = breadthDataAvailable and not na(mcclellanOscillator) and mcclellanOscillator < 0
hindenburgHighsNotDominant = breadthDataAvailable and nyseNewLows > 0 and nyseNewHighs <= nyseNewLows * 2.0
hindenburgTrigger = hindenburgSplitMarket and hindenburgUptrend and hindenburgWeakBreadth and hindenburgHighsNotDominant
hindenburgTriggerCount = int(math.sum(hindenburgTrigger ? 1.0 : 0.0, hindenburgClusterLookback))
hindenburgCluster = hindenburgTriggerCount >= hindenburgClusterMinimum
int hindenburgConditionsMet = 0
hindenburgConditionsMet += hindenburgSplitMarket ? 1 : 0
hindenburgConditionsMet += hindenburgUptrend ? 1 : 0
hindenburgConditionsMet += hindenburgWeakBreadth ? 1 : 0
hindenburgConditionsMet += hindenburgHighsNotDominant ? 1 : 0
string hindenburgText = "NO DATA"
color hindenburgColor = neutralColor
color hindenburgTextColor = color.white
if breadthDataAvailable
if hindenburgCluster
hindenburgText := "CLUSTER " + str.tostring(hindenburgTriggerCount)
hindenburgColor := increaseHedgeColor
else if hindenburgTrigger
hindenburgText := "TRIGGER"
hindenburgColor := hedgeOnColor
else if hindenburgConditionsMet >= 3
hindenburgText := "WATCH 3/4"
hindenburgColor := warningColor
hindenburgTextColor := color.black
else
hindenburgText := "CLEAR " + str.tostring(hindenburgConditionsMet) + "/4"
hindenburgColor := hedgeOffColor
hindenburgTextColor := color.black
// ============================================================
// RISK SCORE - HINDENBURG REMAINS INFORMATIONAL ONLY
// ============================================================
int riskScore = 0
riskScore += vixAboveMean ? 1 : 0
riskScore += vixRising ? 1 : 0
riskScore += spyVolRising ? 1 : 0
riskScore += termStress ? 1 : 0
riskScore += elevatedSkew ? 1 : 0
// ============================================================
// CURRENT RISK CONDITIONS
// ============================================================
warningCondition = validChart and vixRising and spyVolRising and (vixNearMean or vixAboveMean) and riskScore >= 2
normalHedgeCondition = validChart and vixAboveMean and vixRising and spyVolRising and riskScore >= 3
immediateHedgeCondition = validChart and riskScore >= immediateHedgeRiskScore
acuteStressCondition = validChart and immediateHedgeCondition and vixAboveMean and termStress and elevatedSkew
recoveryCondition = validChart and vixFalling and spyVolFalling and not termStress and riskScore <= maximumRecoveryRiskScore
hedgeOffCondition = validChart and vixBelowMean and vixFalling and spyVolFalling and not termStress and riskScore <= maximumHedgeOffRiskScore
// ============================================================
// CONSECUTIVE-DAY COUNTERS
// ============================================================
var int warningCount = 0
var int normalHedgeCount = 0
var int recoveryCount = 0
var int hedgeOffCount = 0
if barstate.isconfirmed
warningCount := warningCondition ? warningCount + 1 : 0
normalHedgeCount := normalHedgeCondition ? normalHedgeCount + 1 : 0
recoveryCount := recoveryCondition ? recoveryCount + 1 : 0
hedgeOffCount := hedgeOffCondition ? hedgeOffCount + 1 : 0
warningConfirmed = warningCount >= warningConfirmationDays
normalHedgeConfirmed = normalHedgeCount >= hedgeConfirmationDays
recoveryConfirmed = recoveryCount >= recoveryConfirmationDays
hedgeOffConfirmed = hedgeOffCount >= hedgeOffConfirmationDays
// ============================================================
// STATE MACHINE
// ============================================================
int HEDGE_OFF = 0
int HEDGE_WARNING = 1
int HEDGE_ON = 2
int INCREASE_HEDGE = 3
int RECOVERING = 4
var int hedgeState = HEDGE_OFF
previousHedgeState = hedgeState
if barstate.isconfirmed and validChart
if acuteStressCondition
hedgeState := INCREASE_HEDGE
else if immediateHedgeCondition
hedgeState := HEDGE_ON
else if hedgeState == HEDGE_OFF
if normalHedgeConfirmed
hedgeState := HEDGE_ON
else if warningConfirmed
hedgeState := HEDGE_WARNING
else if hedgeState == HEDGE_WARNING
if normalHedgeConfirmed
hedgeState := HEDGE_ON
else if hedgeOffConfirmed
hedgeState := HEDGE_OFF
else if hedgeState == HEDGE_ON
if recoveryConfirmed
hedgeState := RECOVERING
else if hedgeState == INCREASE_HEDGE
if normalHedgeCondition or riskScore >= 3
hedgeState := HEDGE_ON
else if recoveryConfirmed
hedgeState := RECOVERING
else if hedgeState == RECOVERING
if not recoveryCondition and riskScore >= 3
hedgeState := HEDGE_ON
else if normalHedgeCondition
hedgeState := HEDGE_ON
else if hedgeOffConfirmed
hedgeState := HEDGE_OFF
stateChanged = barstate.isconfirmed and hedgeState != previousHedgeState
hedgeWarningEvent = stateChanged and hedgeState == HEDGE_WARNING
hedgeOnEvent = stateChanged and hedgeState == HEDGE_ON
increaseHedgeEvent = stateChanged and hedgeState == INCREASE_HEDGE
recoveringEvent = stateChanged and hedgeState == RECOVERING
hedgeOffEvent = stateChanged and hedgeState == HEDGE_OFF
// ============================================================
// DISPLAY STATE
// ============================================================
string stateText = "HEDGE OFF"
string hedgeAction = "NO HEDGE"
color stateColor = hedgeOffColor
color stateTextColor = color.black
if not validChart
stateText := "USE SPY 1D"
hedgeAction := "INVALID CHART"
stateColor := neutralColor
stateTextColor := color.white
else if hedgeState == HEDGE_WARNING
stateText := "HEDGE WARNING"
hedgeAction := "PREPARE HEDGE"
stateColor := warningColor
else if hedgeState == HEDGE_ON
stateText := "HEDGE ON"
hedgeAction := "KEEP HEDGE"
stateColor := hedgeOnColor
stateTextColor := color.white
else if hedgeState == INCREASE_HEDGE
stateText := "INCREASE HEDGE"
hedgeAction := "STRONG HEDGE"
stateColor := increaseHedgeColor
stateTextColor := color.white
else if hedgeState == RECOVERING
stateText := "RECOVERING"
hedgeAction := "KEEP HEDGE"
stateColor := recoveringColor
else
stateText := "HEDGE OFF"
hedgeAction := "NO HEDGE"
string conditionText = "LOW/MIXED RISK"
color conditionColor = neutralColor
color conditionTextColor = color.white
if not validChart
conditionText := "INVALID CHART"
else if acuteStressCondition
conditionText := "ACUTE STRESS"
conditionColor := increaseHedgeColor
else if immediateHedgeCondition
conditionText := "HIGH RISK"
conditionColor := hedgeOnColor
else if normalHedgeCondition
conditionText := "RISK OFF"
conditionColor := hedgeOnColor
else if recoveryCondition
conditionText := "IMPROVING"
conditionColor := recoveringColor
conditionTextColor := color.black
else if warningCondition
conditionText := "RISK RISING"
conditionColor := warningColor
conditionTextColor := color.black
// ============================================================
// SH HEDGE SUGGESTION
// ============================================================
// SH is the selected inverse S&P 500 hedge vehicle.
// This row suggests the next SH-related step from the persistent
// hedge state. It does not calculate position size.
string hedgeIdea = "NO SH"
color hedgeIdeaColor = hedgeOffColor
color hedgeIdeaTextColor = color.black
if not validChart
hedgeIdea := "INVALID CHART"
hedgeIdeaColor := neutralColor
hedgeIdeaTextColor := color.white
else if hedgeState == HEDGE_WARNING
hedgeIdea := "WATCH SH"
hedgeIdeaColor := warningColor
hedgeIdeaTextColor := color.black
else if hedgeState == HEDGE_ON
hedgeIdea := "HOLD SH"
hedgeIdeaColor := hedgeOnColor
hedgeIdeaTextColor := color.white
else if hedgeState == INCREASE_HEDGE
hedgeIdea := "INCREASE SH"
hedgeIdeaColor := increaseHedgeColor
hedgeIdeaTextColor := color.white
else if hedgeState == RECOVERING
hedgeIdea := "HOLD / REDUCE SH"
hedgeIdeaColor := recoveringColor
hedgeIdeaTextColor := color.black
else
hedgeIdea := "NO SH / EXIT"
hedgeIdeaColor := hedgeOffColor
hedgeIdeaTextColor := color.black
// ============================================================
// OPTIONAL BACKGROUND
// ============================================================
color backgroundColor = na
if showBackground and validChart
if hedgeState == INCREASE_HEDGE
backgroundColor := color.new(increaseHedgeColor, 87)
else if hedgeState == HEDGE_ON
backgroundColor := color.new(hedgeOnColor, 90)
else if hedgeState == HEDGE_WARNING
backgroundColor := color.new(warningColor, 91)
else if hedgeState == RECOVERING
backgroundColor := color.new(recoveringColor, 92)
else
backgroundColor := color.new(hedgeOffColor, 94)
bgcolor(backgroundColor)
// ============================================================
// DASHBOARD VALUES
// ============================================================
string chartStatusText = validChart ? "SPY DAILY" : "USE SPY 1D"
color chartStatusColor = validChart ? hedgeOffColor : warningColor
string riskScoreText = str.tostring(riskScore) + " / 5"
string vixText = na(vix) ? "N/A" : str.tostring(vix, "#.##")
string vixMeanText = na(vixMean) ? "N/A" : str.tostring(vixMean, "#.##")
string vixDistanceText = na(vixDistancePercent) ? "N/A" : str.tostring(vixDistancePercent, "#.##") + "%"
string termRatioText = na(vixTermRatio) ? "N/A" : str.tostring(vixTermRatio, "#.###")
string skewText = na(skew) ? "N/A" : str.tostring(skew, "#.##")
string spyVolText = na(spyRealizedVolatility) ? "N/A" : str.tostring(spyRealizedVolatility, "#.##") + "%"
string breadthText = breadthDataAvailable ? str.tostring(newHighPercent, "#.##") + "% / " + str.tostring(newLowPercent, "#.##") + "%" : "N/A"
string confirmationText = "STABLE"
if immediateHedgeCondition
confirmationText := "IMMEDIATE OVERRIDE"
else if (hedgeState == HEDGE_OFF or hedgeState == HEDGE_WARNING) and normalHedgeCondition
confirmationText := "HEDGE " + str.tostring(math.min(normalHedgeCount, hedgeConfirmationDays)) + "/" + str.tostring(hedgeConfirmationDays)
else if hedgeState == HEDGE_OFF and warningCondition
confirmationText := "WARNING " + str.tostring(math.min(warningCount, warningConfirmationDays)) + "/" + str.tostring(warningConfirmationDays)
else if (hedgeState == HEDGE_ON or hedgeState == INCREASE_HEDGE) and recoveryCondition
confirmationText := "RECOVERY " + str.tostring(math.min(recoveryCount, recoveryConfirmationDays)) + "/" + str.tostring(recoveryConfirmationDays)
else if hedgeState == RECOVERING and hedgeOffCondition
confirmationText := "HEDGE OFF " + str.tostring(math.min(hedgeOffCount, hedgeOffConfirmationDays)) + "/" + str.tostring(hedgeOffConfirmationDays)
// ============================================================
// TOP DECISION DASHBOARD
// ============================================================
var table dashboard = table.new(
position.top_right,
2,
8,
border_width=2,
border_color=headerColor,
frame_color=headerColor,
frame_width=2)
if barstate.islast
if showDashboard
table.cell(dashboard, 0, 0, "SPY HEDGE", bgcolor=headerColor, text_color=color.white, text_size=size.normal)
table.cell(dashboard, 1, 0, chartStatusText, bgcolor=chartStatusColor, text_color=color.black, text_size=size.normal)
table.cell(dashboard, 0, 1, "HEDGE ACTION", bgcolor=headerColor, text_color=color.white, text_size=size.normal)
table.cell(dashboard, 1, 1, hedgeAction, bgcolor=stateColor, text_color=stateTextColor, text_size=size.normal)
table.cell(dashboard, 0, 2, "SH IDEA", bgcolor=headerColor, text_color=color.white, text_size=size.normal)
table.cell(dashboard, 1, 2, hedgeIdea, bgcolor=hedgeIdeaColor, text_color=hedgeIdeaTextColor, text_size=size.normal)
table.cell(dashboard, 0, 3, "CURRENT RISK", bgcolor=headerColor, text_color=color.white, text_size=size.normal)
table.cell(dashboard, 1, 3, conditionText, bgcolor=conditionColor, text_color=conditionTextColor, text_size=size.normal)
table.cell(dashboard, 0, 4, "PRICE STRUCTURE", bgcolor=headerColor, text_color=color.white, text_size=size.normal)
table.cell(dashboard, 1, 4, spyTrendText, bgcolor=spyTrendColor, text_color=spyTrendTextColor, text_size=size.normal)
table.cell(dashboard, 0, 5, "HINDENBURG", bgcolor=headerColor, text_color=color.white, text_size=size.normal)
table.cell(dashboard, 1, 5, hindenburgText, bgcolor=hindenburgColor, text_color=hindenburgTextColor, text_size=size.normal)
table.cell(dashboard, 0, 6, "RISK SCORE", bgcolor=headerColor, text_color=color.white, text_size=size.normal)
table.cell(dashboard, 1, 6, riskScoreText, bgcolor=conditionColor, text_color=conditionTextColor, text_size=size.normal)
table.cell(dashboard, 0, 7, "VIX / VIX3M", bgcolor=headerColor, text_color=color.white, text_size=size.normal)
table.cell(dashboard, 1, 7, vixText + " / " + termRatioText, bgcolor=termStress ? hedgeOnColor : neutralColor, text_color=color.white, text_size=size.normal)
else
for column = 0 to 1
for row = 0 to 7
table.cell(dashboard, column, row, "", bgcolor=color.new(color.black, 100))
// ============================================================
// ALERT CONDITIONS
// ============================================================
alertcondition(hedgeWarningEvent, title="SPY Hedge: Hedge Warning", message="SPY Daily Hedge V3: Hedge warning confirmed after the daily close.")
alertcondition(hedgeOnEvent, title="SPY Hedge: Hedge On", message="SPY Daily Hedge V3: Hedge-On state confirmed after the daily close.")
alertcondition(increaseHedgeEvent, title="SPY Hedge: Increase Hedge", message="SPY Daily Hedge V3: Acute stress detected. Review whether the hedge should be increased.")
alertcondition(recoveringEvent, title="SPY Hedge: Recovering", message="SPY Daily Hedge V3: Conditions are improving, but the hedge remains active.")
alertcondition(hedgeOffEvent, title="SPY Hedge: Hedge Off", message="SPY Daily Hedge V3: Recovery confirmed. Review whether the hedge should be removed.")
alertcondition(hindenburgTrigger, title="SPY Hedge: Hindenburg Trigger", message="SPY Daily Hedge V3: A Hindenburg-style breadth trigger occurred after the close.")
alertcondition(hindenburgCluster and not hindenburgCluster[1], title="SPY Hedge: Hindenburg Cluster", message="SPY Daily Hedge V3: A Hindenburg-style trigger cluster is active.")