OPEN-SOURCE SCRIPT
Macro Market Health Index

This comprehensive indicator, Macro Market Health and Dynamic Regime Scoring, is a multi-asset "Risk-ON / Risk-OFF" framework designed to quantify market health by analyzing six specialized macro pillars. Unlike static indicators, this tool features an adaptive weighting engine that calibrates the importance of each macro block based on its real-time relationship with the specific asset currently on your chart
.
The Six Pillars of Market Health
The indicator processes raw data through six "Blocks," each utilizing specific mathematical models to score health from 0 to 1
:
Risk Block (Sentiment): Monitors the VIX (normalized against a baseline of 22), Gold, and the USD/JPY "Carry Trade"
. It calculates a blend of absolute levels (distance from the 200-day EMA) and momentum (9-day ROC of the 21-day EMA) to detect capital flight into safe havens
.
Breadth Block (Internal Strength): Uses the S5FI (S&P 500 stocks above their 50-day EMA) and the SPX/RSP Spread
. If the standard S&P 500 is significantly outperforming the equal-weighted version, it signals poor "under the hood" participation
.
Equity Block (Momentum & Volume): Analyzes the S&P 500 using a Gaussian "Sweet Spot" model
. It scores the trend highest when the price is in a healthy range above the 200-day EMA, while also penalizing the score if relative volume trends (21-day vs 251-day EMA) show exhaustion
.
Crypto Block (Risk Appetite): Serves as a high-beta proxy by measuring Bitcoin's distance from its 50, 100, and 200-day EMAs
. These are weighted (45% for 50-day, 32% for 100-day, 23% for 200-day) to capture multi-timeframe risk sentiment
.
Growth Block (Economic Context): Tracks Crude Oil and its 50-day correlation to equities
. It identifies whether energy prices are acting as a growth driver or a risk-off inflationary headwind
.
Credit Block (Fixed Income): Monitors the HYG (High Yield Corporate Bonds) as a leading indicator of credit stress
. It evaluates both the trend level and the rate of change in corporate bond demand
.
Advanced Mathematical Components
To ensure all data is comparable, the script employs several core math engines:
Sigmoid Normalization: Squashes all outputs into a standard 0 to 1 range for easy comparison
.
Z-Score Sigmoids: Normalizes volatility and momentum by measuring how many standard deviations a value is from its mean
.
Gaussian Probability: Uses a bell-curve distribution to score the "Equity Block," rewarding trends that stay within a specific volatility-adjusted distance from the mean
.
Distance/ATR Scaling: All price distances from moving averages are divided by the ATR (Average True Range) to ensure the scores are relative to current market volatility
.
Data-Driven Weighting: Tailored to YOUR Asset
The standout feature is the Weight Engine, which rejects the "one-size-fits-all" approach. It calculates weights against the specific ticker (hlc3) on your chart
:
Asset Correlation: The indicator measures the real-time statistical correlation between each macro block and the specific stock you are trading
. If your stock starts moving in lockstep with Credit or Crypto, those blocks are automatically given more weight
.
Dynamic Volatility Scaling: It calculates the ratio of a block's volatility (CV) to your stock's volatility (CV) to dynamically adjust the lookback period (between 50 and 300 bars)
Adaptive Lookback Engine: The index uses the Coefficient of Variation (CV) (StandardDeviation/Mean) to compare macro environment volatility against your stock's volatility
. This ratio automatically scales the lookback window between 50 bars (for high-volatility responsiveness) and 300 bars (for stable trend smoothing)
.
Weighting & Analytics: Final weights blend asset-specific correlation with Inverse Volatility (1/SD) to prioritize correlated, stable, low-noise signals
.
Signals and Predictive Analytics
Trade Status Overlay: Provides a definitive "TRADE" (Score > 0.58) or "NO TRADE" (Score < 0.45) signal
.
Regime Classification: Categorizes the market into BULL MARKET, EARLY BULL, NEUTRAL, or RISK OFF
.
Swing Probability: Uses a Gaussian Survival Model to estimate the conditional probability that a "Risk-ON" or "Risk-Off" (current identified) regime will last for a user-defined "Swing Duration" (e.g., the next 21 bars)
.
Reliability Index: Based on the number of historical samples collected for that specific asset, it labels the probability data as Adequate, Marginal, or Low
.
.
The Six Pillars of Market Health
The indicator processes raw data through six "Blocks," each utilizing specific mathematical models to score health from 0 to 1
:
Risk Block (Sentiment): Monitors the VIX (normalized against a baseline of 22), Gold, and the USD/JPY "Carry Trade"
. It calculates a blend of absolute levels (distance from the 200-day EMA) and momentum (9-day ROC of the 21-day EMA) to detect capital flight into safe havens
.
Breadth Block (Internal Strength): Uses the S5FI (S&P 500 stocks above their 50-day EMA) and the SPX/RSP Spread
. If the standard S&P 500 is significantly outperforming the equal-weighted version, it signals poor "under the hood" participation
.
Equity Block (Momentum & Volume): Analyzes the S&P 500 using a Gaussian "Sweet Spot" model
. It scores the trend highest when the price is in a healthy range above the 200-day EMA, while also penalizing the score if relative volume trends (21-day vs 251-day EMA) show exhaustion
.
Crypto Block (Risk Appetite): Serves as a high-beta proxy by measuring Bitcoin's distance from its 50, 100, and 200-day EMAs
. These are weighted (45% for 50-day, 32% for 100-day, 23% for 200-day) to capture multi-timeframe risk sentiment
.
Growth Block (Economic Context): Tracks Crude Oil and its 50-day correlation to equities
. It identifies whether energy prices are acting as a growth driver or a risk-off inflationary headwind
.
Credit Block (Fixed Income): Monitors the HYG (High Yield Corporate Bonds) as a leading indicator of credit stress
. It evaluates both the trend level and the rate of change in corporate bond demand
.
Advanced Mathematical Components
To ensure all data is comparable, the script employs several core math engines:
Sigmoid Normalization: Squashes all outputs into a standard 0 to 1 range for easy comparison
.
Z-Score Sigmoids: Normalizes volatility and momentum by measuring how many standard deviations a value is from its mean
.
Gaussian Probability: Uses a bell-curve distribution to score the "Equity Block," rewarding trends that stay within a specific volatility-adjusted distance from the mean
.
Distance/ATR Scaling: All price distances from moving averages are divided by the ATR (Average True Range) to ensure the scores are relative to current market volatility
.
Data-Driven Weighting: Tailored to YOUR Asset
The standout feature is the Weight Engine, which rejects the "one-size-fits-all" approach. It calculates weights against the specific ticker (hlc3) on your chart
:
Asset Correlation: The indicator measures the real-time statistical correlation between each macro block and the specific stock you are trading
. If your stock starts moving in lockstep with Credit or Crypto, those blocks are automatically given more weight
.
Dynamic Volatility Scaling: It calculates the ratio of a block's volatility (CV) to your stock's volatility (CV) to dynamically adjust the lookback period (between 50 and 300 bars)
Adaptive Lookback Engine: The index uses the Coefficient of Variation (CV) (StandardDeviation/Mean) to compare macro environment volatility against your stock's volatility
. This ratio automatically scales the lookback window between 50 bars (for high-volatility responsiveness) and 300 bars (for stable trend smoothing)
.
Weighting & Analytics: Final weights blend asset-specific correlation with Inverse Volatility (1/SD) to prioritize correlated, stable, low-noise signals
.
Signals and Predictive Analytics
Trade Status Overlay: Provides a definitive "TRADE" (Score > 0.58) or "NO TRADE" (Score < 0.45) signal
.
Regime Classification: Categorizes the market into BULL MARKET, EARLY BULL, NEUTRAL, or RISK OFF
.
Swing Probability: Uses a Gaussian Survival Model to estimate the conditional probability that a "Risk-ON" or "Risk-Off" (current identified) regime will last for a user-defined "Swing Duration" (e.g., the next 21 bars)
.
Reliability Index: Based on the number of historical samples collected for that specific asset, it labels the probability data as Adequate, Marginal, or Low
.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
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.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Disclaimer
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.