本页源码来自 TradingView 公开发布的开源脚本,版权归原作者所有, 请遵循其原始许可(Pine 脚本常见 CC BY-NC-SA / MPL-2.0 / MIT)。 本项目仅用于研究检索与许可范围内的移植。
//@version=6
indicator("Macro Regime Headwind Oscillator", shorttitle="MRHO-S", overlay=false, precision=1, max_bars_back=500)
isUnsupportedTF = timeframe.isseconds or (timeframe.isintraday and timeframe.multiplier < 240)
var label tfWarn = na
if barstate.islast
if isUnsupportedTF
tfWarnTxt = "MRHO-S - UNSUPPORTED TIMEFRAME\n\nCalibrated for 4H charts and above.\nOn lower timeframes the daily macro inputs are sampled against too few chart bars, so oscillator readings, regime calls and signals lose meaning.\n\nSwitch to 4H or higher for valid output."
if na(tfWarn)
tfWarn := label.new(bar_index + 10, 100.0, tfWarnTxt, xloc=xloc.bar_index, yloc=yloc.price, color=#E74C3C, textcolor=color.black, style=label.style_label_up, size=size.small, textalign=text.align_center)
label.set_xy(tfWarn, bar_index + 10, 100.0)
label.set_text(tfWarn, tfWarnTxt)
else if not na(tfWarn)
label.delete(tfWarn)
tfWarn := na
grpA = "Engine A - Inflation / Tightening Basket"
usdTicker = input.symbol("TVC:DXY", "US Dollar Index", group=grpA, tooltip="Symbol used to measure US Dollar strength/weakness. A rising dollar is treated as a tightening / risk-off force inside Engine A. Default is the ICE US Dollar Index (DXY).")
yieldTicker = input.symbol("TVC:US10Y", "Basket Yield (US02Y/US05Y/US10Y)", group=grpA, tooltip="Government bond yield symbol used as the 'cost of money' component of Engine A. Rising yields are read as tightening. Swap this for US02Y or US05Y to emphasize a different part of the curve.")
energyTicker = input.symbol("TVC:USOIL", "Energy (WTI Crude)", group=grpA, tooltip="Energy price proxy (default WTI Crude). Rising energy prices are treated as inflationary / tightening pressure on the economy.")
inflTicker = input.symbol("FRED:T10YIE", "10Y Breakeven Inflation", group=grpA, tooltip="Market-implied 10-year inflation expectations (breakeven rate). Rising breakevens add to the tightening score. Only used if 'Include Breakevens in Basket' is enabled.")
useInfl = input.bool(true, "Include Breakevens in Basket", group=grpA, tooltip="When enabled, 10Y breakeven inflation is included as a 4th score/vote in Engine A. Disable to use a 3-asset basket (USD, Yield, Oil only).")
lookback = input.int(50, "Z-Score Lookback (bars)", minval=10, group=grpA, tooltip="Number of daily bars used for the rolling mean/standard deviation behind every z-score in Engine A and the shock terms in Engine B. Shorter = more reactive and noisier. Longer = smoother and slower to flag new tightening/easing moves.")
maLen = input.int(20, "Directional MA (confluence votes)", minval=2, group=grpA, tooltip="Length of the simple moving average each Engine A asset is compared against to cast its directional vote (above = tightening vote, below = easing vote). Used only for the agreement/confidence calculation, not the raw score.")
confThresh = input.float(0.66, "Min Agreement for Full Signal", minval=0.5, maxval=1.0, step=0.01, group=grpA, tooltip="Minimum fraction of the 4 Engine A assets that must agree on direction for the basket score to be used at full strength. Below this threshold the score is discounted by the multiplier below.")
lowConfMult = input.float(0.35, "Multiplier When Assets Disagree", minval=0.0, maxval=1.0, step=0.05, group=grpA, tooltip="Scaling factor applied to Engine A's score when the 4 assets fail to reach the minimum agreement threshold above. Lower values mute the basket more aggressively during periods of internal disagreement.")
grpB = "Engine B - Stress / Growth-Shock Index"
vixTicker = input.symbol("CBOE:VIX", "VIX", group=grpB, tooltip="CBOE Volatility Index. Used for both its historical percentile level and sudden volatility shocks.")
vix3mTicker = input.symbol("CBOE:VIX3M", "VIX 3-Month", group=grpB, tooltip="3-month CBOE Volatility Index. Compared against spot VIX to detect term-structure inversion (backwardation), a classic acute-stress signal.")
hyTicker = input.symbol("FRED:BAMLH0A0HYM2", "HY Credit Spread (OAS)", group=grpB, tooltip="ICE BofA US High Yield Option-Adjusted Spread. Widening spreads indicate rising credit stress and deteriorating risk appetite.")
y2Ticker = input.symbol("TVC:US02Y", "2Y Yield (curve)", group=grpB, tooltip="2-Year Treasury yield, used with the 10-Year yield below to build the yield-curve (bull-steepener) stress component.")
y10Ticker = input.symbol("TVC:US10Y", "10Y Yield (curve)", group=grpB, tooltip="10-Year Treasury yield, used with the 2-Year yield above to build the yield-curve (bull-steepener) stress component.")
useVix = input.bool(true, "Use VIX Level/Shock", group=grpB, tooltip="Enable/disable the VIX level-percentile and shock component inside the Stress Index.")
useTerm = input.bool(true, "Use VIX Term Structure", group=grpB, tooltip="Enable/disable the VIX / VIX3M term-structure component inside the Stress Index.")
useHY = input.bool(true, "Use HY Credit Spreads", group=grpB, tooltip="Enable/disable the High-Yield credit spread component inside the Stress Index.")
useCurve = input.bool(true, "Use Bull-Steepener Signal", group=grpB, tooltip="Enable/disable the yield-curve bull-steepener component (falling 2Y yield + steepening curve) — a classic growth-scare signal — inside the Stress Index.")
stressLen = input.int(252, "Percentile Lookback (bars)", minval=50, group=grpB, tooltip="Number of daily bars used for the percentile-rank calculations of VIX and HY spreads (252 is approximately one trading year).")
rocLen = input.int(10, "Curve Change Length (bars)", minval=2, group=grpB, tooltip="Number of bars used to measure the recent change in the 2Y yield and the 10Y-2Y curve for the bull-steepener component.")
stressLo = input.float(0.35, "Stress Gate Starts", minval=0.0, maxval=1.0, step=0.05, group=grpB, tooltip="Stress Index level at which the 'stress gate' begins to open, i.e. starts influencing the blend and the Deflation Flip. Below this level stress is treated as negligible.")
stressHi = input.float(0.65, "Stress Gate Full", minval=0.0, maxval=1.0, step=0.05, group=grpB, tooltip="Stress Index level at which the 'stress gate' is fully open (maximum influence on the blend and the Deflation Flip). Between Stress Gate Starts and here, the gate ramps up linearly.")
stressBaseW = input.float(0.30, "Base Stress Weight", minval=0.0, maxval=1.0, step=0.05, group=grpB, tooltip="Minimum weight the Stress Index always carries in the final blend, even while markets are calm. Effective weight grows above this floor as the stress gate opens.")
grpR = "Regime Switching (Rolling Correlation)"
useChartSym = input.bool(true, "Use Current Chart Symbol as Benchmark", group=grpR, tooltip="When enabled, the regime-switching correlation is computed between the macro basket and the symbol currently on your chart. When disabled, the fixed benchmark symbol below is used instead.")
benchTicker = input.symbol("SP:SPX", "Benchmark Symbol (if toggle OFF)", group=grpR, tooltip="Benchmark symbol used for the regime-switching correlation when 'Use Current Chart Symbol as Benchmark' is disabled.")
corrLen = input.int(30, "Correlation Length", minval=10, group=grpR, tooltip="Number of daily bars used for the rolling correlation between the benchmark's returns and the change in Engine A's raw score. Shorter reacts faster to regime shifts; longer is more stable.")
corrSmooth = input.int(10, "Correlation Smoothing (EMA)", minval=1, group=grpR, tooltip="EMA length applied to the raw rolling correlation to reduce noise before it sets the Inflation Weight and the Deflation Flip.")
regimeSharp = input.float(1.5, "Regime Sharpness", minval=0.5, maxval=5.0, step=0.1, group=grpR, tooltip="Controls how aggressively the Inflation Weight reacts to changes in correlation. Higher values make the regime switch faster and more binary; lower values make it more gradual.")
muteFloor = input.float(0.40, "Reflation Mute Floor", minval=0.0, maxval=1.0, step=0.05, group=grpR, tooltip="Minimum weight kept on a rising basket when the benchmark is rising WITH it (positive correlation, no stress) — i.e. a reflation regime.")
grpEMA = "Daily 200 EMA (Visual & Signal Filter)"
showEMA2 = input.bool(true, "Show Daily 200 EMA", group=grpEMA, tooltip="Toggles whether the Daily 200 EMA line is drawn on the price chart.")
ema2Len = input.int(200, "EMA Length", minval=1, maxval=500, group=grpEMA, tooltip="Length of the Exponential Moving Average, calculated on the timeframe selected below regardless of your chart's own timeframe.")
htf2 = input.timeframe("1D", "Timeframe", group=grpEMA, tooltip="Timeframe used to calculate the EMA. Default is Daily. The value is fetched in a non-repainting way using the previous closed bar of this timeframe.")
slopeBars = input.int(10, "Slope Lookback Bars", minval=1, maxval=100, group=grpEMA, tooltip="Number of bars (on the EMA's own timeframe) used to measure the EMA's recent percentage slope, which determines its Bullish / Bearish / Flat color.")
flatThresh = input.float(0.05, "Flat Threshold (%)", minval=0.001, step=0.005, group=grpEMA, tooltip="Minimum absolute slope percentage required for the EMA to be classified Bullish or Bearish. Slopes smaller than this are Flat/Sideways. Note: with a 200-length EMA this threshold can rarely be reached — raise it if you want the Flat state to appear more often.")
lineWidth2 = input.int(2, "Line Width", minval=1, maxval=5, group=grpEMA, tooltip="Line width of the Daily 200 EMA as drawn on the price chart.")
bullColor = input.color(color.rgb(37, 253, 8), "Bullish Color", group=grpEMA, tooltip="Color used for the EMA line when its slope is classified Bullish (rising faster than the Flat Threshold).")
bearColor = input.color(color.rgb(247, 11, 11), "Bearish Color", group=grpEMA, tooltip="Color used for the EMA line when its slope is classified Bearish (falling faster than the Flat Threshold).")
flatColor = input.color(color.rgb(120, 120, 120), "Flat / Sideways Color", group=grpEMA, tooltip="Color used for the EMA line when its slope is within the Flat Threshold (sideways).")
grpV = "Visuals & Signals"
smoothLen = input.int(3, "Output Smoothing (EMA)", minval=1, group=grpV, tooltip="EMA length applied to the raw 0-100 score before it is plotted and evaluated for signals. Higher values produce a smoother, slower oscillator.")
upperTh = input.float(70.0, "High Headwind Threshold", group=grpV, tooltip="Oscillator level above which the regime is classified 'High Headwind' and the High Risk signal can fire.")
lowerTh = input.float(30.0, "Strong Tailwind Threshold", group=grpV, tooltip="Oscillator level below which the regime is classified 'Strong Tailwind' and the Strong Long signal can fire.")
neutralBand = input.float(5.0, "Neutral Band Around 50", minval=0.0, group=grpV, tooltip="Distance above/below the center line (50) treated as a Neutral regime on the dashboard, rather than Headwind or Tailwind.")
showEngines = input.bool(false, "Show Engine Components", group=grpV, tooltip="When enabled, plots the raw Engine A (effective) and Engine B (Stress Index x100) lines for diagnostic/educational purposes.")
showTable = input.bool(true, "Show Regime Dashboard", group=grpV, tooltip="Toggles the on-chart dashboard table summarizing the current regime, oscillator value, correlation, weights, stress, agreement, deflation flip state, active symbol/timeframe, and the last signal fired.")
grpSig = "Signal Confirmation"
confirmOnClose = input.bool(true, "Wait for Candle Close (Non-Repainting Signals)", group=grpSig, tooltip="When enabled (recommended), all crossover-based signals (Long, Strong Long, Down, High Risk) and their matching alerts are only evaluated on confirmed/closed bars, preventing a signal from appearing and then disappearing intrabar. When disabled, signals evaluate in real time on the forming bar and may change before that bar closes.")
gateHighRiskEMA = input.bool(false, "Gate High Risk Signal with Daily 200 EMA", group=grpSig, tooltip="When enabled, the High Risk signal only fires while price is below the Daily 200 EMA, matching the filter already applied to the other three signals. When disabled (default), High Risk fires purely from the oscillator crossing the High Headwind Threshold, regardless of EMA position.")
grpDash = "Dashboard Position & Size"
dashPosInput = input.string("Top Right", "Dashboard Position", options=["Top Left","Top Center","Top Right","Middle Left","Middle Center","Middle Right","Bottom Left","Bottom Center","Bottom Right"], group=grpDash, tooltip="Screen position of the regime dashboard table.")
dashSizeInput = input.string("Small", "Dashboard Text Size", options=["Tiny","Small","Normal","Large","Huge"], group=grpDash, tooltip="Text size used for every cell in the regime dashboard table.")
f_clamp(float x, float lo, float hi) =>
math.max(lo, math.min(hi, x))
f_tanh(float x) =>
xc = f_clamp(x, -10.0, 10.0)
e = math.exp(2.0 * xc)
(e - 1.0) / (e + 1.0)
f_z(float src, int len) =>
m = ta.sma(src, len)
s = ta.stdev(src, len)
na(s) ? na : s > 0 ? (src - m) / s : 0.0
f_sq(float src, int len) =>
f_tanh(f_z(src, len) / 2.0)
f_vote(float src, int len) =>
ma = ta.sma(src, len)
na(src) or na(ma) ? na : src > ma ? 1.0 : -1.0
f_wavg5(float v1, float w1, float v2, float w2, float v3, float w3, float v4, float w4, float v5, float w5) =>
float s = 0.0
float ws = 0.0
if not na(v1) and w1 > 0
s += v1 * w1
ws += w1
if not na(v2) and w2 > 0
s += v2 * w2
ws += w2
if not na(v3) and w3 > 0
s += v3 * w3
ws += w3
if not na(v4) and w4 > 0
s += v4 * w4
ws += w4
if not na(v5) and w5 > 0
s += v5 * w5
ws += w5
ws > 0 ? s / ws : na
f_dashPos(string p) =>
switch p
"Top Left" => position.top_left
"Top Center" => position.top_center
"Top Right" => position.top_right
"Middle Left" => position.middle_left
"Middle Center" => position.middle_center
"Middle Right" => position.middle_right
"Bottom Left" => position.bottom_left
"Bottom Center" => position.bottom_center
=> position.bottom_right
f_dashSize(string s) =>
switch s
"Tiny" => size.tiny
"Small" => size.small
"Normal" => size.normal
"Large" => size.large
=> size.huge
sigTF = "1D"
usd = request.security(usdTicker, sigTF, close[1], lookahead=barmerge.lookahead_on)
yld = request.security(yieldTicker, sigTF, close[1], lookahead=barmerge.lookahead_on)
oil = request.security(energyTicker, sigTF, close[1], lookahead=barmerge.lookahead_on)
infl = request.security(inflTicker, sigTF, close[1], lookahead=barmerge.lookahead_on)
vix = request.security(vixTicker, sigTF, close[1], lookahead=barmerge.lookahead_on)
vix3m = request.security(vix3mTicker, sigTF, close[1], lookahead=barmerge.lookahead_on)
hy = request.security(hyTicker, sigTF, close[1], lookahead=barmerge.lookahead_on)
y2 = request.security(y2Ticker, sigTF, close[1], lookahead=barmerge.lookahead_on)
y10 = request.security(y10Ticker, sigTF, close[1], lookahead=barmerge.lookahead_on)
targetBenchSymbol = useChartSym ? syminfo.tickerid : benchTicker
bench = request.security(targetBenchSymbol, sigTF, close[1], lookahead=barmerge.lookahead_on)
[htf2EMA, htf2SlopePct] = request.security(syminfo.tickerid, htf2, [ta.ema(close[1], ema2Len), ((ta.ema(close[1], ema2Len) - ta.ema(close[1], ema2Len)[slopeBars]) / math.max(close[1], 1e-10)) * 100.0], lookahead=barmerge.lookahead_on)
isFlat2 = math.abs(htf2SlopePct) < flatThresh
isBull2 = not isFlat2 and htf2SlopePct > 0
isBear2 = not isFlat2 and htf2SlopePct < 0
ema2Color = isFlat2 ? flatColor : isBull2 ? bullColor : bearColor
sUsd = f_sq(usd, lookback)
sYld = f_sq(yld, lookback)
sOil = f_sq(oil, lookback)
sInflRaw = f_sq(infl, lookback)
sInfl = useInfl ? sInflRaw : na
SA_raw = f_wavg5(sUsd, 1.0, sYld, 1.0, sOil, 1.0, sInfl, 1.0, na, 0.0)
vUsd = f_vote(usd, maLen)
vYld = f_vote(yld, maLen)
vOil = f_vote(oil, maLen)
vInflRaw = f_vote(infl, maLen)
vInfl = useInfl ? vInflRaw : na
nVotes = (na(vUsd) ? 0.0 : 1.0) + (na(vYld) ? 0.0 : 1.0) + (na(vOil) ? 0.0 : 1.0) + (na(vInfl) ? 0.0 : 1.0)
sumVotes = nz(vUsd) + nz(vYld) + nz(vOil) + nz(vInfl)
agree = nVotes > 0 ? (nVotes + math.abs(sumVotes)) / (2.0 * nVotes) : 0.5
confMult = agree >= confThresh ? agree : lowConfMult
SA = nz(SA_raw, 0.0) * confMult
vixPct = ta.percentrank(vix, stressLen) / 100.0
vixShock = math.max(0.0, f_sq(vix, lookback))
cVix = useVix ? 0.5 * vixPct + 0.5 * vixShock : na
termRatio = vix / vix3m
cTerm = useTerm ? f_clamp((termRatio - 0.90) / 0.20, 0.0, 1.0) : na
hyPct = ta.percentrank(hy, stressLen) / 100.0
hyShock = math.max(0.0, f_sq(hy, lookback))
cHY = useHY ? 0.4 * hyPct + 0.6 * hyShock : na
curve = y10 - y2
dCurve = ta.change(curve, rocLen)
d2 = ta.change(y2, rocLen)
dCurveS = f_tanh(f_z(dCurve, lookback) / 2.0)
cCurve = useCurve ? (d2 < 0 and dCurve > 0 ? math.max(0.0, dCurveS) : 0.0) : na
SB = nz(f_wavg5(cVix, 1.0, cTerm, 0.75, cHY, 1.0, cCurve, 0.5, na, 0.0), 0.0)
stressGate = f_clamp((SB - stressLo) / math.max(stressHi - stressLo, 0.01), 0.0, 1.0)
benchRet = math.log(bench / math.max(bench[1], 1e-10))
basketChg = ta.change(SA_raw)
rhoRaw = ta.correlation(benchRet, basketChg, corrLen)
rho = ta.ema(nz(rhoRaw, 0.0), corrSmooth)
wInfl = f_clamp(0.5 - 0.5 * regimeSharp * rho, 0.0, 1.0)
flip = stressGate * (1.0 - wInfl)
effA = SA >= 0 ? SA * (muteFloor + (1.0 - muteFloor) * math.max(wInfl, stressGate)) : SA * (1.0 - 2.0 * flip)
benchVol = ta.stdev(benchRet, corrLen)
basketVol = ta.stdev(basketChg, corrLen)
rawBeta = basketVol > 0 ? (rho * benchVol / basketVol) : rho
symBeta = f_clamp(math.abs(rawBeta), 0.5, 2.0)
benchZ = f_z(bench, lookback)
macroZ = SA_raw * 2.0
symDiverg = f_clamp((benchZ - macroZ) * 0.15, -0.25, 0.25)
wS = stressBaseW + (1.0 - stressBaseW) * stressGate
stressSigned = 2.0 * SB - 1.0
contribA = (1.0 - wS) * effA
contribB = wS * stressSigned
scoreAdapted = f_clamp((contribA + contribB) * symBeta - symDiverg, -1.0, 1.0)
oscRaw = 50.0 + 50.0 * scoreAdapted
osc = ta.ema(oscRaw, smoothLen)
oscFinal = nz(osc, 50.0)
isTypeB = math.abs(contribB) > math.abs(contribA)
regimeTypeBNum = isTypeB ? 1.0 : 0.0
isHead = oscFinal >= 50.0 + neutralBand
isTail = oscFinal <= 50.0 - neutralBand
priceBullish = close >= close[1] or oscFinal <= nz(oscFinal[1], oscFinal)
barConfirmOk = not confirmOnClose or barstate.isconfirmed
bullCrossRaw = ta.crossunder(oscFinal, 50.0)
bearCrossRaw = ta.crossover(oscFinal, 50.0)
strongBullRaw = ta.crossunder(oscFinal, lowerTh)
strongBearRaw = ta.crossover(oscFinal, upperTh)
bullCross = bullCrossRaw and barConfirmOk
bearCross = bearCrossRaw and barConfirmOk
strongBull = strongBullRaw and barConfirmOk
strongBear = strongBearRaw and barConfirmOk
isAboveEMA = close > htf2EMA
isBelowEMA = close < htf2EMA
bullCrossSig = bullCross and isAboveEMA
strongBullSig = strongBull and isAboveEMA
bearCrossSig = bearCross and isBelowEMA
strongBearSig = gateHighRiskEMA ? (strongBear and isBelowEMA) : strongBear
var string lastSig = "none"
if bullCrossSig
lastSig := "LONG"
if strongBullSig
lastSig := "STRONG LONG"
if bearCrossSig
lastSig := "DOWN"
if strongBearSig
lastSig := "HIGH RISK"
hline(50, "Center Line", color=color.gray, linestyle=hline.style_dashed)
hline(upperTh, "High Headwind", color=color.new(#CB0000, 50), linestyle=hline.style_dotted)
hline(lowerTh, "Strong Tailwind", color=color.new(#1FFF00, 50), linestyle=hline.style_dotted)
colTypeA = #CB0000
colTypeB = #8B001A
colTail = #1FFF00
colNeut = #F0FF00
dashGreen = #2ECC71
dashRed = #E74C3C
targetHeadColor = isTypeB ? colTypeB : colTypeA
dynamicGradColor = oscFinal >= 50.0 ? color.from_gradient(oscFinal, 50.0, 62.0, colNeut, targetHeadColor) : color.from_gradient(oscFinal, 38.0, 50.0, colTail, colNeut)
candleCol = dynamicGradColor
barcolor(candleCol, title="Momentum Candle Body Color")
plotcandle(open, high, low, close, title="Momentum Candle Wicks & Borders", color=candleCol, wickcolor=candleCol, bordercolor=candleCol, force_overlay=true)
plot(oscFinal, "Headwind Area Gradient", color=dynamicGradColor, style=plot.style_columns, histbase=50)
plot(showEngines ? 50.0 + 50.0 * effA : na, "Engine A (effective)", color=color.new(#F0FF00, 30), linewidth=1)
plot(showEngines ? 100.0 * SB : na, "Stress Index (x100)", color=color.new(#8B001A, 30), linewidth=1)
plot(showEMA2 ? htf2EMA : na, title="Daily 200 EMA (Visual)", color=ema2Color, linewidth=lineWidth2, force_overlay=true)
plotshape(bullCrossSig ? oscFinal : na, title="Long Signal", style=shape.labelup, location=location.absolute, color=#03BF31, text="LONG", textcolor=color.black, size=size.tiny)
plotshape(strongBullSig ? oscFinal : na, title="Strong Long", style=shape.labelup, location=location.absolute, color=#03BF31, text="L+", textcolor=color.black, size=size.tiny)
plotshape(bearCrossSig ? oscFinal : na, title="Trend Down", style=shape.labeldown, location=location.absolute, color=#A51212, text="DOWN", textcolor=color.black, size=size.tiny)
plotshape(strongBearSig ? oscFinal : na, title="High Risk", style=shape.labeldown, location=location.absolute, color=#A51212, text="RISK", textcolor=color.black, size=size.tiny)
var table dash = table.new(f_dashPos(dashPosInput), 2, 9, bgcolor=color.black, border_width=1, border_color=color.new(color.gray, 60))
if showTable and barstate.islast
dashSize = f_dashSize(dashSizeInput)
regimeTxt = isHead ? (isTypeB ? "TYPE B - Stress / Growth Shock" : "TYPE A - Inflation / Tightening") : isTail ? "TAILWIND - Supportive" : "NEUTRAL"
regimeCol = isHead ? dashRed : isTail ? dashGreen : color.white
oscCol = priceBullish ? dashGreen : dashRed
benchLabel = useChartSym ? "Chart vs Basket Rho" : "SPX vs Basket Rho"
symInfoTxt = syminfo.ticker + " · " + timeframe.period
table.cell(dash, 0, 0, "Regime", text_color=color.white, text_size=dashSize)
table.cell(dash, 1, 0, regimeTxt, text_color=regimeCol, text_size=dashSize)
table.cell(dash, 0, 1, "Oscillator", text_color=color.white, text_size=dashSize)
table.cell(dash, 1, 1, str.tostring(oscFinal, "#.0") + (priceBullish ? " UP" : " DN"), text_color=oscCol, text_size=dashSize)
table.cell(dash, 0, 2, benchLabel, text_color=color.white, text_size=dashSize)
table.cell(dash, 1, 2, str.tostring(rho, "#.00") + (rho < 0 ? " (Inflation)" : " (Growth)"), text_color=color.white, text_size=dashSize)
table.cell(dash, 0, 3, "Inflation Weight", text_color=color.white, text_size=dashSize)
table.cell(dash, 1, 3, str.tostring(wInfl * 100.0, "#") + "%", text_color=color.white, text_size=dashSize)
table.cell(dash, 0, 4, "Stress Index", text_color=color.white, text_size=dashSize)
table.cell(dash, 1, 4, str.tostring(SB * 100.0, "#") + "%", text_color=SB > stressHi ? dashRed : color.white, text_size=dashSize)
table.cell(dash, 0, 5, "Basket Agreement", text_color=color.white, text_size=dashSize)
table.cell(dash, 1, 5, str.tostring(agree * 100.0, "#") + "%", text_color=color.white, text_size=dashSize)
table.cell(dash, 0, 6, "Deflation Flip", text_color=color.white, text_size=dashSize)
table.cell(dash, 1, 6, flip > 0.5 ? "ACTIVE" : "off", text_color=flip > 0.5 ? dashRed : color.white, text_size=dashSize)
table.cell(dash, 0, 7, "Last Signal", text_color=color.white, text_size=dashSize)
table.cell(dash, 1, 7, lastSig, text_color=(lastSig == "LONG" or lastSig == "STRONG LONG") ? dashGreen : (lastSig == "DOWN" or lastSig == "HIGH RISK") ? dashRed : color.white, text_size=dashSize)
table.cell(dash, 0, 8, "Chart / TF", text_color=color.white, text_size=dashSize)
table.cell(dash, 1, 8, symInfoTxt, text_color=color.white, text_size=dashSize)
alertcondition(bullCrossSig, "Long / Bullish Macro Shift", "MRHO crossed below 50 & above Daily 200 EMA - macro tailwind: long signal.")
alertcondition(bearCrossSig, "Bearish / Downward Trend Shift", "MRHO crossed above 50 & below Daily 200 EMA - macro headwind: down signal.")
alertcondition(strongBullSig, "Strong Tailwind", "MRHO entered strong tailwind zone (<30) & above Daily 200 EMA.")
alertcondition(strongBearSig, "High Headwind Risk", "MRHO entered high headwind zone (>70).")
alertcondition(ta.crossover(flip, 0.5) and barConfirmOk, "Type B Flip Activated", "Stress + growth regime: falling yields/oil now read as bearish.")
alertcondition(ta.crossunder(flip, 0.5) and barConfirmOk, "Type B Flip Deactivated", "Stress + growth regime flip has turned off; falling yields/oil reverting to normal tailwind interpretation.")
alertcondition(ta.crossunder(oscFinal, 50) and barConfirmOk, "Headwind Easing", "MRHO crossed back below 50.")
alertcondition(ta.crossover(regimeTypeBNum, 0.5) and barConfirmOk, "Regime Shifted to Type B", "The dominant driver of the current headwind/tailwind has shifted to the Stress / Growth-Shock engine.")
alertcondition(ta.crossunder(regimeTypeBNum, 0.5) and barConfirmOk, "Regime Shifted to Type A", "The dominant driver of the current headwind/tailwind has shifted to the Inflation / Tightening engine.")