OPEN-SOURCE SCRIPT
Market Volatility Index

Market Regime: Pivot Density + Efficiency + ATR Compression
A market regime detection tool designed to help identify whether price is currently behaving more like a trending market, ranging market, or transitioning environment.
Rather than relying on a single metric, this indicator combines three independent market behavior measurements into a weighted composite score:
• Pivot Density
• Price Efficiency Ratio
• ATR Compression/Expansion
The goal is to provide context before entering trades so you can better align strategy selection with current market conditions.
How It Works
Pivot Density
Measures how frequently pivot highs and lows occur over a lookback period.
High pivot density:
• More frequent reversals
• More indecision
• More likely ranging/choppy behavior
Low pivot density:
• Cleaner directional movement
• Stronger trends
Efficiency Ratio
Measures:
Net Movement ÷ Total Movement
High efficiency:
• Directional price movement
• Stronger trend behavior
Low efficiency:
• Back-and-forth movement
• Less directional conviction
ATR Compression / Expansion
Measures current volatility relative to historical volatility.
ATR compressed:
• Volatility contraction
• Common during ranges or consolidation
ATR expanded:
• Increasing volatility
• Common during stronger directional movement
Composite Regime Score
The three components are combined into a weighted score:
0 → Strong Trend Environment
1 → Strong Range Environment
Default interpretation:
🟢 Trend Zone
Range Score ≤ Trend Threshold
🟡 Transition Zone
Between thresholds
🔴 Range Zone
Range Score ≥ Range Threshold
Background Colors
Green Background
• Trending conditions
• Lower pivot density
• Higher efficiency
• Expanding volatility
Yellow Background
• Mixed or transitional conditions
Red Background
• Choppy/ranging conditions
• Higher pivot density
• Lower efficiency
• Volatility compression
Inputs
Timeframe
Calculation Timeframe
Allows calculations from an alternate timeframe while remaining on the current chart.
Wait Until Bar Close
Uses confirmed higher timeframe values to reduce intrabar fluctuations and maintain consistency.
Pivot Density
Pivot Length
Controls pivot sensitivity.
Lower values:
• More pivots
• Faster response
Higher values:
• Fewer pivots
• Smoother behavior
Pivot Lookback
Number of bars used for pivot density calculations.
Efficiency
Efficiency Length
Controls how far back directional efficiency is measured.
Lower values:
• Faster reactions
Higher values:
• More smoothing
ATR Compression
ATR Length
Length used for current volatility calculations.
ATR Baseline Length
Historical volatility average used for comparison.
Weighting
Adjust contribution of:
• Pivot Density
• Efficiency
• ATR Compression
Increasing a weight causes that component to have greater influence on the final regime score.
Potential Uses
✓ Trend-following strategy filter
✓ Mean reversion strategy filter
✓ Avoiding choppy conditions
✓ Volatility regime detection
✓ Multi-timeframe market context
✓ Strategy optimization
Notes
This indicator is intended as an environment and context tool rather than a direct buy or sell signal generator.
Market regimes constantly evolve, and understanding whether conditions favor trend continuation or mean reversion can help improve decision-making.
Best used alongside:
• Market structure
• Trend tools
• Volume analysis
• Entry and risk management systems
About TrendGenY Indicators
TrendGenY indicators are built from market experience, creative concepts, and a constant pursuit of unique perspectives. Rather than following conventional ideas, the focus is on uncovering alternative insights and viewing market behavior through different angles to reveal information that traditional tools may overlook and help traders build a more meaningful edge in the market.
A market regime detection tool designed to help identify whether price is currently behaving more like a trending market, ranging market, or transitioning environment.
Rather than relying on a single metric, this indicator combines three independent market behavior measurements into a weighted composite score:
• Pivot Density
• Price Efficiency Ratio
• ATR Compression/Expansion
The goal is to provide context before entering trades so you can better align strategy selection with current market conditions.
How It Works
Pivot Density
Measures how frequently pivot highs and lows occur over a lookback period.
High pivot density:
• More frequent reversals
• More indecision
• More likely ranging/choppy behavior
Low pivot density:
• Cleaner directional movement
• Stronger trends
Efficiency Ratio
Measures:
Net Movement ÷ Total Movement
High efficiency:
• Directional price movement
• Stronger trend behavior
Low efficiency:
• Back-and-forth movement
• Less directional conviction
ATR Compression / Expansion
Measures current volatility relative to historical volatility.
ATR compressed:
• Volatility contraction
• Common during ranges or consolidation
ATR expanded:
• Increasing volatility
• Common during stronger directional movement
Composite Regime Score
The three components are combined into a weighted score:
0 → Strong Trend Environment
1 → Strong Range Environment
Default interpretation:
🟢 Trend Zone
Range Score ≤ Trend Threshold
🟡 Transition Zone
Between thresholds
🔴 Range Zone
Range Score ≥ Range Threshold
Background Colors
Green Background
• Trending conditions
• Lower pivot density
• Higher efficiency
• Expanding volatility
Yellow Background
• Mixed or transitional conditions
Red Background
• Choppy/ranging conditions
• Higher pivot density
• Lower efficiency
• Volatility compression
Inputs
Timeframe
Calculation Timeframe
Allows calculations from an alternate timeframe while remaining on the current chart.
Wait Until Bar Close
Uses confirmed higher timeframe values to reduce intrabar fluctuations and maintain consistency.
Pivot Density
Pivot Length
Controls pivot sensitivity.
Lower values:
• More pivots
• Faster response
Higher values:
• Fewer pivots
• Smoother behavior
Pivot Lookback
Number of bars used for pivot density calculations.
Efficiency
Efficiency Length
Controls how far back directional efficiency is measured.
Lower values:
• Faster reactions
Higher values:
• More smoothing
ATR Compression
ATR Length
Length used for current volatility calculations.
ATR Baseline Length
Historical volatility average used for comparison.
Weighting
Adjust contribution of:
• Pivot Density
• Efficiency
• ATR Compression
Increasing a weight causes that component to have greater influence on the final regime score.
Potential Uses
✓ Trend-following strategy filter
✓ Mean reversion strategy filter
✓ Avoiding choppy conditions
✓ Volatility regime detection
✓ Multi-timeframe market context
✓ Strategy optimization
Notes
This indicator is intended as an environment and context tool rather than a direct buy or sell signal generator.
Market regimes constantly evolve, and understanding whether conditions favor trend continuation or mean reversion can help improve decision-making.
Best used alongside:
• Market structure
• Trend tools
• Volume analysis
• Entry and risk management systems
About TrendGenY Indicators
TrendGenY indicators are built from market experience, creative concepts, and a constant pursuit of unique perspectives. Rather than following conventional ideas, the focus is on uncovering alternative insights and viewing market behavior through different angles to reveal information that traditional tools may overlook and help traders build a more meaningful edge in the market.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.
Mã nguồn mở
Theo đúng tinh thần TradingView, tác giả của tập lệnh này đã công bố nó dưới dạng mã nguồn mở, để các nhà giao dịch có thể xem xét và xác minh chức năng. Chúc mừng tác giả! Mặc dù bạn có thể sử dụng miễn phí, hãy nhớ rằng việc công bố lại mã phải tuân theo Nội quy.
Thông báo miễn trừ trách nhiệm
Thông tin và các ấn phẩm này không nhằm mục đích, và không cấu thành, lời khuyên hoặc khuyến nghị về tài chính, đầu tư, giao dịch hay các loại khác do TradingView cung cấp hoặc xác nhận. Đọc thêm tại Điều khoản Sử dụng.