OPEN-SOURCE SCRIPT
Обновлено

Hurst Dual-Channel + ECDF Early Reentry (Single Trigger)

298
Hello,
This indicator can be useful during ranging market phases, especially on short timeframes such as 5 minutes, within a statistically contrarian approach.
It combines two quantitative methodologies:
– Hurst-type adaptive channels, which measure short- and medium-term price deviations using the ATR (Average True Range);
– an Empirical Cumulative Distribution Function (ECDF), which locates the current price between its recent extremes (0 corresponding to the lower bound, 1 to the upper bound).
The goal is to identify relative overbought and oversold zones, where the price exceeds the channels and then begins to revert toward its statistical mean.
The indicator does not issue trading recommendations: it merely highlights specific statistical conditions for research and analytical purposes.
The “BUY” and “SELL” labels indicate such technical configurations:
– ECDF < 0.2 with price returning above the lower channels → bullish reentry.
– ECDF > 0.9 with price returning below the upper channels → bearish reentry.
The parameters (channel periods, ECDF window, smoothing) allow you to fine-tune the sensitivity of the analysis according to instrument volatility or chosen timeframe.

🟩 Buy Signal (BUY)
A buy signal is triggered when a strong downside deviation pushes the price below both channels, followed by a gradual reentry inside the bands.
More precisely:
– The low is below both channels (low < scb and low < mcb).
– The ECDF crosses back above 0.19 (exit from oversold).
– Both events occur within the last six bars.
– The price moves back above the lower channel (high > scb).
– No previous long signal is active.
This configuration represents a statistical reentry to the mean after an excessive drop.

🟥 Sell Signal (SELL)
Conversely, a sell signal appears when a strong upside deviation pushes the price above both channels, followed by a pullback below them:
– The high exceeds both channels (high > sct and high > mct).
– The ECDF crosses below 0.9 (exit from overbought).
– Both events occur within the last six bars.
– The price falls back below the upper channel (low < sct).
– No previous short signal is active.
This reflects a bearish reentry following a statistical overextension.

⚙️ Operating Logic
Each signal is triggered only once per cycle thanks to the variables triggered_long and triggered_short, preventing duplicates until a new extreme occurs.
The tool is designed for visual analysis and pattern research, not for automated execution.

🔍 ECDF Principle and Calculation
The ECDF is a non-parametric measure of a value’s position within its recent distribution:
ECDF(X)=number of values ≤XNECDF(X) = \frac{\text{number of values } \le X}{N}ECDF(X)=Nnumber of values ≤X​
It expresses the empirical proportion of observations below the current value.
Example:
If, among the last 100 observations, 85 are below the current price, then
ECDF=0.85ECDF = 0.85ECDF=0.85
→ The price is at the 85th percentile, statistically high relative to recent history.
Strengths: robust, model-free, well-suited to asymmetric or non-normal market regimes.
Limitations: it does not measure amplitude and depends on the selected window size.

🌊 Intuitive Analogy: The River and the Gauge
Imagine a river with a depth gauge:
– The Z-Score tells you how many meters above the average level the water currently stands.
– The ECDF tells you in how many past cases the water level was lower than it is now.
The Z-Score assumes the river always follows the same symmetrical pattern.
The ECDF simply observes reality — adapting naturally, even when the current becomes unpredictable.

Final note:
This indicator is designed for visual and statistical exploration of price behavior.
The signals represent statistical states, not trade instructions.
Entering long or short positions based on them is entirely at your own discretion and risk.
Информация о релизе
This indicator enhances the previous “Dual-Channel + ECDF Reentry” model by introducing Hurst-adaptive channel lengths.
Instead of using fixed lookback periods, the short and medium channels now dynamically expand or contract according to a real-time estimate of the Hurst exponent, a measure of the market’s fractal persistence.

When the market becomes chaotic or mean-reverting (H near 0), the channels shorten to react more quickly to price reversals.
When the market shows persistent, trending behavior (H near 1), the channels lengthen to smooth out noise and highlight structural moves.
This adaptive behavior allows the indicator to “breathe” with market volatility and regime changes without requiring manual retuning.

It combines two complementary quantitative concepts:
– Hurst-type adaptive channels, built from smoothed moving averages and ATR offsets, whose periods vary continuously based on the fractal structure of price.
– Empirical Cumulative Distribution Function (ECDF) analysis, which measures the current price position within its recent statistical range (0 = local minimum, 1 = local maximum).

The goal is to detect statistical overextensions and reentries toward equilibrium:
zones where price temporarily escapes its adaptive envelope, then reverts toward the mean with measurable probability.

This indicator does not produce trading advice or signals to execute directly.
It identifies statistical conditions of imbalance and reversion for research, discretionary study, or further model development.

Adaptive Structure and Logic

Hurst Estimation
The script implements a rescaled-range (R/S) proxy to compute the local Hurst exponent over a configurable window.
The exponent is smoothed with an EMA and normalized between 0 and 1, then linearly interpolated between user-defined minimum and maximum channel lengths.
This process continuously adjusts the channel sensitivity according to evolving market roughness.

Channel Computation
Adaptive short- and medium-term averages are updated with recursive formulas, ensuring responsiveness and computational efficiency.
ATR-based offsets (multiplied by user-defined coefficients) create upper and lower envelopes that adapt dynamically to volatility and fractal state.

ECDF Logic and Signals
The ECDF evaluates the statistical rank of the current price within a sliding window.
– ECDF < 0.2 and price reentering from below → potential bullish reentry (BUY).
– ECDF > 0.9 and price reentering from above → potential bearish reentry (SELL).
Only one signal is issued per phase thanks to internal memory variables that prevent repetition until a new extreme occurs.

Summary of Improvements

– Replaced static channel periods with Hurst-driven adaptive lengths.
– Added Hurst smoothing and sensitivity scaling for stability and customization.
– Improved responsiveness during ranging vs. trending regimes.
– Retained ECDF-based contrarian logic for consistent statistical interpretation.
– Included optional debug plot of Hurst value to visualize the adaptive behavior in real time.

Отказ от ответственности

Все виды контента, которые вы можете увидеть на TradingView, не являются финансовыми, инвестиционными, торговыми или любыми другими рекомендациями. Мы не предоставляем советы по покупке и продаже активов. Подробнее — в Условиях использования TradingView.