OPEN-SOURCE SCRIPT
업데이트됨 Volatility Regime Clustering

# Volatility Regime Clustering (VRC) - Intelligent Volatility Classification
## The Problem
Most traders use the same position size regardless of market conditions. This leads to excessive risk during high volatility periods and missed profits during calm periods. Standard volatility indicators (ATR, Bollinger Bands) show current values but don't automatically classify market regimes.
## The Solution
**Volatility Regime Clustering** uses a machine learning algorithm (k-means clustering) to automatically identify volatility regimes based on historical data. The indicator independently finds boundaries between calm, normal, and nervous markets for each trading instrument.
## How It Works
### Technical Implementation
1. **Volatility Normalization**: ATR is converted to basis points for comparability across instruments with different prices.
2. **K-means Clustering**:
- The indicator analyzes the last N bars (default 200)
- Automatically groups historical ATR values into 2-4 clusters
- Cluster centroids are evenly distributed from minimum to maximum volatility
- The algorithm iteratively refines cluster boundaries every 5 bars
3. **False Signal Protection**:
- Threshold-based smoothing: regime changes only after 3+ consecutive confirmations
- Empty cluster protection with automatic reinitialization
- Warmup period to accumulate sufficient history
4. **Guaranteed Order**:
- Regime 0 always = low volatility
- Regime 1 always = medium volatility
- Regime 2 always = high volatility
- Regime 3 always = extreme volatility
## Visualization
- 🟢 **Green Background**: Low volatility - calm market, full position size recommended
- 🟡 **Yellow Background**: Medium volatility - standard conditions, 75-80% of normal risk recommended
- 🟠 **Orange Background**: High volatility - nervous market, reduce risk to 40-50%
- 🔴 **Red Background**: Extreme volatility - panic/news, minimum risk 25% or stay out
**Info Panel** (top right corner) displays:
- Current volatility regime
- ATR in basis points
- Current cluster center (regime mean value)
- Deviation from cluster center (how close to regime transition)
- Regime stability (% of time in current state)
- Recommended risk multiplier
- Recommended position size in %
## How to Use
### Basic Approach (Risk Management)
1. Add the indicator to any asset chart
2. Wait for warmup period completion (requires minimum 200 bars of history)
3. Monitor background color and recommendations table
4. Adjust position size according to risk multiplier
**Example**:
- You normally risk 2% of capital per trade
- Indicator shows "Risk Multiplier: 0.50x" (orange/red regime)
- Reduce risk to 1% (2% × 0.5 = 1%)
### Advanced Usage
**Entry Filtering**:
- Enter positions only in green/yellow regimes
- Avoid new positions during red background
**Open Position Management**:
- When transitioning to high volatility, move stop-losses further
- In calm regimes, use more aggressive take-profits
**Options Strategies**:
- High volatility → sell options (elevated premium)
- Low volatility → buy options before potential expansion
## Settings
### Main Parameters
- **ATR Length** (14): ATR calculation period. Lower = faster reaction, higher = smoother
- **Clustering Lookback** (200): number of bars for algorithm training. Recommended 150-300
- **Number of Regimes** (3): number of volatility regimes (2-4)
- 2 regimes: simple "calm/nervous"
- 3 regimes: "low/medium/high" (recommended)
- 4 regimes: adds "extreme" regime for rare events
- **Regime Smoothing** (3): number of confirmation bars for regime change. Higher = fewer false switches
### Visual Settings
- **Show Background Color**: enable/disable colored background
- **Show Regime Labels**: display labels on chart when regime changes
- **Show Risk Adjustment Info**: show/hide info panel
- **Info Panel Size**: panel font size (Tiny/Small/Normal/Large)
- **Colors**: customize colors for each regime
## What Makes It Different
Unlike existing volatility indicators:
1. **Automatic Adaptation**: no manual threshold configuration needed for each asset
2. **Machine Learning**: uses k-means clustering instead of fixed percentiles
3. **Self-Learning**: regime boundaries recalculated based on rolling window history
4. **Specific Recommendations**: not just volatility level display, but precise numerical multiplier for position sizing
5. **Noise Protection**: threshold-based smoothing prevents chaotic regime switching
6. **Universality**: ATR normalization allows application across any instruments (forex, stocks, crypto)
## Limitations
- Requires minimum 200 bars of history for correct operation
- On very low timeframes (M1-M5) may be overly sensitive
- Indicator reacts with slight delay due to smoothing (this protects against false signals)
## Recommendations
- **Intraday Trading**: use on H1-H4 with default parameters
- **Swing Trading**: increase Clustering Lookback to 300-500 bars
- **Scalping**: reduce Regime Smoothing to 1-2 and ATR Length to 7-10
- **Combination with Other Indicators**: use VRC as a risk filter on top of your main strategy
## Alerts
The indicator supports three alert types:
- **Regime Change**: any volatility regime change
- **Extreme Volatility**: entry into extreme volatility regime
- **Low Volatility**: entry into low volatility regime
---
**Important**: This indicator is a risk management tool, not a trading system. Use it in combination with a proven entry and exit strategy.
## The Problem
Most traders use the same position size regardless of market conditions. This leads to excessive risk during high volatility periods and missed profits during calm periods. Standard volatility indicators (ATR, Bollinger Bands) show current values but don't automatically classify market regimes.
## The Solution
**Volatility Regime Clustering** uses a machine learning algorithm (k-means clustering) to automatically identify volatility regimes based on historical data. The indicator independently finds boundaries between calm, normal, and nervous markets for each trading instrument.
## How It Works
### Technical Implementation
1. **Volatility Normalization**: ATR is converted to basis points for comparability across instruments with different prices.
2. **K-means Clustering**:
- The indicator analyzes the last N bars (default 200)
- Automatically groups historical ATR values into 2-4 clusters
- Cluster centroids are evenly distributed from minimum to maximum volatility
- The algorithm iteratively refines cluster boundaries every 5 bars
3. **False Signal Protection**:
- Threshold-based smoothing: regime changes only after 3+ consecutive confirmations
- Empty cluster protection with automatic reinitialization
- Warmup period to accumulate sufficient history
4. **Guaranteed Order**:
- Regime 0 always = low volatility
- Regime 1 always = medium volatility
- Regime 2 always = high volatility
- Regime 3 always = extreme volatility
## Visualization
- 🟢 **Green Background**: Low volatility - calm market, full position size recommended
- 🟡 **Yellow Background**: Medium volatility - standard conditions, 75-80% of normal risk recommended
- 🟠 **Orange Background**: High volatility - nervous market, reduce risk to 40-50%
- 🔴 **Red Background**: Extreme volatility - panic/news, minimum risk 25% or stay out
**Info Panel** (top right corner) displays:
- Current volatility regime
- ATR in basis points
- Current cluster center (regime mean value)
- Deviation from cluster center (how close to regime transition)
- Regime stability (% of time in current state)
- Recommended risk multiplier
- Recommended position size in %
## How to Use
### Basic Approach (Risk Management)
1. Add the indicator to any asset chart
2. Wait for warmup period completion (requires minimum 200 bars of history)
3. Monitor background color and recommendations table
4. Adjust position size according to risk multiplier
**Example**:
- You normally risk 2% of capital per trade
- Indicator shows "Risk Multiplier: 0.50x" (orange/red regime)
- Reduce risk to 1% (2% × 0.5 = 1%)
### Advanced Usage
**Entry Filtering**:
- Enter positions only in green/yellow regimes
- Avoid new positions during red background
**Open Position Management**:
- When transitioning to high volatility, move stop-losses further
- In calm regimes, use more aggressive take-profits
**Options Strategies**:
- High volatility → sell options (elevated premium)
- Low volatility → buy options before potential expansion
## Settings
### Main Parameters
- **ATR Length** (14): ATR calculation period. Lower = faster reaction, higher = smoother
- **Clustering Lookback** (200): number of bars for algorithm training. Recommended 150-300
- **Number of Regimes** (3): number of volatility regimes (2-4)
- 2 regimes: simple "calm/nervous"
- 3 regimes: "low/medium/high" (recommended)
- 4 regimes: adds "extreme" regime for rare events
- **Regime Smoothing** (3): number of confirmation bars for regime change. Higher = fewer false switches
### Visual Settings
- **Show Background Color**: enable/disable colored background
- **Show Regime Labels**: display labels on chart when regime changes
- **Show Risk Adjustment Info**: show/hide info panel
- **Info Panel Size**: panel font size (Tiny/Small/Normal/Large)
- **Colors**: customize colors for each regime
## What Makes It Different
Unlike existing volatility indicators:
1. **Automatic Adaptation**: no manual threshold configuration needed for each asset
2. **Machine Learning**: uses k-means clustering instead of fixed percentiles
3. **Self-Learning**: regime boundaries recalculated based on rolling window history
4. **Specific Recommendations**: not just volatility level display, but precise numerical multiplier for position sizing
5. **Noise Protection**: threshold-based smoothing prevents chaotic regime switching
6. **Universality**: ATR normalization allows application across any instruments (forex, stocks, crypto)
## Limitations
- Requires minimum 200 bars of history for correct operation
- On very low timeframes (M1-M5) may be overly sensitive
- Indicator reacts with slight delay due to smoothing (this protects against false signals)
## Recommendations
- **Intraday Trading**: use on H1-H4 with default parameters
- **Swing Trading**: increase Clustering Lookback to 300-500 bars
- **Scalping**: reduce Regime Smoothing to 1-2 and ATR Length to 7-10
- **Combination with Other Indicators**: use VRC as a risk filter on top of your main strategy
## Alerts
The indicator supports three alert types:
- **Regime Change**: any volatility regime change
- **Extreme Volatility**: entry into extreme volatility regime
- **Low Volatility**: entry into low volatility regime
---
**Important**: This indicator is a risk management tool, not a trading system. Use it in combination with a proven entry and exit strategy.
릴리즈 노트
code update오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
🎉 Join our FREE open Telegram channel! Everyone welcome! 📱✨ t.me/smart_day_trader
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.
오픈 소스 스크립트
트레이딩뷰의 진정한 정신에 따라, 이 스크립트의 작성자는 이를 오픈소스로 공개하여 트레이더들이 기능을 검토하고 검증할 수 있도록 했습니다. 작성자에게 찬사를 보냅니다! 이 코드는 무료로 사용할 수 있지만, 코드를 재게시하는 경우 하우스 룰이 적용된다는 점을 기억하세요.
🎉 Join our FREE open Telegram channel! Everyone welcome! 📱✨ t.me/smart_day_trader
면책사항
해당 정보와 게시물은 금융, 투자, 트레이딩 또는 기타 유형의 조언이나 권장 사항으로 간주되지 않으며, 트레이딩뷰에서 제공하거나 보증하는 것이 아닙니다. 자세한 내용은 이용 약관을 참조하세요.