OPEN-SOURCE SCRIPT
Hurst Exponent Adaptive Filter (HEAF) [PhenLabs]

📊 PhenLabs - Hurst Exponent Adaptive Filter (HEAF)
Version: PineScript™ v6
📌 Description
The Hurst Exponent Adaptive Filter (HEAF) is an advanced Pine Script indicator designed to dynamically adjust moving average calculations based on real time market regimes detected through the Hurst Exponent. The intention behind the creation of this indicator was not a buy/sell indicator but rather a tool to help sharpen traders ability to distinguish regimes in the market mathematically rather than guessing. By analyzing price persistence, it identifies whether the market is trending, mean-reverting, or exhibiting random walk behavior, automatically adapting the MA length to provide more responsive alerts in volatile conditions and smoother outputs in stable ones. This helps traders avoid false signals in choppy markets and capitalize on strong trends, making it ideal for adaptive trading strategies across various timeframes and assets.
Unlike traditional moving averages, HEAF incorporates fractal dimension analysis via the Hurst Exponent to create a self-tuning filter that evolves with market conditions. Traders benefit from visual cues like color coded regimes, adaptive bands for volatility channels, and an information panel that suggests appropriate strategies, enhancing decision making without constant manual adjustments by the user.
🚀 Points of Innovation
🔧 Core Components
🔥 Key Features
🎨 Visualization

