OPEN-SOURCE SCRIPT
Macro Risk Sentiment

Overview
This indicator provides a simple traffic light for your trading: green means go, red means slow down.
The background color appears directly on your price chart and in the oscillator pane below. When green, macro conditions favor risk assets and you can trade with full conviction. When red, the indicator suggests reducing position sizes, tightening stops, or stepping aside entirely.
The oscillator pane shows the underlying calculation so you can see how close the market is to flipping regimes.
The Core Idea
Markets move in risk cycles. When institutional money is confident, it flows into equities, high-yield bonds, and away from safe havens. When fear takes over, money rotates into treasuries, the dollar strengthens, and volatility spikes.
This indicator reads those flows by monitoring four markets simultaneously:
Risk-On Signals (good for stocks when rising)
TLT - Long-term Treasury bonds
JNK - High-yield corporate credit
Risk-Off Signals (bad for stocks when rising)
DXY - US Dollar strength
VIX - Market volatility
When bonds and credit are strong relative to their recent history while the dollar and volatility are weak, the background turns green. You have a tailwind. When the opposite occurs, the background turns red. You are fighting the current.
How It Works
Step 1: Z-Score Normalization
Each input is converted to a z-score: how many standard deviations the current value is from its 252-day rolling average. This puts all four inputs on a comparable scale regardless of their absolute price levels.
Step 2: Composite Calculation
Macro Score = (TLT z-score + JNK z-score) minus (DXY z-score + VIX z-score)
Risk-on inputs contribute positively when elevated. Risk-off inputs subtract when elevated. The result is clamped between -1.5 and +1.5 and smoothed with EMAs.
Step 3: State Machine
The indicator uses crossover-based transitions with memory:
RISK ON triggers when the smoothed macro line crosses above its signal line.
RISK OFF triggers when the macro line crosses below its signal line, or when price breaks below its EMA while the macro value is negative (double confirmation exit).
How to Use It
Green Background - Full Steam Ahead
Macro conditions support risk-taking. This is when trend-following strategies tend to work best. Use normal position sizes, take breakout trades, and hold winners longer.
Red Background - Reduce Risk
The macro wind is against you. Consider smaller positions, quicker profit-taking, or sitting out entirely. Mean-reversion setups may work better than trend-following during these periods. Many major drawdowns occur during red regimes.
The Oscillator Pane
The colored line is the macro reading, the white line is its signal. When the colored line crosses above the signal, conditions turn bullish. When it crosses below, conditions turn bearish. The zero line represents neutral. Positive values mean macro conditions are better than the one-year average.
What Makes This Original
This implementation combines z-score normalization across multiple asset classes with a state machine approach that reduces whipsaws. The price filter acts as a circuit breaker but only triggers exits when macro conditions are also deteriorating, preventing premature exits during temporary price weakness.
Settings Guide
Main Settings
Z-Score Lookback (default 252) - Period for calculating mean and standard deviation. 252 bars equals one trading year on daily charts.
Macro EMA (default 7) - Smoothing applied to the raw composite score.
Signal EMA (default 8) - Secondary smoothing for the crossover signal line.
Price Filter
Enable Price Filter (default On) - When enabled, price breaking below the EMA triggers an exit only if the macro value is also negative.
EMA Length (default 20) - The EMA period for the price filter.
Data Sources
Each source (TLT, JNK, DXY, VIX) can be enabled or disabled and weighted from 0 to 3. Default is equal weighting (1.0) for all sources.
Limitations
This is a daily-timeframe indicator. On intraday charts, signals reflect yesterday's macro reading until the day closes.
The z-score lookback creates recency bias. What was normal over the past year may not reflect longer-term historical norms.
Intermarket correlations can change. What worked in recent decades may shift in different monetary regimes.
Not all equity drawdowns come with macro warning. Flash crashes and idiosyncratic events can occur without macro deterioration.
The indicator identifies conditions, not predictions. Green does not guarantee gains. Red does not guarantee losses.
Disclaimer
This indicator is for educational and informational purposes only. It does not constitute financial advice.
Green background does not mean buy. Red background does not mean sell. These are environmental readings to help you calibrate your risk-taking, not trade signals.
Past intermarket relationships do not guarantee future behavior. Always conduct your own research. Consider your personal risk tolerance. Never risk more than you can afford to lose.
This indicator provides a simple traffic light for your trading: green means go, red means slow down.
The background color appears directly on your price chart and in the oscillator pane below. When green, macro conditions favor risk assets and you can trade with full conviction. When red, the indicator suggests reducing position sizes, tightening stops, or stepping aside entirely.
The oscillator pane shows the underlying calculation so you can see how close the market is to flipping regimes.
The Core Idea
Markets move in risk cycles. When institutional money is confident, it flows into equities, high-yield bonds, and away from safe havens. When fear takes over, money rotates into treasuries, the dollar strengthens, and volatility spikes.
This indicator reads those flows by monitoring four markets simultaneously:
Risk-On Signals (good for stocks when rising)
TLT - Long-term Treasury bonds
JNK - High-yield corporate credit
Risk-Off Signals (bad for stocks when rising)
DXY - US Dollar strength
VIX - Market volatility
When bonds and credit are strong relative to their recent history while the dollar and volatility are weak, the background turns green. You have a tailwind. When the opposite occurs, the background turns red. You are fighting the current.
How It Works
Step 1: Z-Score Normalization
Each input is converted to a z-score: how many standard deviations the current value is from its 252-day rolling average. This puts all four inputs on a comparable scale regardless of their absolute price levels.
Step 2: Composite Calculation
Macro Score = (TLT z-score + JNK z-score) minus (DXY z-score + VIX z-score)
Risk-on inputs contribute positively when elevated. Risk-off inputs subtract when elevated. The result is clamped between -1.5 and +1.5 and smoothed with EMAs.
Step 3: State Machine
The indicator uses crossover-based transitions with memory:
RISK ON triggers when the smoothed macro line crosses above its signal line.
RISK OFF triggers when the macro line crosses below its signal line, or when price breaks below its EMA while the macro value is negative (double confirmation exit).
How to Use It
Green Background - Full Steam Ahead
Macro conditions support risk-taking. This is when trend-following strategies tend to work best. Use normal position sizes, take breakout trades, and hold winners longer.
Red Background - Reduce Risk
The macro wind is against you. Consider smaller positions, quicker profit-taking, or sitting out entirely. Mean-reversion setups may work better than trend-following during these periods. Many major drawdowns occur during red regimes.
The Oscillator Pane
The colored line is the macro reading, the white line is its signal. When the colored line crosses above the signal, conditions turn bullish. When it crosses below, conditions turn bearish. The zero line represents neutral. Positive values mean macro conditions are better than the one-year average.
What Makes This Original
This implementation combines z-score normalization across multiple asset classes with a state machine approach that reduces whipsaws. The price filter acts as a circuit breaker but only triggers exits when macro conditions are also deteriorating, preventing premature exits during temporary price weakness.
Settings Guide
Main Settings
Z-Score Lookback (default 252) - Period for calculating mean and standard deviation. 252 bars equals one trading year on daily charts.
Macro EMA (default 7) - Smoothing applied to the raw composite score.
Signal EMA (default 8) - Secondary smoothing for the crossover signal line.
Price Filter
Enable Price Filter (default On) - When enabled, price breaking below the EMA triggers an exit only if the macro value is also negative.
EMA Length (default 20) - The EMA period for the price filter.
Data Sources
Each source (TLT, JNK, DXY, VIX) can be enabled or disabled and weighted from 0 to 3. Default is equal weighting (1.0) for all sources.
Limitations
This is a daily-timeframe indicator. On intraday charts, signals reflect yesterday's macro reading until the day closes.
The z-score lookback creates recency bias. What was normal over the past year may not reflect longer-term historical norms.
Intermarket correlations can change. What worked in recent decades may shift in different monetary regimes.
Not all equity drawdowns come with macro warning. Flash crashes and idiosyncratic events can occur without macro deterioration.
The indicator identifies conditions, not predictions. Green does not guarantee gains. Red does not guarantee losses.
Disclaimer
This indicator is for educational and informational purposes only. It does not constitute financial advice.
Green background does not mean buy. Red background does not mean sell. These are environmental readings to help you calibrate your risk-taking, not trade signals.
Past intermarket relationships do not guarantee future behavior. Always conduct your own research. Consider your personal risk tolerance. Never risk more than you can afford to lose.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source veröffentlicht. Auf diese Weise können nun auch andere Trader das Script rezensieren und die Funktionalität überprüfen. Vielen Dank an den Autor! Sie können das Script kostenlos verwenden, aber eine Wiederveröffentlichung des Codes unterliegt unseren Hausregeln.
Haftungsausschluss
Die Informationen und Veröffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlägen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.