OPEN-SOURCE SCRIPT
Risk Dispersion Regime Indicator

Its primary objective is to measure the real-time correlation level (the lockstep movement) of a basket of assets to generate a dynamic multiplier. This multiplier adjusts your position sizing based on the current market risk regime.
⚙️ Configuration and Inputs
Customizable Basket: The script analyzes a basket of 3 to 20 assets (the slots). By default, it is preconfigured with major US sector and index ETFs (SPY, QQQ, XLK, etc.).
Analysis Windows: The user defines the lookback period for the correlation calculation (default 120 sessions) and the historical depth to establish the ranking (default 750 sessions).
Position Sizing Governor: Allows you to configure the amplitude of the position adjustments via a minimum multiplier (0.3x), a maximum multiplier (1.7x), and a global strength modifier.
🧮 Mathematical Mechanics and Logic
Standardization (Z-Score): The indicator converts the return of each asset in the basket into a Z-score (return standardized relative to its mean and standard deviation) to put all symbols on the exact same scale.
Group Correlation (Rho): Instead of calculating asset pairs one by one (which is computationally heavy), the code uses an optimized mathematical identity: it derives the average correlation of the basket directly from the variance of the assets' average.
Walk-Forward Ranking: The script calculates the percentile of the current correlation strictly against previously observed historical values. This method guarantees zero lookahead bias, making the indicator perfectly safe and robust for algorithmic backtesting.
🖥️ Visual Outputs and Interface
Main Plots: The indicator draws three lines on a separate lower pane: the correlation rank (percentile), the raw correlation, and the resulting position size multiplier.
Color-Coded Regimes: The chart background changes color dynamically. It turns red when the market moves as a monolith (rank > 0.90, signaling high systemic risk) and green when the market is highly dispersed (rank < 0.25, a favorable environment for stock-picking).
Diagnostic Dashboard: A table is displayed in the top right corner. It indicates the real-time market state (Very Tight, Loose, etc.), the recommended multiplier, and includes built-in safeguards (e.g., warning the user if the timeframe is not daily or if specific assets lack historical quote data).
Built-in Alerts: Alert conditions (alertcondition) are programmed to notify the user whenever the market crosses extreme correlation thresholds (90th and 25th percentiles).
⚙️ Configuration and Inputs
Customizable Basket: The script analyzes a basket of 3 to 20 assets (the slots). By default, it is preconfigured with major US sector and index ETFs (SPY, QQQ, XLK, etc.).
Analysis Windows: The user defines the lookback period for the correlation calculation (default 120 sessions) and the historical depth to establish the ranking (default 750 sessions).
Position Sizing Governor: Allows you to configure the amplitude of the position adjustments via a minimum multiplier (0.3x), a maximum multiplier (1.7x), and a global strength modifier.
🧮 Mathematical Mechanics and Logic
Standardization (Z-Score): The indicator converts the return of each asset in the basket into a Z-score (return standardized relative to its mean and standard deviation) to put all symbols on the exact same scale.
Group Correlation (Rho): Instead of calculating asset pairs one by one (which is computationally heavy), the code uses an optimized mathematical identity: it derives the average correlation of the basket directly from the variance of the assets' average.
Walk-Forward Ranking: The script calculates the percentile of the current correlation strictly against previously observed historical values. This method guarantees zero lookahead bias, making the indicator perfectly safe and robust for algorithmic backtesting.
🖥️ Visual Outputs and Interface
Main Plots: The indicator draws three lines on a separate lower pane: the correlation rank (percentile), the raw correlation, and the resulting position size multiplier.
Color-Coded Regimes: The chart background changes color dynamically. It turns red when the market moves as a monolith (rank > 0.90, signaling high systemic risk) and green when the market is highly dispersed (rank < 0.25, a favorable environment for stock-picking).
Diagnostic Dashboard: A table is displayed in the top right corner. It indicates the real-time market state (Very Tight, Loose, etc.), the recommended multiplier, and includes built-in safeguards (e.g., warning the user if the timeframe is not daily or if specific assets lack historical quote data).
Built-in Alerts: Alert conditions (alertcondition) are programmed to notify the user whenever the market crosses extreme correlation thresholds (90th and 25th percentiles).
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.