OPEN-SOURCE SCRIPT
FX Risk Regime (Risk-On - Risk-Off) - Composite

Overview
FX Risk Regime - Composite is a macro-driven regime detection indicator designed to classify market conditions into:
The model aggregates cross-asset information from equities, volatility, USD strength, and carry flows to generate a standardised composite risk score. It is particularly useful for FX traders who trade risk-sensitive and defensive currency pairs.
This indicator does not directly predict price direction. Instead, it identifies the prevailing macro regime so traders can align directional bias and risk management accordingly.
Conceptual Framework
Financial markets tend to rotate between two dominant macro states:
Risk-On
Capital flows into higher-beta currencies and growth-linked assets.
Risk-Off
Capital rotates into defensive currencies and safe-haven assets.
This indicator quantifies these dynamics and standardises them using Z-scores to create a normalised composite regime signal.
Indicator Architecture
The model is constructed using four cross-asset components:
1. Equity Momentum (SPX)
Symbol:
SPX
Measures risk appetite via equity momentum
Positive equity momentum = Risk-On bias
2. Volatility Index (VIX)
Symbol:
VIX
Standardised and inverted
Rising volatility = Risk-Off
Falling volatility = Risk-On
3. USD Index (DXY)
Symbol:
DXY
USD strength is associated with defensive flows
Rising DXY = Risk-Off
4. Carry Proxy (AUDJPY)
Symbol:
AUDJPY
High-beta FX pair representing global carry flows
Rising AUDJPY = Risk-On
Mathematical Construction
Each component is transformed using:
Composite Score:
Pine Script®
The result is smoothed and compared to a configurable regime threshold.
Regime Classification
Green Background
Risk-On Regime (score > +threshold)
Red Background
Risk-Off Regime (score < −threshold)
Neutral Zone
Between thresholds — transitional conditions.
What Does the 0.8 Threshold Mean?
The default threshold (0.8) represents approximately:
0.8 standard deviations above or below the composite mean.
It filters out noise and avoids reacting to minor fluctuations.
Lower threshold - more signals, more sensitivity
Higher threshold - fewer signals, stronger conviction
For swing trading, values between 0.8 and 1.2 are typically appropriate.
How to Use This Indicator
1. Regime Filter for FX Trading
Use as a directional bias filter.
In Risk-On:
Favor:
Avoid:
In Risk-Off:
Favor:
Avoid:
2. Position Sizing Tool
Increase size in aligned regime
Reduce exposure during neutral regime
3. Strategy Overlay
Combine with:
This indicator improves expectancy by preventing trades against macro flow.
Best Timeframes
Recommended:
1H
4H
Daily
Lower timeframes may be noisy because macro variables update at slower frequencies.
Asset Classes Where It Works Best
FX Pairs:
- JPY crosses
- Commodity currencies
- High beta crosses
Indices:
- DAX
- Nasdaq
- S&P500
Commodities:
- Oil
- Copper
Crypto:
- BTCUSD (during macro-correlated phases)
Strengths
Limitations
Suggested Improvements (Advanced Users)
For advanced research:
Customization
All major parameters are configurable:
This allows adaptation for:
FX Risk Regime - Composite is a macro-driven regime detection indicator designed to classify market conditions into:
- Risk-On
- Risk-Off
- Neutral / Transitional
The model aggregates cross-asset information from equities, volatility, USD strength, and carry flows to generate a standardised composite risk score. It is particularly useful for FX traders who trade risk-sensitive and defensive currency pairs.
This indicator does not directly predict price direction. Instead, it identifies the prevailing macro regime so traders can align directional bias and risk management accordingly.
Conceptual Framework
Financial markets tend to rotate between two dominant macro states:
Risk-On
- Equities rising
- Volatility falling
- USD softening
- Carry trades performing
Capital flows into higher-beta currencies and growth-linked assets.
Risk-Off
- Equities declining
- Volatility rising
- USD strengthening
- Carry trades unwinding
Capital rotates into defensive currencies and safe-haven assets.
This indicator quantifies these dynamics and standardises them using Z-scores to create a normalised composite regime signal.
Indicator Architecture
The model is constructed using four cross-asset components:
1. Equity Momentum (SPX)
Symbol:
Measures risk appetite via equity momentum
Positive equity momentum = Risk-On bias
2. Volatility Index (VIX)
Symbol:
Standardised and inverted
Rising volatility = Risk-Off
Falling volatility = Risk-On
3. USD Index (DXY)
Symbol:
USD strength is associated with defensive flows
Rising DXY = Risk-Off
4. Carry Proxy (AUDJPY)
Symbol:
High-beta FX pair representing global carry flows
Rising AUDJPY = Risk-On
Mathematical Construction
Each component is transformed using:
- Log momentum
- Rolling Z-Score normalisation
- Optional EMA smoothing
Composite Score:
RawScore = Z(SPX Momentum)
+ Z(−VIX)
+ Z(−DXY Momentum)
+ Z(AUDJPY Momentum)
The result is smoothed and compared to a configurable regime threshold.
Regime Classification
Green Background
Risk-On Regime (score > +threshold)
Red Background
Risk-Off Regime (score < −threshold)
Neutral Zone
Between thresholds — transitional conditions.
What Does the 0.8 Threshold Mean?
The default threshold (0.8) represents approximately:
0.8 standard deviations above or below the composite mean.
It filters out noise and avoids reacting to minor fluctuations.
Lower threshold - more signals, more sensitivity
Higher threshold - fewer signals, stronger conviction
For swing trading, values between 0.8 and 1.2 are typically appropriate.
How to Use This Indicator
1. Regime Filter for FX Trading
Use as a directional bias filter.
In Risk-On:
Favor:
- AUDJPY
- NZDJPY
- CADJPY
- EURAUD
- GBPJPY
Avoid:
- USDJPY shorts
- CHF strength trades
In Risk-Off:
Favor:
- USDJPY longs
- CHFJPY shorts
- EURJPY shorts
- AUDUSD shorts
Avoid:
- Carry longs
2. Position Sizing Tool
Increase size in aligned regime
Reduce exposure during neutral regime
3. Strategy Overlay
Combine with:
- Trend systems (EMA / MACD)
- Momentum systems
- Breakout systems
- Carry strategies
This indicator improves expectancy by preventing trades against macro flow.
Best Timeframes
Recommended:
1H
4H
Daily
Lower timeframes may be noisy because macro variables update at slower frequencies.
Asset Classes Where It Works Best
FX Pairs:
- JPY crosses
- Commodity currencies
- High beta crosses
Indices:
- DAX
- Nasdaq
- S&P500
Commodities:
- Oil
- Copper
Crypto:
- BTCUSD (during macro-correlated phases)
Strengths
- Cross-asset driven
- Macro consistent
- Quantitative standardization
- Regime persistence model (state memory)
- Adaptable threshold
- Fully transparent logic
Limitations
- Not a predictive model
- Reacts with slight lag
- May misclassify during structural regime shifts
- Dependent on external symbol data availability
- Regime changes can be violent. Use risk management.
Suggested Improvements (Advanced Users)
For advanced research:
- Weight components by historical Information Ratio
- Use dynamic thresholds based on rolling volatility
- Add bond yield spreads (US10Y vs JGB)
- Add credit spreads (CDX)
- Add copper/gold ratio
Customization
All major parameters are configurable:
- Z-Score Lookback
- Momentum Lookback
- Threshold
- Smoothing
- Symbols
This allows adaptation for:
- Short-term trading
- Swing trading
- Macro overlay models
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
この情報および投稿は、TradingViewが提供または推奨する金融、投資、トレード、その他のアドバイスや推奨を意図するものではなく、それらを構成するものでもありません。詳細は利用規約をご覧ください。
オープンソーススクリプト
TradingViewの精神に則り、このスクリプトの作者はコードをオープンソースとして公開してくれました。トレーダーが内容を確認・検証できるようにという配慮です。作者に拍手を送りましょう!無料で利用できますが、コードの再公開はハウスルールに従う必要があります。
免責事項
この情報および投稿は、TradingViewが提供または推奨する金融、投資、トレード、その他のアドバイスや推奨を意図するものではなく、それらを構成するものでもありません。詳細は利用規約をご覧ください。