OPEN-SOURCE SCRIPT
Volatility Regimes | GainzAlgo

๐ OVERVIEW:
=========
This is a comprehensive ATR-based trading system designed for professional
traders who need advanced volatility analysis, precise trade management, and
intelligent market regime detection. The indicator combines multiple proven
volatility concepts into one powerful, customizable tool.
โญ WHY THIS SYSTEM IS UNIQUE AND WORTHY OF PUBLICATION:
====================================================
This is not simply a collection of ATR-based indicators placed together.
It represents a unified volatility analysis framework where each component
is specifically designed to work in concert with the others, creating a
complete trading workflow that cannot be replicated by using multiple
separate indicators.
๐ SYNERGISTIC INTEGRATION - How Components Work Together:
๐ง 1. CONTEXT-AWARE ANALYSIS
The Volatility Regime Detection acts as the "brain" of the system,
classifying market conditions into 4 distinct phases. Every other
component then adapts its behavior based on this regime classification:
- ATR Bands expand/contract with regime changes
- Stop Loss distances automatically adjust (tighter in compression,
wider in high volatility)
- Take Profit targets scale proportionally to current regime
- Signal sensitivity filters itself based on market phase
๐ 2. UNIFIED VOLATILITY FOUNDATION
All calculations share a single ATR baseline calculation, ensuring
internal consistency across the entire system. When ATR changes, every
element updates in perfect synchronization:
- Bands recalculate from the same ATR value
- Risk management levels use the same volatility measurement
- Regime classification and signals reference identical data
๐ก๏ธ 3. INTEGRATED RISK MANAGEMENT
The system doesn't just show WHERE to enter - it calculates HOW MUCH
to risk:
- Dynamic Stop Loss adapts to current ATR automatically
- Position Size Calculator uses the dynamic stop to compute exact quantities
- Take Profit levels scale proportionally, maintaining optimal risk:reward
โ 4. TWO-STAGE SIGNAL CONFIRMATION
The alert system creates a logical progression:
Step 1: Volatility Breakout โ Market energy is building
Step 2: Trend Confirmation โ Direction confirmed with volatility support
This prevents false breakouts by requiring both volatility AND direction.
๐ฆ 5. PROFESSIONAL WORKFLOW INTEGRATION
The system mirrors how institutional traders analyze markets:
Phase 1: Assess regime โ What's the market doing?
Phase 2: Identify setup โ Where's the opportunity?
Phase 3: Calculate risk โ What's my exposure?
Phase 4: Set targets โ Where do I take profit?
Phase 5: Monitor regime โ When do conditions change?
โ WHY NOT USE SEPARATE INDICATORS?
- Separate ATR Bands: Don't know about regime changes, remain static
- Separate Regime Indicator: Doesn't automatically adjust stop/targets
- Separate Position Calculator: Doesn't know your actual ATR-based stop
- Manual Integration: Requires constant mental calculation and cross-referencing
๐งฎ DETAILED CALCULATION METHODOLOGY:
=================================
๐ ATR (AVERAGE TRUE RANGE) CALCULATION:
- True Range = Maximum of:
1. Current High - Current Low
2. Absolute value of (Current High - Previous Close)
3. Absolute value of (Current Low - Previous Close)
- ATR = Simple Moving Average of True Range over specified period (default: 14)
๐ DYNAMIC ATR BANDS:
- Upper Band = Current Close + (ATR ร Band Multiplier)
- Lower Band = Current Close - (ATR ร Band Multiplier)
- Band 1: 1.0ร ATR (closest support/resistance)
- Band 2: 2.0ร ATR (intermediate zone)
- Band 3: 3.0ร ATR (extended zone)
๐ก๏ธ VOLATILITY REGIME CLASSIFICATION:
Step 1: Calculate ATR Baseline
- Baseline ATR = SMA or EMA of ATR over long period (default: 50 bars)
- This represents "normal" volatility for the instrument
Step 2: Calculate ATR Ratio
- ATR Ratio = Current ATR รท Baseline ATR
- Example: If current ATR = 70 and baseline = 50, ratio = 1.40
Step 3: Classify Regime Based on Ratio
- COMPRESSION: Ratio < 0.70 (ATR is 30% below normal)
Market consolidating, volatility contracting, energy building
- EXPANSION: Ratio between 1.15 and 1.40 (ATR is 15-40% above normal)
Volatility breaking out, early phase of directional movement
- HIGH VOLATILITY: Ratio > 1.40 (ATR is 40%+ above normal)
Strong sustained trend with high participation
- EXHAUSTION: ATR declining after high volatility period
Requires: Previous high ratio + declining ATR over X bars (default: 5)
Trend maturity, potential reversal or consolidation approaching
๐ DYNAMIC STOP LOSS CALCULATION:
- For Long Positions: Stop Loss = Entry Price - (ATR ร SL Multiplier)
- For Short Positions: Stop Loss = Entry Price + (ATR ร SL Multiplier)
- Default Multiplier: 2.0ร ATR
- Adjusts automatically: Wider in high volatility, tighter in compression
๐ฏ TAKE PROFIT LEVELS:
- TP1 = Entry Price ยฑ (ATR ร TP1 Multiplier) [default: 1.5ร]
- TP2 = Entry Price ยฑ (ATR ร TP2 Multiplier) [default: 2.5ร]
- TP3 = Entry Price ยฑ (ATR ร TP3 Multiplier) [default: 4.0ร]
- Direction (+ or -) depends on trade direction
๐ฆ POSITION SIZE CALCULATION:
Formula: Position Size = Account Risk Amount รท Stop Loss Distance
Step-by-step:
1. Risk Amount = Account Size ร (Risk Percentage รท 100)
2. Stop Distance = |Entry Price - Stop Loss Price|
3. Position Size = Risk Amount รท Stop Distance
๐ ATR PERCENTILE RANKING:
- >80% = Extremely high volatility
- 20-80% = Normal volatility range
- <20% = Extremely low volatility
๐ VOLATILITY CONTRACTION PATTERN:
Detects extended low-volatility periods indicating imminent breakout.
๐งญ TREND DETECTION SIGNALS:
Bullish: Price > MA AND Current ATR > ATR MA
Bearish: Price < MA AND Current ATR > ATR MA
โก VOLATILITY BREAKOUT SIGNALS:
Triggered when ATR exceeds its moving average by a defined threshold.
๐งฉ CORE FEATURES:
==============
1. ATR BANDS (Dynamic Support/Resistance)
2. VOLATILITY REGIME DETECTION
3. DYNAMIC STOP LOSS SYSTEM
4. MULTIPLE TAKE PROFIT LEVELS
5. SUPPORT & RESISTANCE LEVELS
6. RISK MANAGEMENT CALCULATOR
7. ATR PERCENTILE RANKING
8. VOLATILITY CONTRACTION PATTERN
9. TREND DETECTION SIGNALS
10. VOLATILITY BREAKOUT SIGNALS
โ๏ธ RECOMMENDED SETTINGS BY TRADING STYLE:
======================================
DAY TRADING โข SWING TRADING โข POSITION TRADING โข SCALPING
๐ HOW TO USE THIS INDICATOR:
==========================
STEP 1: Identify Market Regime
STEP 2: Wait for Entry Signal
STEP 3: Set Stop Loss
STEP 4: Set Take Profits
STEP 5: Position Sizing
STEP 6: Monitor & Manage
๐ ALERT SYSTEM:
=============
Alerts for volatility breakouts, trend changes, regime transitions,
ATR band crossings, contraction completion, and percentile extremes.
๐จ CUSTOMIZATION:
==============
All visuals, thresholds, multipliers, colors, alerts, and risk parameters
can be fully customized.
โ ๏ธ IMPORTANT DISCLAIMER:
=====================
This indicator is a volatility analysis tool and does NOT provide financial advice.
Past performance does not guarantee future results.
All trading involves substantial risk.
All trading decisions are the sole responsibility of the user.
=========
This is a comprehensive ATR-based trading system designed for professional
traders who need advanced volatility analysis, precise trade management, and
intelligent market regime detection. The indicator combines multiple proven
volatility concepts into one powerful, customizable tool.
โญ WHY THIS SYSTEM IS UNIQUE AND WORTHY OF PUBLICATION:
====================================================
This is not simply a collection of ATR-based indicators placed together.
It represents a unified volatility analysis framework where each component
is specifically designed to work in concert with the others, creating a
complete trading workflow that cannot be replicated by using multiple
separate indicators.
๐ SYNERGISTIC INTEGRATION - How Components Work Together:
๐ง 1. CONTEXT-AWARE ANALYSIS
The Volatility Regime Detection acts as the "brain" of the system,
classifying market conditions into 4 distinct phases. Every other
component then adapts its behavior based on this regime classification:
- ATR Bands expand/contract with regime changes
- Stop Loss distances automatically adjust (tighter in compression,
wider in high volatility)
- Take Profit targets scale proportionally to current regime
- Signal sensitivity filters itself based on market phase
๐ 2. UNIFIED VOLATILITY FOUNDATION
All calculations share a single ATR baseline calculation, ensuring
internal consistency across the entire system. When ATR changes, every
element updates in perfect synchronization:
- Bands recalculate from the same ATR value
- Risk management levels use the same volatility measurement
- Regime classification and signals reference identical data
๐ก๏ธ 3. INTEGRATED RISK MANAGEMENT
The system doesn't just show WHERE to enter - it calculates HOW MUCH
to risk:
- Dynamic Stop Loss adapts to current ATR automatically
- Position Size Calculator uses the dynamic stop to compute exact quantities
- Take Profit levels scale proportionally, maintaining optimal risk:reward
โ 4. TWO-STAGE SIGNAL CONFIRMATION
The alert system creates a logical progression:
Step 1: Volatility Breakout โ Market energy is building
Step 2: Trend Confirmation โ Direction confirmed with volatility support
This prevents false breakouts by requiring both volatility AND direction.
๐ฆ 5. PROFESSIONAL WORKFLOW INTEGRATION
The system mirrors how institutional traders analyze markets:
Phase 1: Assess regime โ What's the market doing?
Phase 2: Identify setup โ Where's the opportunity?
Phase 3: Calculate risk โ What's my exposure?
Phase 4: Set targets โ Where do I take profit?
Phase 5: Monitor regime โ When do conditions change?
โ WHY NOT USE SEPARATE INDICATORS?
- Separate ATR Bands: Don't know about regime changes, remain static
- Separate Regime Indicator: Doesn't automatically adjust stop/targets
- Separate Position Calculator: Doesn't know your actual ATR-based stop
- Manual Integration: Requires constant mental calculation and cross-referencing
๐งฎ DETAILED CALCULATION METHODOLOGY:
=================================
๐ ATR (AVERAGE TRUE RANGE) CALCULATION:
- True Range = Maximum of:
1. Current High - Current Low
2. Absolute value of (Current High - Previous Close)
3. Absolute value of (Current Low - Previous Close)
- ATR = Simple Moving Average of True Range over specified period (default: 14)
๐ DYNAMIC ATR BANDS:
- Upper Band = Current Close + (ATR ร Band Multiplier)
- Lower Band = Current Close - (ATR ร Band Multiplier)
- Band 1: 1.0ร ATR (closest support/resistance)
- Band 2: 2.0ร ATR (intermediate zone)
- Band 3: 3.0ร ATR (extended zone)
๐ก๏ธ VOLATILITY REGIME CLASSIFICATION:
Step 1: Calculate ATR Baseline
- Baseline ATR = SMA or EMA of ATR over long period (default: 50 bars)
- This represents "normal" volatility for the instrument
Step 2: Calculate ATR Ratio
- ATR Ratio = Current ATR รท Baseline ATR
- Example: If current ATR = 70 and baseline = 50, ratio = 1.40
Step 3: Classify Regime Based on Ratio
- COMPRESSION: Ratio < 0.70 (ATR is 30% below normal)
Market consolidating, volatility contracting, energy building
- EXPANSION: Ratio between 1.15 and 1.40 (ATR is 15-40% above normal)
Volatility breaking out, early phase of directional movement
- HIGH VOLATILITY: Ratio > 1.40 (ATR is 40%+ above normal)
Strong sustained trend with high participation
- EXHAUSTION: ATR declining after high volatility period
Requires: Previous high ratio + declining ATR over X bars (default: 5)
Trend maturity, potential reversal or consolidation approaching
๐ DYNAMIC STOP LOSS CALCULATION:
- For Long Positions: Stop Loss = Entry Price - (ATR ร SL Multiplier)
- For Short Positions: Stop Loss = Entry Price + (ATR ร SL Multiplier)
- Default Multiplier: 2.0ร ATR
- Adjusts automatically: Wider in high volatility, tighter in compression
๐ฏ TAKE PROFIT LEVELS:
- TP1 = Entry Price ยฑ (ATR ร TP1 Multiplier) [default: 1.5ร]
- TP2 = Entry Price ยฑ (ATR ร TP2 Multiplier) [default: 2.5ร]
- TP3 = Entry Price ยฑ (ATR ร TP3 Multiplier) [default: 4.0ร]
- Direction (+ or -) depends on trade direction
๐ฆ POSITION SIZE CALCULATION:
Formula: Position Size = Account Risk Amount รท Stop Loss Distance
Step-by-step:
1. Risk Amount = Account Size ร (Risk Percentage รท 100)
2. Stop Distance = |Entry Price - Stop Loss Price|
3. Position Size = Risk Amount รท Stop Distance
๐ ATR PERCENTILE RANKING:
- >80% = Extremely high volatility
- 20-80% = Normal volatility range
- <20% = Extremely low volatility
๐ VOLATILITY CONTRACTION PATTERN:
Detects extended low-volatility periods indicating imminent breakout.
๐งญ TREND DETECTION SIGNALS:
Bullish: Price > MA AND Current ATR > ATR MA
Bearish: Price < MA AND Current ATR > ATR MA
โก VOLATILITY BREAKOUT SIGNALS:
Triggered when ATR exceeds its moving average by a defined threshold.
๐งฉ CORE FEATURES:
==============
1. ATR BANDS (Dynamic Support/Resistance)
2. VOLATILITY REGIME DETECTION
3. DYNAMIC STOP LOSS SYSTEM
4. MULTIPLE TAKE PROFIT LEVELS
5. SUPPORT & RESISTANCE LEVELS
6. RISK MANAGEMENT CALCULATOR
7. ATR PERCENTILE RANKING
8. VOLATILITY CONTRACTION PATTERN
9. TREND DETECTION SIGNALS
10. VOLATILITY BREAKOUT SIGNALS
โ๏ธ RECOMMENDED SETTINGS BY TRADING STYLE:
======================================
DAY TRADING โข SWING TRADING โข POSITION TRADING โข SCALPING
๐ HOW TO USE THIS INDICATOR:
==========================
STEP 1: Identify Market Regime
STEP 2: Wait for Entry Signal
STEP 3: Set Stop Loss
STEP 4: Set Take Profits
STEP 5: Position Sizing
STEP 6: Monitor & Manage
๐ ALERT SYSTEM:
=============
Alerts for volatility breakouts, trend changes, regime transitions,
ATR band crossings, contraction completion, and percentile extremes.
๐จ CUSTOMIZATION:
==============
All visuals, thresholds, multipliers, colors, alerts, and risk parameters
can be fully customized.
โ ๏ธ IMPORTANT DISCLAIMER:
=====================
This indicator is a volatility analysis tool and does NOT provide financial advice.
Past performance does not guarantee future results.
All trading involves substantial risk.
All trading decisions are the sole responsibility of the user.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source verรถffentlicht. Auf diese Weise kรถnnen nun auch andere Trader das Script rezensieren und die Funktionalitรคt รผberprรผfen. Vielen Dank an den Autor! Sie kรถnnen das Script kostenlos verwenden, aber eine Wiederverรถffentlichung des Codes unterliegt unseren Hausregeln.
Get GainzAlgo only at gainzalgo.com
Haftungsausschluss
Die Informationen und Verรถffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlรคgen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.
Open-source Skript
Ganz im Sinne von TradingView hat dieser Autor sein/ihr Script als Open-Source verรถffentlicht. Auf diese Weise kรถnnen nun auch andere Trader das Script rezensieren und die Funktionalitรคt รผberprรผfen. Vielen Dank an den Autor! Sie kรถnnen das Script kostenlos verwenden, aber eine Wiederverรถffentlichung des Codes unterliegt unseren Hausregeln.
Get GainzAlgo only at gainzalgo.com
Haftungsausschluss
Die Informationen und Verรถffentlichungen sind nicht als Finanz-, Anlage-, Handels- oder andere Arten von Ratschlรคgen oder Empfehlungen gedacht, die von TradingView bereitgestellt oder gebilligt werden, und stellen diese nicht dar. Lesen Sie mehr in den Nutzungsbedingungen.