OPEN-SOURCE SCRIPT
Macro Risk Sentiment - Intermarket Timing Signal

Overview
This indicator builds a composite macro sentiment score by analyzing intermarket relationships between bonds, credit spreads, the US dollar, and volatility. The core premise is that these markets often signal shifts in risk appetite before equities react, providing a timing edge for managing exposure.
When macro conditions favor risk assets, the indicator signals RISK-ON (green). When conditions deteriorate, it signals RISK-OFF (red). This is not a predictive tool but rather a systematic way to assess the current macro environment.
The Problem It Solves
Markets do not move in isolation. Before major equity drawdowns, stress often appears first in credit markets, bonds, and volatility. By monitoring these leading indicators systematically, we can identify periods when holding equity exposure carries elevated risk.
The goal is not to catch every move but to avoid the worst drawdowns by stepping aside when multiple macro factors align negatively.
How It Works
Step 1: Data Collection
The indicator pulls daily data from four key markets:
Risk-On Inputs (positive for equities when rising):
- TLT (20+ Year Treasury Bonds): Rising bonds can signal improving liquidity or flight-to-safety ending
- JNK (High-Yield Corporate Bonds): Rising junk bonds indicate credit conditions improving and risk appetite increasing
Risk-Off Inputs (negative for equities when rising):
- DXY (US Dollar Index): Strong dollar tightens global financial conditions and signals risk-off flows
- VIX (Volatility Index): Elevated VIX indicates fear and hedging demand
Step 2: Z-Score Normalization
Each input trades at different absolute levels, so direct comparison is impossible. The indicator converts each to a z-score: how many standard deviations the current value is from its 252-day (1 year) average.
A z-score of +1 means "unusually high relative to recent history." A z-score of -1 means "unusually low." This puts all inputs on the same scale.
Step 3: Composite Calculation
The macro score combines the normalized inputs:
Macro Score = (TLT z-score + JNK z-score) - (DXY z-score + VIX z-score)
The result is clamped between -1.5 and +1.5 to prevent outliers from dominating, then smoothed with an EMA to reduce noise.
Step 4: Signal Generation
Seven different methods are available for determining when conditions shift:
1. EMA Cross: Classic crossover between smoothed macro and its signal line
2. Slope: Simple direction of the macro trend
3. Momentum: Rate of change exceeding a threshold
4. Session Delta: Comparing today's reading to yesterday's
5. Pivot: Market structure analysis (higher lows vs lower highs)
6. Acceleration: Second derivative (is momentum increasing?)
7. Multi-Confirm: Requires 4 or more methods to agree
Why These Specific Markets?
Bonds (TLT)
Treasury bonds often lead equities at turning points. When institutions rotate into bonds, it signals caution. When they rotate out, it signals risk appetite returning.
Credit (JNK)
High-yield bonds price credit risk faster than equities. Widening credit spreads (falling JNK) often precede equity weakness by days or weeks.
Dollar (DXY)
A strong dollar creates headwinds for multinational earnings, tightens global USD liquidity, and signals defensive positioning globally.
Volatility (VIX)
The options market prices fear before it manifests in price. Sustained elevated VIX readings indicate hedging demand and uncertainty.
Research Application: Weekly Put Selling
One application of this indicator is timing premium-selling strategies. I tested using the EMA Cross method to filter 7-day-to-expiration (7DTE) put sales on ES futures with 90% Profit Target and 600% Stop Loss, only selling puts when the indicator showed RISK-ON.
Results with Macro Filter (2020-2025):
- Trades: 200
- Win Rate: 96.0%
- Total P/L: +$33,636
- Max Drawdown: 2.91%
- Profit Factor: 3.51
Results without Filter (same period):
- Trades: 357
- Win Rate: 96.1%
- Total P/L: +$63,492
- Max Drawdown: 10.30%
- Profit Factor: 2.90
Key Insight:
The filtered approach made less total profit (fewer trades) but reduced maximum drawdown by 72% (from 10.30% to 2.91%). This significantly improves risk-adjusted returns and allows for potentially higher position sizing with confidence.
Note: These results are from external backtesting on actual options data, not the TradingView backtest engine. Past performance does not guarantee future results.
Features
Settings Guide
Macro Settings
Signal Method
Data Sources
How to Use
Basic Interpretation:
For Risk Management:
For Options Strategies:
Alert Setup:
Research Ideas
This indicator is designed as a research framework. Consider testing:
Limitations
Disclaimer
This indicator is for educational and research purposes only. It does not constitute financial advice.
Credits
Intermarket analysis concepts draw from established macro trading principles. The multi-signal approach is original work designed to give users flexibility in how they interpret the macro data.
This indicator builds a composite macro sentiment score by analyzing intermarket relationships between bonds, credit spreads, the US dollar, and volatility. The core premise is that these markets often signal shifts in risk appetite before equities react, providing a timing edge for managing exposure.
When macro conditions favor risk assets, the indicator signals RISK-ON (green). When conditions deteriorate, it signals RISK-OFF (red). This is not a predictive tool but rather a systematic way to assess the current macro environment.
The Problem It Solves
Markets do not move in isolation. Before major equity drawdowns, stress often appears first in credit markets, bonds, and volatility. By monitoring these leading indicators systematically, we can identify periods when holding equity exposure carries elevated risk.
The goal is not to catch every move but to avoid the worst drawdowns by stepping aside when multiple macro factors align negatively.
How It Works
Step 1: Data Collection
The indicator pulls daily data from four key markets:
Risk-On Inputs (positive for equities when rising):
- TLT (20+ Year Treasury Bonds): Rising bonds can signal improving liquidity or flight-to-safety ending
- JNK (High-Yield Corporate Bonds): Rising junk bonds indicate credit conditions improving and risk appetite increasing
Risk-Off Inputs (negative for equities when rising):
- DXY (US Dollar Index): Strong dollar tightens global financial conditions and signals risk-off flows
- VIX (Volatility Index): Elevated VIX indicates fear and hedging demand
Step 2: Z-Score Normalization
Each input trades at different absolute levels, so direct comparison is impossible. The indicator converts each to a z-score: how many standard deviations the current value is from its 252-day (1 year) average.
A z-score of +1 means "unusually high relative to recent history." A z-score of -1 means "unusually low." This puts all inputs on the same scale.
Step 3: Composite Calculation
The macro score combines the normalized inputs:
Macro Score = (TLT z-score + JNK z-score) - (DXY z-score + VIX z-score)
The result is clamped between -1.5 and +1.5 to prevent outliers from dominating, then smoothed with an EMA to reduce noise.
Step 4: Signal Generation
Seven different methods are available for determining when conditions shift:
1. EMA Cross: Classic crossover between smoothed macro and its signal line
2. Slope: Simple direction of the macro trend
3. Momentum: Rate of change exceeding a threshold
4. Session Delta: Comparing today's reading to yesterday's
5. Pivot: Market structure analysis (higher lows vs lower highs)
6. Acceleration: Second derivative (is momentum increasing?)
7. Multi-Confirm: Requires 4 or more methods to agree
Why These Specific Markets?
Bonds (TLT)
Treasury bonds often lead equities at turning points. When institutions rotate into bonds, it signals caution. When they rotate out, it signals risk appetite returning.
Credit (JNK)
High-yield bonds price credit risk faster than equities. Widening credit spreads (falling JNK) often precede equity weakness by days or weeks.
Dollar (DXY)
A strong dollar creates headwinds for multinational earnings, tightens global USD liquidity, and signals defensive positioning globally.
Volatility (VIX)
The options market prices fear before it manifests in price. Sustained elevated VIX readings indicate hedging demand and uncertainty.
Research Application: Weekly Put Selling
One application of this indicator is timing premium-selling strategies. I tested using the EMA Cross method to filter 7-day-to-expiration (7DTE) put sales on ES futures with 90% Profit Target and 600% Stop Loss, only selling puts when the indicator showed RISK-ON.
Results with Macro Filter (2020-2025):
- Trades: 200
- Win Rate: 96.0%
- Total P/L: +$33,636
- Max Drawdown: 2.91%
- Profit Factor: 3.51
Results without Filter (same period):
- Trades: 357
- Win Rate: 96.1%
- Total P/L: +$63,492
- Max Drawdown: 10.30%
- Profit Factor: 2.90
Key Insight:
The filtered approach made less total profit (fewer trades) but reduced maximum drawdown by 72% (from 10.30% to 2.91%). This significantly improves risk-adjusted returns and allows for potentially higher position sizing with confidence.
Note: These results are from external backtesting on actual options data, not the TradingView backtest engine. Past performance does not guarantee future results.
Features
- Seven configurable signal methods for different trading styles
- Adjustable weights for each data source
- Z-score normalization puts all inputs on equal footing
- Visual info table showing all metrics at a glance
- Background coloring for quick regime identification
- Alert conditions for signal changes
- Secondary plot showing method-specific metrics
Settings Guide
Macro Settings
- Z-Score Lookback (default 252): Period for calculating standard deviations. 252 equals approximately one trading year. Longer periods are more stable but slower to adapt.
- Macro EMA (default 7): Smoothing for the raw composite score. Lower values give faster but noisier signals.
- Signal EMA (default 8): Secondary smoothing for the signal line. Used primarily in EMA Cross method.
Signal Method
- EMA Cross: Recommended starting point. Signals when smoothed macro crosses its signal line.
- Slope: Simpler approach based purely on trend direction.
- Momentum: Requires rate of change to exceed a threshold.
- Session Delta: Compares today to yesterday (daily timeframe focus).
- Pivot: Uses market structure (higher lows for bullish, lower highs for bearish).
- Acceleration: Measures change in slope (second derivative).
- Multi-Confirm: Conservative approach requiring 4+ methods to agree.
Data Sources
- Each source can be enabled/disabled and weighted from 0 to 3
- Default is equal weighting (1.0) for all four sources
- Experiment with emphasizing sources most relevant to your trading (tested on SPX)
How to Use
Basic Interpretation:
- Green background / RISK-ON: Macro conditions favor equity exposure
- Red background / RISK-OFF: Macro conditions suggest caution
- Arrow markers indicate regime changes
For Risk Management:
- Use RISK-OFF signals to reduce position size or hedge
- Use RISK-ON signals to resume normal exposure
- Consider the indicator as one input among many, not a complete system
For Options Strategies:
- Avoid selling premium during RISK-OFF periods
- Resume premium selling when RISK-ON returns
- This approach trades frequency for reduced tail risk
Alert Setup:
- Set alerts on "Bullish Turn" and "Bearish Turn" conditions
- Receive notifications when the macro regime changes
Research Ideas
This indicator is designed as a research framework. Consider testing:
- Different signal methods for your specific strategy
- Adding or removing data sources based on what you trade
- Varying the z-score lookback for different market regimes
- Combining with price-based filters (moving averages, support/resistance)
- Using the multi-confirm method for higher-conviction signals only
Limitations
- The indicator uses daily data, so intraday signals may lag
- Overnight gaps from surprise news cannot be anticipated
- False signals will occur, especially in choppy, range-bound markets
- The z-score lookback creates a recency bias; what was "normal" a year ago may not be relevant today
- Not all drawdowns are preceded by macro deterioration; some come from idiosyncratic events
- Past intermarket relationships may not persist in the future
Disclaimer
This indicator is for educational and research purposes only. It does not constitute financial advice.
- Past performance does not guarantee future results
- The research results shared are from historical backtesting and may not reflect actual trading conditions
- Always conduct your own research and due diligence
- Consider your personal risk tolerance before making any trading decisions
- Never risk more than you can afford to lose
Credits
Intermarket analysis concepts draw from established macro trading principles. The multi-signal approach is original work designed to give users flexibility in how they interpret the macro data.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.
Skrypt open-source
W zgodzie z duchem TradingView twórca tego skryptu udostępnił go jako open-source, aby użytkownicy mogli przejrzeć i zweryfikować jego działanie. Ukłony dla autora. Korzystanie jest bezpłatne, jednak ponowna publikacja kodu podlega naszym Zasadom serwisu.
Wyłączenie odpowiedzialności
Informacje i publikacje nie stanowią i nie powinny być traktowane jako porady finansowe, inwestycyjne, tradingowe ani jakiekolwiek inne rekomendacje dostarczane lub zatwierdzone przez TradingView. Więcej informacji znajduje się w Warunkach użytkowania.