OPEN-SOURCE SCRIPT
ontagion & Shock System (CSS) - Systemic Risk Tracker

The Contagion & Shock System (CSS) is an advanced quantitative indicator designed to measure systemic risk and sector contagion in real-time. Instead of looking at a single asset in isolation, this system tracks how sudden price shocks ripple across a configurable basket of proxy assets, helping traders identify true macro risk-on or risk-off environments.
1. Shock Detection
The system continuously monitors the base asset for sudden volatility spikes. It triggers an active "Shock" if a single bar exceeds a specific percentage threshold, or if a cumulative multi-bar move indicates sustained, aggressive buying or selling pressure.
2. Dynamic Correlation Engine (Wave Assignment)
The indicator runs a live Pearson Correlation (using log returns) between your base chart and 10 configurable proxy assets (e.g., SPY, QQQ, VIX, XLF). It automatically buckets these assets into three contagion waves:
Wave 1 (Immediate Impact): Correlation >= 0.70
Wave 2 (Lagging Impact): Correlation >= 0.40
Wave 3 (Distant/Isolated): Correlation < 0.40
3. Contagion Pressure Index (CPI)
Displayed as a central histogram, the CPI aggregates the correlation strength and directional movement of all 10 proxies. A positive score indicates risk-on contagion (assets are rising together), while a negative score indicates risk-off contagion (assets are falling together).
4. Systemic Risk Score (0-100)
Located in the dashboard, this gauge blends the magnitude of the CPI, the number of assets currently caught in Wave 1, and the recency of the last price shock. A score above 80 indicates severe market-wide stress.
Users can fully customize the shock thresholds, cumulative lookback windows, correlation lengths, and all 10 proxy tickers via the indicator settings to tailor the system to specific sectors or asset classes.
1. Shock Detection
The system continuously monitors the base asset for sudden volatility spikes. It triggers an active "Shock" if a single bar exceeds a specific percentage threshold, or if a cumulative multi-bar move indicates sustained, aggressive buying or selling pressure.
2. Dynamic Correlation Engine (Wave Assignment)
The indicator runs a live Pearson Correlation (using log returns) between your base chart and 10 configurable proxy assets (e.g., SPY, QQQ, VIX, XLF). It automatically buckets these assets into three contagion waves:
Wave 1 (Immediate Impact): Correlation >= 0.70
Wave 2 (Lagging Impact): Correlation >= 0.40
Wave 3 (Distant/Isolated): Correlation < 0.40
3. Contagion Pressure Index (CPI)
Displayed as a central histogram, the CPI aggregates the correlation strength and directional movement of all 10 proxies. A positive score indicates risk-on contagion (assets are rising together), while a negative score indicates risk-off contagion (assets are falling together).
4. Systemic Risk Score (0-100)
Located in the dashboard, this gauge blends the magnitude of the CPI, the number of assets currently caught in Wave 1, and the recency of the last price shock. A score above 80 indicates severe market-wide stress.
Users can fully customize the shock thresholds, cumulative lookback windows, correlation lengths, and all 10 proxy tickers via the indicator settings to tailor the system to specific sectors or asset classes.
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
これらの情報および投稿は、TradingViewが提供または承認する金融、投資、取引、またはその他の種類の助言もしくは推奨であることを意図したものではなく、またこれらに該当するものでもありません。詳細は利用規約をご覧ください。