📖 Usage Guidelines
Core Settings
Hurst Lookback Period
Minimum MA Length
Maximum MA Length
Sensitivity Power
MA Type
🖼️ Visual Settings
Show Adaptive Bands
Band Multiplier
Show Information Panel
MA Line Width
Color Theme
🚨 Alert Settings
Enable Alerts
✅ Best Use Cases
⚠️ Limitations
💡 What Makes This Unique
🔬 How It Works
Hurst Exponent Computation:
Length Adaptation:
Visualization and Signals:
Version: PineScript™ v6
📌 Description
The Hurst Exponent Adaptive Filter (HEAF) is an advanced Pine Script indicator designed to dynamically adjust moving average calculations based on real time market regimes detected through the Hurst Exponent. The intention behind the creation of this indicator was not a buy/sell indicator but rather a tool to help sharpen traders ability to distinguish regimes in the market mathematically rather than guessing. By analyzing price persistence, it identifies whether the market is trending, mean-reverting, or exhibiting random walk behavior, automatically adapting the MA length to provide more responsive alerts in volatile conditions and smoother outputs in stable ones. This helps traders avoid false signals in choppy markets and capitalize on strong trends, making it ideal for adaptive trading strategies across various timeframes and assets.
Unlike traditional moving averages, HEAF incorporates fractal dimension analysis via the Hurst Exponent to create a self-tuning filter that evolves with market conditions. Traders benefit from visual cues like color coded regimes, adaptive bands for volatility channels, and an information panel that suggests appropriate strategies, enhancing decision making without constant manual adjustments by the user.
🚀 Points of Innovation
- Dynamic MA length adjustment using Hurst Exponent for regime-aware filtering, reducing lag in trends and noise in ranges.
- Integrated market regime classification (trending, mean-reverting, random) with visual and alert-based notifications.
- Customizable color themes and adaptive bands that incorporate ATR for volatility-adjusted channels.
- Built-in information panel providing real-time strategy recommendations based on detected regimes.
- Power sensitivity parameter to fine-tune adaptation aggressiveness, allowing personalization for different trading styles.
- Support for multiple MA types (EMA, SMA, WMA) within an adaptive framework.
🔧 Core Components
- Hurst Exponent Calculation: Computes the fractal dimension of price series over a user-defined lookback to detect market persistence or anti-persistence.
- Adaptive Length Mechanism: Maps Hurst values to MA lengths between minimum and maximum bounds, using a power function for sensitivity control.
- Moving Average Engine: Applies the chosen MA type (EMA, SMA, or WMA) to the adaptive length for the core filter line.
- Adaptive Bands: Creates upper and lower channels using ATR multiplied by a band factor, scaled to the current adaptive length.
- Regime Detection: Classifies market state with thresholds (e.g., >0.55 for trending) and triggers alerts on regime changes.
- Visualization System: Includes gradient fills, regime-colored MA lines, and an info panel for at-a-glance insights.
🔥 Key Features
- Regime-Adaptive Filtering: Automatically shortens MA in mean-reverting markets for quick responses and lengthens it in trends for smoother signals, helping traders stay aligned with market dynamics.
- Custom Alerts: Notifies on regime shifts and band breakouts, enabling timely strategy adjustments like switching to trend-following in bullish regimes.
- Visual Enhancements: Color-coded MA lines, gradient band fills, and an optional info panel that displays market state and trading tips, improving chart readability.
- Flexible Settings: Adjustable lookback, min/max lengths, sensitivity power, MA type, and themes to suit various assets and timeframes.
- Band Breakout Signals: Highlights potential overbought/oversold conditions via ATR-based channels, useful for entry/exit timing.
🎨 Visualization
- Main Adaptive MA Line: Plotted with regime-based colors (e.g., green for trending) to visually indicate market state and filter position relative to price.
- Adaptive Bands: Upper and lower lines with gradient fills between them, showing volatility channels that widen in random regimes and tighten in trends.
- Price vs. MA Fills: Color-coded areas between price and MA (e.g., bullish green above MA in trending modes) for quick trend strength assessment.
- Information Panel: Top-right table displaying current regime (e.g., "Trending Market") and strategy suggestions like "Follow trends" or "Trade ranges."
📖 Usage Guidelines
Core Settings
Hurst Lookback Period
- Default: 100
- Range: 20-500
- Description: Sets the period for Hurst Exponent calculation; longer values provide more stable regime detection but may lag, while shorter ones are more responsive to recent changes.
Minimum MA Length
- Default: 10
- Range: 5-50
- Description: Defines the shortest possible adaptive MA length, ideal for fast responses in mean-reverting conditions.
Maximum MA Length
- Default: 200
- Range: 50-500
- Description: Sets the longest adaptive MA length for smoothing in strong trends; adjust based on asset volatility.
Sensitivity Power
- Default: 2.0
- Range: 1.0-5.0
- Description: Controls how aggressively the length adapts to Hurst changes; higher values make it more sensitive to regime shifts.
MA Type
- Default: EMA
- Options: EMA, SMA, WMA
- Description: Chooses the moving average calculation method; EMA is more responsive, while SMA/WMA offer different weighting.
🖼️ Visual Settings
Show Adaptive Bands
- Default: True
- Description: Toggles visibility of upper/lower bands for volatility channels.
Band Multiplier
- Default: 1.5
- Range: 0.5-3.0
- Description: Scales band width using ATR; higher values create wider channels for conservative signals.
Show Information Panel
- Default: True
- Description: Displays regime info and strategy tips in a top-right panel.
MA Line Width
- Default: 2
- Range: 1-5
- Description: Adjusts thickness of the main MA line for better visibility.
Color Theme
- Default: Blue
- Options: Blue, Classic, Dark Purple, Vibrant
- Description: Selects color scheme for MA, bands, and fills to match user preferences.
🚨 Alert Settings
Enable Alerts
- Default: True
- Description: Activates notifications for regime changes and band breakouts.
✅ Best Use Cases
- Trend-Following Strategies: In detected trending regimes, use the adaptive MA as a trailing stop or entry filter for momentum trades.
- Range Trading: During mean-reverting periods, monitor band breakouts for buying dips or selling rallies within channels.
- Risk Management in Random Markets: Reduce exposure when random walk is detected, using tight stops suggested in the info panel.
- Multi-Timeframe Analysis: Apply on higher timeframes for regime confirmation, then drill down to lower ones for entries.
- Volatility-Based Entries: Use upper/lower band crossovers as signals in adaptive channels for overbought/oversold trades.
⚠️ Limitations
- Lagging in Transitions: Regime detection may delay during rapid market shifts, requiring confirmation from other tools.
- Not a Standalone System: Best used in conjunction with other indicators; random regimes can lead to whipsaws if traded aggressively.
- Parameter Sensitivity: Optimal settings vary by asset and timeframe, necessitating backtesting.
💡 What Makes This Unique
- Hurst-Driven Adaptation: Unlike static MAs, it uses fractal analysis to self-tune, providing regime-specific filtering that's rare in standard indicators.
- Integrated Strategy Guidance: The info panel offers actionable tips tied to regimes, bridging analysis and execution.
- Multi-Regime Visualization: Combines adaptive bands, colored fills, and alerts in one tool for comprehensive market state awareness.
🔬 How It Works
Hurst Exponent Computation:
- Calculates log returns over the lookback period to derive the rescaled range (R/S) ratio.
- Normalizes to a 0-1 value, where >0.55 indicates trending, <0.45 mean-reverting, and in-between random.
Length Adaptation:
- Maps normalized Hurst to an MA length via a power function, clamping between min and max.
- Applies the selected MA type to close prices using this dynamic length.
Visualization and Signals:
- Plots the MA with regime colors, adds ATR-based bands, and fills areas for trend strength.
- Triggers alerts on regime changes or band crosses, with the info panel suggesting strategies like momentum riding in trends.
💡 Note:
For optimal results, backtest settings on your preferred assets and combine with volume or momentum indicators. Remember, no indicator guarantees profits—use with proper risk management. Access premium features and support at PhenLabs.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Smart Tools for Smarter Trades: phenlabs.com
Join our growing community: discord.gg/phen
All content provided by PhenLabs is for informational & educational purposes only. Past performance does not guarantee future results.
Join our growing community: discord.gg/phen
All content provided by PhenLabs is for informational & educational purposes only. Past performance does not guarantee future results.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.
Open-source script
In true TradingView spirit, the creator of this script has made it open-source, so that traders can review and verify its functionality. Kudos to the author! While you can use it for free, remember that republishing the code is subject to our House Rules.
Smart Tools for Smarter Trades: phenlabs.com
Join our growing community: discord.gg/phen
All content provided by PhenLabs is for informational & educational purposes only. Past performance does not guarantee future results.
Join our growing community: discord.gg/phen
All content provided by PhenLabs is for informational & educational purposes only. Past performance does not guarantee future results.
Disclaimer
The information and publications are not meant to be, and do not constitute, financial, investment, trading, or other types of advice or recommendations supplied or endorsed by TradingView. Read more in the Terms of Use.