Adaptive Regime Filter + Divergence (AER-VN) [KEYALGOS]Adaptive Regime Filter + Divergence (AER-VN)
Professional Grade Market Regime Classification with Advanced Divergence Detection
Precision trend identification using Adaptive Efficiency Ratio methodology
Volatility-normalized thresholds that adjust to real-time market conditions
Automatic divergence detection (Regular and Hidden) with visual confirmation lines
Four distinct market regimes with color-coded clarity
Zero-lag signal generation with confirmation logic
OVERVIEW
The Adaptive Regime Filter with Volatility Normalization (AER-VN) represents a sophisticated evolution of traditional trend filtering methodologies. This proprietary indicator combines Kaufman's Efficiency Ratio principles with dynamic volatility adaptation to classify market conditions into four actionable regimes: Uptrend, Downtrend, Choppiness, and Consolidation.
The integrated Divergence Detection System operates as a secondary analytical layer, identifying momentum exhaustion and trend continuation patterns through comparative analysis of price action versus efficiency metrics. Unlike standard oscillators that measure raw momentum, this system evaluates the quality of price movement, providing earlier and more reliable reversal signals.
METHODOLOGY AND TECHNIQUE
1. Adaptive Efficiency Ratio (AER) Core
Traditional efficiency ratios utilize static thresholds that fail across varying volatility environments. The AER-VN methodology introduces dynamic threshold calculation that self-adjusts based on current volatility relative to historical norms.
Displacement Measurement: Calculates net price movement over the lookback period
Path Distance Analysis: Sums absolute bar-to-bar movements to determine movement quality
Efficiency Calculation: Ratio of displacement to path distance (0.0 to 1.0 scale)
Threshold Adaptation: Baseline efficiency requirements scale proportionally with the ATR ratio
When volatility expands (ATR above mean), the system automatically raises the efficiency threshold required to qualify as "trending." This prevents false trend signals during volatile chop. Conversely, during low volatility periods, the threshold contracts to capture subtle trending behavior.
2. Volatility Normalization Engine
The Volatility Normalization component creates a relative volatility index by comparing current ATR readings against a rolling historical average. This produces an ATR Ratio that serves as the scaling factor for dynamic threshold calculation.
Current ATR: Short-term volatility measurement (default 14 periods)
Mean ATR: Long-term volatility baseline (default 50 periods)
Adaptive Scaling: Raw threshold = Base Threshold x ATR Ratio
Ceiling Protection: Maximum threshold cap prevents mathematically impossible requirements during extreme volatility events
3. Four Regime Classification System
Uptrend (Teal): Efficiency exceeds dynamic threshold with positive price displacement. Indicates high-quality upward movement with minimal retracement.
Downtrend (Maroon): Efficiency exceeds dynamic threshold with negative price displacement. Indicates sustained selling pressure with directional clarity.
Choppiness (Orange): Efficiency below threshold during above-average volatility. Characterized by noisy, directionless movement with large wicks and whipsaws.
Consolidation (Gray): Efficiency below threshold during below-average volatility. Represents quiet, range-bound markets with compressed price action.
4. Zero-Lag Divergence Detection
The divergence system employs confirmed swing detection to identify pivotal highs and lows without repainting. Once a swing point is confirmed (price violates the extreme), the system evaluates four divergence classifications:
Regular Bearish Divergence: Price records higher highs while Efficiency Ratio records lower highs. Indicates trend exhaustion and potential reversal to the downside.
Regular Bullish Divergence: Price records lower lows while Efficiency Ratio records higher lows. Indicates selling exhaustion and potential reversal to the upside.
Hidden Bearish Divergence: Price records lower highs while Efficiency Ratio records higher highs. Suggests continuation of the current downtrend after a pullback.
Hidden Bullish Divergence: Price records higher lows while Efficiency Ratio records lower lows. Suggests continuation of the current uptrend after a retracement.
Visual confirmation lines connect the relevant swing points on the indicator panel, allowing traders to verify divergence validity visually.
INPUT PARAMETERS AND CONFIGURATION
Efficiency Ratio Settings
ER Lookback (N)
Default: 10 | Range: 2+
The calculation period for efficiency measurement. Shorter values increase sensitivity to recent price action, suitable for scalping lower timeframes. Longer values smooth the oscillator, better for swing trading higher timeframes.
Base ER Threshold
Default: 0.25 | Range: 0.05 to 0.80 | Step: 0.05
The foundational efficiency level required in normalized volatility conditions. Higher values demand cleaner, more directional movement to trigger trending regime classification. Lower values allow noisier price action to qualify as trending.
Max Threshold Cap
Default: 0.65 | Range: 0.10 to 0.99 | Step: 0.05
The absolute ceiling for the dynamic threshold. This safety mechanism prevents the threshold from rising to levels mathematically impossible to achieve during extreme volatility expansion.
Volatility Normalization Settings
ATR Length
Default: 14 | Range: 1+
The lookback period for Average True Range calculation. Determines how quickly the system responds to changing volatility conditions.
ATR Mean Lookback
Default: 50 | Range: 5+
The historical window for establishing the volatility baseline. Longer periods create a smoother volatility reference, while shorter periods adapt more quickly to regime changes in volatility.
Divergence Detection Settings
Swing Definition Length
Default: 10 | Range: 3+
The lookback window for identifying swing highs and lows. Determines the minimum number of bars required to establish a pivot point. Lower values detect micro-swings (more signals, more noise). Higher values detect major swings (fewer signals, higher quality).
Visual Display Toggles
Show Regular Div Markers: Display circle markers for Regular Bearish and Regular Bullish divergences
Show Hidden Div Markers: Display circle markers for Hidden Bearish and Hidden Bullish divergences
Line: Regular Bearish: Draw connecting lines between swing highs for Regular Bearish divergences (Red)
Line: Regular Bullish: Draw connecting lines between swing lows for Regular Bullish divergences (Lime)
Line: Hidden Bearish: Draw connecting lines for Hidden Bearish divergences (Orange)
Line: Hidden Bullish: Draw connecting lines for Hidden Bullish divergences (Aqua)
Visual Settings
Color Price Bars
Toggle to apply regime colors directly to price candles/bars on the main chart. Uptrend (Teal), Downtrend (Maroon), Choppiness (Orange), Consolidation (Gray).
INTERPRETATION GUIDE
Reading the Oscillator
The main panel displays three critical elements:
Efficiency Ratio Line: The primary oscillator colored by current regime. Values near 1.0 indicate perfect efficiency (strong trend). Values near 0.0 indicate complete inefficiency (chop).
Dynamic Threshold: The white crossed line representing the current volatility-adjusted efficiency requirement. When the ER line crosses above this threshold, the regime shifts to trending.
Base Threshold Reference: The gray dotted line showing the static baseline (0.25 default) for reference.
Divergence Signal Interpretation
Red Circle (Regular Bearish): Momentum divergence at highs. Consider reducing long exposure or preparing short entries. Highest probability when appearing near resistance or after extended uptrends.
Lime Circle (Regular Bullish): Momentum divergence at lows. Consider reducing short exposure or preparing long entries. Highest probability when appearing near support or after extended downtrends.
Orange Circle (Hidden Bearish): Trend continuation signal in downtrends. Pullback likely ending, downtrend resumption probable.
Aqua Circle (Hidden Bullish): Trend continuation signal in uptrends. Retracement likely ending, uptrend resumption probable.
TRADING APPLICATIONS
Strategy 1: Regime-Based Trend Following
Enter long positions only when the indicator displays Teal coloring (Uptrend regime) and short positions only during Maroon coloring (Downtrend regime). Exit positions when the regime shifts to Orange or Gray, indicating the trending condition has ended.
Best for: Directional traders and trend followers
Timeframe: M15 and higher recommended for stability
Confluence: Combine with moving average alignment or breakout patterns
Strategy 2: Divergence Reversal Trading
Monitor for Regular Divergences (Red or Lime circles) as early warning systems. Wait for price confirmation (engulfing candles, pin bars) at the divergence point before entering. Use the connecting lines to visualize the divergence strength.
Best for: Counter-trend scalpers and swing traders
Timeframe: M5 to H1 depending on swing length settings
Confluence: Combine with support/resistance levels and volume analysis
Strategy 3: Chop Avoidance and Consolidation Breakout
Use the Orange (Choppiness) and Gray (Consolidation) regimes as "No Trade" zones or reduction zones. Wait for a divergence to form within these regimes, then enter when the regime shifts back to trending (Teal or Maroon), capturing the breakout momentum.
Best for: Patience-based traders seeking high-probability setups
Timeframe: Effective across all timeframes
Confluence: Combine with volume expansion on regime change
Strategy 4: Hidden Divergence Continuation
In established trends (Teal lasting 5+ bars), look for Hidden Bullish Divergences (Aqua) on pullbacks to enter additional long positions. In established downtrends (Maroon), look for Hidden Bearish Divergences (Orange) on rallies to add to shorts.
Best for: Position traders adding to winners
Timeframe: H1 to Daily for best results
Confluence: Combine with Fibonacci retracement levels
OPTIMIZATION GUIDELINES
For Lower Timeframes (M1 to M5)
Reduce ER Lookback to 6-8 for faster response
Lower Base ER Threshold to 0.15-0.20 to account for noise
Reduce Max Threshold Cap to 0.50-0.55
Shorten ATR Mean Lookback to 20-30
Reduce Swing Definition Length to 6-8 for micro-structure
For Higher Timeframes (H1 to Daily)
Increase ER Lookback to 14-21 for smoother readings
Maintain or increase Base ER Threshold to 0.30+ for quality control
Increase ATR Mean Lookback to 50-100 for stable volatility baselines
Increase Swing Definition Length to 10-20 for major pivots only
ALERTS AND NOTIFICATIONS
The indicator includes built-in alert conditions for:
Regular Bearish Divergence Detection
Regular Bullish Divergence Detection
Configure TradingView alerts to trigger on these conditions to monitor markets without constant chart watching.
BEST PRACTICES AND RISK MANAGEMENT
Always confirm divergence signals with price action patterns (engulfing candles, pin bars, break of structure) rather than entering immediately on marker appearance.
Avoid trading divergence signals that occur deep within the Choppiness (Orange) regime without waiting for a regime shift confirmation.
Use the regime colors as a position sizing guide: Full size in Teal/Maroon, half size in Gray, flat or minimal in Orange.
The indicator excels when combined with support/resistance analysis. Divergences forming at key S/R levels carry significantly higher probability.
In ranging markets, decrease the Base ER Threshold to reduce whipsaws. In strongly trending markets, consider increasing it to filter out minor retracements.
TECHNICAL NOTES
The indicator does not repaint. Swing points require confirmation on the subsequent bar to print, ensuring signals remain fixed after formation.
All calculations utilize Pine Script v6 native functions for optimal performance and minimal resource usage.
The Volatility Normalization component prevents the common failure mode of static efficiency indicators during periods of expanding volatility.
Connecting lines for divergences are managed with automatic cleanup protocols to prevent chart clutter on extended runs.
SUPPORT AND UPDATES
This indicator is maintained by KeyAlgos. All users receive automatic updates as methodology improvements are implemented. For questions regarding parameter optimization or implementation strategies, utilize the TradingView comments section on this publication.
Disclaimer: This indicator is a technical analysis tool designed to assist with market analysis, not a guaranteed profit system. Always practice proper risk management and use stop losses. Past performance of indicator signals does not guarantee future results.
Wskaźnik Pine Script®






















