OPEN-SOURCE SCRIPT
Telah dikemas kini

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

487
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.
Nota Keluaran
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.
Nota Keluaran
The new version marks a complete evolution of the model — transforming it from a simple statistical re-entry detector into a hybrid adaptive quantitative system, blending fractal analysis, probabilistic learning, pivot forecasting, and dynamic scenario visualization.
Here’s a clear thesis–antithesis–synthesis breakdown of what changed.

Thesis: The old model

The first version was minimalist, deterministic, and purely signal-based.
It included:

A basic Hurst adaptive structure: two channels (short and medium) whose lengths adjusted to the Hurst exponent.

A linear ECDF (empirical cumulative distribution) to locate price within its recent range.

Binary logic: ECDF < 0.2 → “BUY”, ECDF > 0.9 → “SELL”.

A simple memory system to avoid duplicate signals.

Static plots with a basic visual layout.

Essentially, it was a clean prototype, useful for identifying mean-reversion zones, but lacking context awareness or probabilistic weighting.

Antithesis: The new model

The second version introduces a modular and intelligent architecture, turning the indicator into an adaptive decision engine.
The upgrades fall into six key areas:

1. Enhanced fractal adaptation

The Hurst logic is now fully self-adjusting with parameters like hurst_sensitivity, hurst_smooth_len, and adaptive min/max bounds.

Channel lengths recalibrate dynamically according to market persistence (more reactive when H < 0.5, slower when H > 0.5).

Multi-scale adaptation is achieved through the medium_ratio parameter.

2. Pivot forecasting engine

A new calc_pivot_forecast() function estimates average pivot intervals and predicts the expected time until the next one.

Independent short-term and medium-term forecasts merge into an adaptive radar.

Visual markers: circles for anticipated pivots, diamonds for confirmed ones.

A configurable “forecast window” shows potential reversal zones before they occur.

3. Probabilistic modeling + adaptive learning

A logistic regression model now drives pivot probability:

𝑃(up)=1+𝑒−(𝛽0+𝛽1𝐸𝐶𝐷𝐹+𝛽2𝐻+𝛽3Δ𝐻+𝛽4Δ𝑡)

Each term has a distinct quantitative meaning:

β₀ (Intercept):
The baseline bias of the model — it shifts the whole probability curve up or down, acting as a neutral prior when no signal is active.

β₁ · ECDF (Empirical Cumulative Distribution Function):
Measures where the current price sits within its recent range (0 = local low, 1 = local high).
When β₁ < 0, low ECDF values (oversold) increase P(up) — a mean-reversion component.

β₂ · H (Hurst Exponent):
Captures the market’s fractal persistence.
H > 0.5 indicates trend persistence (momentum), H < 0.5 indicates anti-persistence (mean reversion).
β₂ adjusts the influence of trending vs. reverting regimes.

β₃ · ΔH (Change in Hurst):
Detects transitions between regimes — when the market switches from persistent to anti-persistent behavior or vice versa.
Positive ΔH means increasing trend structure; negative ΔH signals growing randomness or potential reversals.

β₄ · Δt (Normalized time since last pivot):
Represents the temporal phase of the cycle — how long it has been since the last confirmed pivot relative to the average pivot interval.
High Δt means the current move is aging; the likelihood of reversal grows as Δt → 1.

The sum 𝑧=𝛽0+𝛽1𝐸CDF+𝛽2𝐻+𝛽3Δ𝐻+𝛽4Δ𝑡 is then passed through a logistic activation:​

The β-coefficients are learned online through a dual-memory system:

A fast learner adapts quickly (high learning rate with decay).

A slow learner smooths and stabilizes results over time.

A blend factor λ fuses both to balance adaptability and stability.

The model updates after every bar using the realized return, meaning it “learns” from recent price behavior.

4. I added dynamic scenario visualization (adaptive TP/SL) (but need optimisation)

A new Scenario Mode automatically draws take-profit and stop-loss levels from recent pivots.

Levels adjust according to both volatility (ATR) and Hurst fractality.

Works in ATR multiplier or percentage mode, with optional auto-clearing after N bars.

