Hurst Exponent And Fractal Measures
A single ADF test or a moving-average slope answers "is there a trend right now" with a yes/no for one lookback window. The Hurst exponent asks a broader structural question: across many window sizes at once, does the series' range grow faster than a random walk's own range would (H > 0.5, persistent - a trend that tends to continue), slower (H < 0.5, anti- persistent - a move that tends to reverse), or exactly like a random walk's (H = 0.5, no exploitable structure of this kind)? Because the exponent is fit across a whole spread of window sizes rather than measured once at a single lookback, it is far less sensitive to the specific window an author happened to pick than a single-window statistic is. Two independent estimators are included rather than one. HurstRescaledRange is Hurst's original 1951 R/S method: split the series into windows, compute the range of the cumulative mean-centred sum divided by the window's standard deviation for each, average across windows, and repeat at several window sizes - the slope of log(R/S) against log(window size) is the Hurst exponent by construction. HurstDfa is detrended fluctuation analysis (Peng et al. 1994): integrate the mean-centred series into a random-walk-like profile, then at each of several box sizes fit a local linear trend inside every box and measure the RMS residual after removing it. DFA handles a series with a slowly drifting local mean more robustly than plain R/S, precisely because each box removes its own local trend before measuring fluctuation rather than assuming the whole series is stationary. Running both and comparing them is itself informative - agreement is corroborating evidence, and a meaningful disagreement is a signal the series has structure neither method captures cleanly on its own. HurstInterpret buckets a raw Hurst value into HURST_MEAN_REVERTING, HURST_RANDOM_WALK or HURST_TRENDING using an adjustable neutral band around 0.5, because a finite sample essentially never lands on exactly 0.5 even when the underlying process genuinely has no structure - treating a narrow band around 0.5 as "no detectable signal" avoids reading trading significance into ordinary sampling noise. Notes and limitations - Both estimators need a reasonable amount of data to fit multiple window sizes meaningfully - under a few hundred observations, expect the estimate to be noisy and to swing between runs. Both functions fall back to a neutral 0.5 if there is not enough data to fit at least two window sizes at all. - The Hurst exponent describes a statistical property of the WHOLE window passed in, not a per-bar signal. Recompute it on a fresh rolling window rather than expecting a bar-by-bar value. - Trending in the Hurst sense (H > 0.5, ranges grow faster than a random walk's) is not the same claim as "price is currently going up" - a series can be persistent while falling just as easily as while rising. Combine with a directional indicator if you need direction, not just persistence. - This is a diagnostic tool, not a trading signal generator on its own. It places no trades and issues no buy/sell decision.
Script · MT5 · v1.0 · Free
About Hurst Exponent And Fractal Measures
Hurst Exponent And Fractal Measures is a script for MetaTrader 5. It has 2 settings, such as Series length and Live price bars. MQL source code included.
Files in the download: HurstExponent.mq5.mqh, HurstExponent.txt, HurstExponentDemo.ex5, HurstExponentDemo.mq5.
Settings
| Setting | Default | What it does |
|---|---|---|
| Series length | 512 | Bars in each synthetic test series |
| Live price bars | 400 | Bars of live returns analysed in the final test |
How to install
- Download the ZIP from your PolyMaria library and unzip it.
- In MetaTrader 5 open File → Open Data Folder, then go to MQL5 → Scripts.
- Copy the .mq5 file(s) there. Put any .mqh files in MQL5 → Include.
- Open the .mq5 file in MetaEditor and press Compile (F7) if MetaTrader does not show it.
- Drag the script onto a chart to run it once.
Tags: Fractals · Trend · MT5 Script · MQL5 Source Code