OPEN-SOURCE SCRIPT
Sector Rotation - Risk Preference Indicator

# Sector Rotation - Risk Preference Indicator
## Overview
This indicator measures market risk appetite by comparing the relative strength between **Aggressive** and **Defensive** sectors. It provides a clean, single-line visualization to help traders identify market sentiment shifts and potential trend reversals.
## How It Works
The indicator calculates a **Bullish/Bearish Ratio** by dividing the average price of aggressive sector ETFs by defensive sector ETFs, then normalizing to a baseline of 100.
**Formula:**
- Ratio = (Aggressive Sectors Average / Defensive Sectors Average) × 100
**Interpretation:**
- **Ratio > 100**: Risk-on sentiment (Aggressive sectors outperforming Defensive)
- **Ratio < 100**: Risk-off sentiment (Defensive sectors outperforming Aggressive)
- **Ratio ≈ 100**: Neutral (Both sector groups performing equally)
## Default Sectors
**Defensive Sectors** (Safe havens during uncertainty):
- XLP - Consumer Staples Select Sector SPDR Fund
- XLU - Utilities Select Sector SPDR Fund
- XLV - Health Care Select Sector SPDR Fund
**Aggressive Sectors** (Growth-oriented, higher risk):
- XLK - Technology Select Sector SPDR Fund
- XBI - SPDR S&P Biotech ETF
- XRT - SPDR S&P Retail ETF
## Features
✅ **Fully Customizable Sectors** - Choose any ETFs/tickers for each sector group
✅ **Smoothing Control** - Adjustable SMA period to reduce noise (default: 2)
✅ **Clean Visualization** - Single blue line for easy interpretation
✅ **Multi-timeframe Support** - Works on any timeframe
✅ **Lightweight** - Minimal calculations for fast performance
## Settings
### Defensive Sectors Group
- **Defensive Sector 1**: First defensive ETF ticker (default: XLP)
- **Defensive Sector 2**: Second defensive ETF ticker (default: XLU)
- **Defensive Sector 3**: Third defensive ETF ticker (default: XLV)
### Aggressive Sectors Group
- **Aggressive Sector 1**: First aggressive ETF ticker (default: XLK)
- **Aggressive Sector 2**: Second aggressive ETF ticker (default: XBI)
- **Aggressive Sector 3**: Third aggressive ETF ticker (default: XRT)
### Display Settings
- **Smoothing Length**: SMA period for ratio smoothing (default: 2, range: 1-50)
- Lower values = More responsive but noisier
- Higher values = Smoother but more lagging
## Use Cases
### 1. Market Regime Identification
- **Rising Ratio (trending up)** → Bull market / Risk-on environment
- Aggressive sectors leading, investors chasing growth
- Favorable for long positions in tech, growth stocks
- **Falling Ratio (trending down)** → Bear market / Risk-off environment
- Defensive sectors leading, investors seeking safety
- Consider defensive positioning or short opportunities
### 2. Divergence Analysis
- **Bullish Divergence**: Price makes new lows but ratio rises
- Suggests underlying strength returning
- Potential market bottom forming
- **Bearish Divergence**: Price makes new highs but ratio falls
- Suggests weakening momentum
- Potential market top forming
### 3. Trend Confirmation
- **Strong uptrend + Rising ratio** → Confirmed bullish trend
- **Strong downtrend + Falling ratio** → Confirmed bearish trend
- **Uptrend + Falling ratio** → Weakening trend, watch for reversal
- **Downtrend + Rising ratio** → Potential trend exhaustion
## Best Practices
⚠️ **Timeframe Selection**
- Recommended: Daily, 4H, 1H for cleaner signals
- Lower timeframes (15m, 5m) may produce noisy signals
⚠️ **Complementary Analysis**
- Use alongside price action and volume analysis
- Combine with support/resistance levels
- Not designed as a standalone trading system
⚠️ **Market Conditions**
- Most effective in trending markets
- Less reliable during ranging/consolidation periods
- Works best in liquid, well-traded sectors
⚠️ **Customization Tips**
- Can substitute with international sectors (EWU, EWZ, etc.)
- Can use crypto sectors (DeFi vs Layer1, etc.)
- Adjust smoothing based on trading style (day trading = 2-5, swing = 10-20)
## Display Options
### Default View (overlay=false)
- Shows in separate pane below chart
- Dedicated scale for ratio values
### Alternative View
- Can be moved to main chart pane (drag indicator)
I typically overlay this indicator on the SPY daily chart to observe divergences. I don’t focus on specific values but rather on the direction of the trend.
The author is not responsible for any trading losses incurred using this indicator.
## Support & Feedback
For questions, feature requests, or bug reports:
- Comment below
- Send a private message
- Check for updates regularly
If you find this indicator useful, please:
- ⭐ Leave a like/favorite
- 💬 Share your experience in comments
- 📊 Share charts showing interesting patterns
## Overview
This indicator measures market risk appetite by comparing the relative strength between **Aggressive** and **Defensive** sectors. It provides a clean, single-line visualization to help traders identify market sentiment shifts and potential trend reversals.
## How It Works
The indicator calculates a **Bullish/Bearish Ratio** by dividing the average price of aggressive sector ETFs by defensive sector ETFs, then normalizing to a baseline of 100.
**Formula:**
- Ratio = (Aggressive Sectors Average / Defensive Sectors Average) × 100
**Interpretation:**
- **Ratio > 100**: Risk-on sentiment (Aggressive sectors outperforming Defensive)
- **Ratio < 100**: Risk-off sentiment (Defensive sectors outperforming Aggressive)
- **Ratio ≈ 100**: Neutral (Both sector groups performing equally)
## Default Sectors
**Defensive Sectors** (Safe havens during uncertainty):
- XLP - Consumer Staples Select Sector SPDR Fund
- XLU - Utilities Select Sector SPDR Fund
- XLV - Health Care Select Sector SPDR Fund
**Aggressive Sectors** (Growth-oriented, higher risk):
- XLK - Technology Select Sector SPDR Fund
- XBI - SPDR S&P Biotech ETF
- XRT - SPDR S&P Retail ETF
## Features
✅ **Fully Customizable Sectors** - Choose any ETFs/tickers for each sector group
✅ **Smoothing Control** - Adjustable SMA period to reduce noise (default: 2)
✅ **Clean Visualization** - Single blue line for easy interpretation
✅ **Multi-timeframe Support** - Works on any timeframe
✅ **Lightweight** - Minimal calculations for fast performance
## Settings
### Defensive Sectors Group
- **Defensive Sector 1**: First defensive ETF ticker (default: XLP)
- **Defensive Sector 2**: Second defensive ETF ticker (default: XLU)
- **Defensive Sector 3**: Third defensive ETF ticker (default: XLV)
### Aggressive Sectors Group
- **Aggressive Sector 1**: First aggressive ETF ticker (default: XLK)
- **Aggressive Sector 2**: Second aggressive ETF ticker (default: XBI)
- **Aggressive Sector 3**: Third aggressive ETF ticker (default: XRT)
### Display Settings
- **Smoothing Length**: SMA period for ratio smoothing (default: 2, range: 1-50)
- Lower values = More responsive but noisier
- Higher values = Smoother but more lagging
## Use Cases
### 1. Market Regime Identification
- **Rising Ratio (trending up)** → Bull market / Risk-on environment
- Aggressive sectors leading, investors chasing growth
- Favorable for long positions in tech, growth stocks
- **Falling Ratio (trending down)** → Bear market / Risk-off environment
- Defensive sectors leading, investors seeking safety
- Consider defensive positioning or short opportunities
### 2. Divergence Analysis
- **Bullish Divergence**: Price makes new lows but ratio rises
- Suggests underlying strength returning
- Potential market bottom forming
- **Bearish Divergence**: Price makes new highs but ratio falls
- Suggests weakening momentum
- Potential market top forming
### 3. Trend Confirmation
- **Strong uptrend + Rising ratio** → Confirmed bullish trend
- **Strong downtrend + Falling ratio** → Confirmed bearish trend
- **Uptrend + Falling ratio** → Weakening trend, watch for reversal
- **Downtrend + Rising ratio** → Potential trend exhaustion
## Best Practices
⚠️ **Timeframe Selection**
- Recommended: Daily, 4H, 1H for cleaner signals
- Lower timeframes (15m, 5m) may produce noisy signals
⚠️ **Complementary Analysis**
- Use alongside price action and volume analysis
- Combine with support/resistance levels
- Not designed as a standalone trading system
⚠️ **Market Conditions**
- Most effective in trending markets
- Less reliable during ranging/consolidation periods
- Works best in liquid, well-traded sectors
⚠️ **Customization Tips**
- Can substitute with international sectors (EWU, EWZ, etc.)
- Can use crypto sectors (DeFi vs Layer1, etc.)
- Adjust smoothing based on trading style (day trading = 2-5, swing = 10-20)
## Display Options
### Default View (overlay=false)
- Shows in separate pane below chart
- Dedicated scale for ratio values
### Alternative View
- Can be moved to main chart pane (drag indicator)
I typically overlay this indicator on the SPY daily chart to observe divergences. I don’t focus on specific values but rather on the direction of the trend.
The author is not responsible for any trading losses incurred using this indicator.
## Support & Feedback
For questions, feature requests, or bug reports:
- Comment below
- Send a private message
- Check for updates regularly
If you find this indicator useful, please:
- ⭐ Leave a like/favorite
- 💬 Share your experience in comments
- 📊 Share charts showing interesting patterns
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.
Script open-source
Dans l'esprit TradingView, le créateur de ce script l'a rendu open source afin que les traders puissent examiner et vérifier ses fonctionnalités. Bravo à l'auteur! Bien que vous puissiez l'utiliser gratuitement, n'oubliez pas que la republication du code est soumise à nos Règles.
Clause de non-responsabilité
Les informations et publications ne sont pas destinées à être, et ne constituent pas, des conseils ou recommandations financiers, d'investissement, de trading ou autres fournis ou approuvés par TradingView. Pour en savoir plus, consultez les Conditions d'utilisation.