A full set of visual elements (lines, labels, and arrays) ensures each setup is self-contained and auto-reset.

5. Implied volatility integration (VIX/BVIV)

The indicator now fetches external implied volatility indices (VOLMEX:BVIV or CBOE:VIX).

Normalized via Z-score, these form volatility-weighted support/resistance bands, aligning the fractal geometry with the market’s implied risk environment.

6. HUD interface & emotion filter (i need to improve too)

A clean on-chart HUD displays:

Smoothed Hurst exponent,

ECDF percentile,

P(up) probability,

Last pivot direction,

A live “confidence bar.”

The emotion filter desaturates visuals and disables labels for analytical focus.

A confidence ribbon tints the chart background based on statistical strength.

Synthesis: The big picture

This update transforms the indicator from a static stochastic tool into a probabilistic, self-learning market observer.
It shifts from:

Single-variable logic → multi-factor probabilistic reasoning (Hurst, ECDF, variance, skewness, autocorrelation).

Local signals → context-aware cycle forecasting.

Visual simplicity → structured quantitative dashboard.

In essence, the model no longer says “price is too low or too high.”
It now estimates “the probability of a reversal or continuation given current fractal geometry, memory state, and implied volatility.”
Nota Keluaran
Recalibrate image description
Nota Keluaran
The HUD (Heads-Up Display) has been upgraded to include contextual explanations for each core metric — giving traders not just raw numerical values, but qualitative interpretations of the current market state.

This turns the HUD into a more intuitive decision panel a quick, readable snapshot of both data and meaning.

New logic and descriptions:

my own Hurst:
Displays the raw Hurst exponent (e.g., 0.8) and interprets it as
- Range (H < 0.4): Mean-reverting phase
- Mixed (0.4 ≤ H ≤ 0.6): Transitional structure
- Trend (H > 0.6): Persistent trending regime

My own ECDF:
Shows where price currently sits in its statistical range and labels it as :
- Oversold (ECDF < 0.2)
- Neutral (0.2 ≤ ECDF ≤ 0.8)
- Overbought (ECDF > 0.8)

P(up):
Displays the model’s probabilistic bias:
- Bearish bias (P < 0.45)
- Equilibrium (0.45 ≤ P ≤ 0.55)
- Bullish bias (P > 0.55)

Last Pivot:
Adds context on the most recent confirmed pivot:

Low → Upward phase forecast
High → Downward phase forecast
None → No active pivot

I added
int bars_since_low = ta.barssince(pivot_low_confirm) // number of bars since last confirmed low pivot
int bars_since_high = ta.barssince(pivot_high_confirm) // number of bars since last confirmed high pivot

Which give an information about time.

We can now combinate this indicatopr to the market profile
Nota Keluaran
This indicator is an experimental quantitative hallucination, not a trading system but it wasn’t built for nothing. It’s a sandbox of curiosity, where probability, fractal noise, and pseudo-learning collide just to remind us how fragile “quant reasoning” becomes once it leaves the lab. It looks brilliant on the surface
— logistic regressions, Hurst exponents, adaptive feedback loops
But under scrutiny it’s nothing more than numerical theater: complexity pretending to be insight. The 20+ adjustable knobs don’t create "intelligence"; It’s dangerous because it flatters your intellect while quietly inflating your delusion. Use it as a philosophical exercise like fibonnaci numbers or astral signals, not as a trading tool.
And let’s be absolutely clear: this thing is garbage in practical terms. It predicts nothing, proves nothing, and explains nothing. It’s a chaos generator dressed in quantitative drag. It won’t make you rich, it won’t make you smarter, and it certainly won’t make the market care. It’s the quant equivalent of talking to yourself in a mirror satisfying atin own nonsense.

Penafian

Maklumat dan penerbitan adalah tidak dimaksudkan untuk menjadi, dan tidak membentuk, nasihat untuk kewangan, pelaburan, perdagangan dan jenis-jenis lain atau cadangan yang dibekalkan atau disahkan oleh TradingView. Baca dengan lebih lanjut di Terma Penggunaan.