TradingView statistical indicator guide

Hurst exponent indicator: estimation and sample-size limits

A Hurst exponent indicator estimates how fluctuations scale across observation lengths. Under a suitable stationary-increment model, H above 0.5 suggests persistence and H below 0.5 suggests anti-persistence. A finite-window reading does not establish either property. The estimator, input series and sample length determine its bias and uncertainty; a displayed 0.62 can be ordinary sampling variation under independent returns.

See the decision guide

Scripts with the same name can estimate different quantities

TradingView search results include multi-scale R/S implementations, single-scale approximations and detrended fluctuation analysis. QuantNomad describes dividing a lookback into shorter samples for R/S analysis; RC Tools explicitly describes a single-scale approximation. Their numbers need not match. Record the author and version before comparing settings or colors.

  • Weron compares R/S, DFA and periodogram methods using Gaussian white noise and finds finite-sample behavior matters. Do not transfer a published interval to a different algorithm.
  • The Fractal Dimension Index describes path roughness under its own estimator. D = 2 − H requires a suitable self-affine model; it is not an unconditional conversion between two TradingView indicators.
MethodCalculationLimit to check
Multi-scale R/SRegress log mean rescaled range on log block length.Small blocks and a short sample can bias the slope.
Single-scale approximationInfer H from one R/S value and an assumed scaling constant.One point cannot estimate both the slope and intercept.
Corrected R/SAdjust for the expected finite-sample R/S behavior under a reference model.State the correction, variance divisor and fitted scales.
DFAFit scaling of fluctuations after removing a polynomial trend from an integrated profile.Detrending order and stationary versus integrated input affect interpretation.
Lo modified R/S testAdjust the normalization for short-range dependence.This is a memory test with a lag choice, not a drop-in H slope estimate.

Define a reproducible R/S estimator

For this example, x is a sequence of N log returns, oldest first: x[t] = ln(close[t] / close[t−1]). N returns require N + 1 positive closes. Use N = 128, 256 or 512 and non-overlapping blocks of length n = 8, 16, 32, continuing by powers of two up to N/4. Each scale therefore has at least four blocks. These are explicit demonstration settings, not recommended trading parameters.

  • This definition uses divisor n, no finite-sample correction, no smoothing and no clipping to 0..1. It takes the log after averaging R/S, rather than averaging log R/S.
  • If any required block has S = 0, this example returns undefined for the window. Missing observations or nonpositive closes also invalidate it. Do not replace undefined output with zero or the previous classification.
  • Raw price levels, absolute returns and signed returns answer different questions. A persistent volatility series does not establish persistence in return direction.
StepDefinition
Center each blockd[i] = x[i] − mean(x) within that block.
AccumulateY[0] = 0; Y[k] = Σ d[i] through k.
RescaleR = max(Y) − min(Y); S = sqrt(Σ d[i]² / n); Q = R/S.
Average at each scaleA(n) = arithmetic mean of Q across all blocks of length n.
Estimate HOrdinary least-squares slope of ln A(n) against ln n, including an intercept.

Check the arithmetic before a long-window estimate

Two hypothetical four-return blocks show what R/S measures. Express returns in arbitrary common units: multiplying all observations by the same positive constant cancels between R and S. These tiny blocks verify arithmetic only; they do not estimate long-range dependence.

  • Both blocks have mean zero and the same variance. Their ordering changes the cumulative range.
  • Repeat 1, −1 for 128 observations. Every fitted even-length block has R/S = 1, so ln A(n) = 0 and the fitted slope is exactly zero. This deterministic alternating fixture is not evidence about a market.
  • A constant-return sequence has S = 0 even when its price path rises. A visually smooth price trend can therefore be undefined under this return-based estimator.
Input blockCumulative deviations, including zeroRSR/S
1, −1, 1, −10, 1, 0, 1, 0111
1, 1, −1, −10, 1, 2, 1, 0212

Compare estimation ranges for three sample lengths

The table is a computed simulation, not a market backtest or a table copied from a paper. For each N, generate 5,000 independent sequences of N standard-normal observations and apply exactly the uncorrected estimator above. The null model has independent returns and H = 0.5. Use Python random.Random with seed 20261017 + N. Sort the estimates and select ranks 125 and 4,875, counting from one, for approximate central 95% reference bounds.

  • All three medians exceed 0.5 despite independent simulated observations. A fixed 0.5 color boundary would mistake finite-sample behavior for evidence of persistence.
  • The reference range narrows here as N increases, but the fitted scale set also changes. These results do not isolate sample length from scale selection and are not universal bands.
  • These bounds describe variation of the estimator under a specified null. They are not a 95% confidence interval for the unknown H of an observed market, nor a 95% probability that its true H lies between the bounds.
  • Real returns can have heavy tails, volatility clustering, short-memory dependence and structural breaks. Each can invalidate this independent-Gaussian calibration. Longer windows may also mix different regimes.
Returns NBlock lengths nMedian estimateCentral 95% null reference range
1288, 16, 320.60240.4427 to 0.7593
2568, 16, 32, 640.58820.4751 to 0.6944
5128, 16, 32, 64, 1280.57610.4970 to 0.6571

Test persistence and reversal claims separately

Preselect the estimator, window, scales and significance level. For the narrow null used above, reject in the upper or lower 2.5% tail of the matching simulated distribution. A hypothetical H estimate of 0.62 lies inside every displayed range, so none rejects this null at the two-sided 5% level. Failing to reject does not prove independence.

  • For an explicit two-sided Monte Carlo tail calculation, use p = min(1, 2 × min[(1 + count(Hsim ≤ Hobs))/5001, (1 + count(Hsim ≥ Hobs))/5001]). At Hobs = 0.62 the simulated p-values are 0.8190, 0.5811 and 0.2827 for N = 128, 256 and 512.
  • Lo introduced a modified R/S test to address short-range dependence. A stronger memory analysis should state an appropriate short-memory null and calibration, rather than treating every rejection of independence as long memory.
  • For a mean-reverting price hypothesis, separately test stationarity around the proposed level or spread, stability across periods and the proposed reversion horizon. Anti-persistence alone supplies none of these.
  • Rolling windows overlap. Three lengths, multiple symbols and repeated daily tests create multiple comparisons, not independent confirmations. Predeclare the tests, adjust inference and evaluate the rule on held-out data.
HypothesisWhat a result supportsWhat it does not establish
Upper-tail estimateIncompatibility with this particular independent-return calibration.Long-range memory rather than short correlation, breaks or a different distribution.
Lower-tail estimateUnusually low scaling for this particular null and estimator.Price stationarity, a stable mean, a reversion horizon or profitable reversal trades.
Estimate inside boundsInsufficient evidence against this null from this statistic.Proof that the process is random or has no tradeable structure.

Reproduce the simulation with Python

Run this standalone Python 3 example to regenerate the reference ranges. It uses only the standard library. Keep the return generation, block scales, variance divisor and regression definition unchanged when comparing the table; use a separate calibration when any of them changes.

Independent Gaussian calibration for the stated estimator; no market data or trading signals.python
import math
import random
import statistics


def rs(block):
    mean = statistics.mean(block)
    deviations = [v - mean for v in block]
    sd = math.sqrt(sum(v * v for v in deviations) / len(block))
    if sd == 0:
        raise ValueError('Constant block: R/S is undefined')
    total, path = 0.0, [0.0]
    for v in deviations:
        total += v
        path.append(total)
    return (max(path) - min(path)) / sd


def estimate(values):
    n = len(values)
    if n not in (128, 256, 512) or not all(map(math.isfinite, values)):
        raise ValueError('Use 128, 256 or 512 finite observations')
    scales = [2 ** k for k in range(3, int(math.log2(n)) - 1)]
    x, y = [], []
    for size in scales:
        ratios = [rs(values[j:j + size]) for j in range(0, n, size)]
        x.append(math.log(size))
        y.append(math.log(statistics.mean(ratios)))
    xm, ym = statistics.mean(x), statistics.mean(y)
    return sum((a-xm)*(b-ym) for a, b in zip(x, y)) / sum((a-xm)**2 for a in x)


def simulate(n):
    rng = random.Random(20261017 + n)
    estimates = sorted(estimate([rng.gauss(0, 1) for _ in range(n)]) for _ in range(5000))
    return {'N': n, 'lower': estimates[124], 'median': statistics.median(estimates), 'upper': estimates[4874], 'p_H_062': min(1, 2 * min((1 + sum(h <= .62 for h in estimates))/5001, (1 + sum(h >= .62 for h in estimates))/5001))}


for n in (128, 256, 512):
    print(simulate(n))

Verify the TradingView implementation before alerts

Save the symbol, exchange feed, session, chart type, timeframe and source alongside the algorithm. Match the individual block means, R/S values, averaged A(n) and regression slope against an independent calculation. Compare completed bars first; an open candle changes its return and can move the estimate across a boundary.

  • Require N + 1 valid positive closes before the first estimate. Use only current and past observations, preserve chronological block ordering and recalculate each rolling window without a recursive seed.
  • For a hypothetical upper-tail alert, use the full-precision, pre-calibrated upper bound for that exact N. Require a valid previous estimate at or below the bound and a valid current estimate strictly above it on a confirmed chart bar. Suppress alerts for invalid windows.
  • A confirmed chart bar does not settle an unfinished higher-timeframe input. Audit higher-timeframe requests separately. This example uses chart-timeframe closes only.
  • Pineify can draft Pine Script from the written estimator specification. Include the arithmetic fixtures, initialization, undefined states and close-only condition in the request. Check numerical parity in TradingView before generating alerts; syntax validation does not validate the statistical model.
  • Use a public algorithm or code you have permission to use. This process does not recover protected source, choose a trade direction or demonstrate profitability.
Where Pineify fits

Pine Script AI Coding Agent

Turn a specified Hurst estimator and its verification fixtures into a Pine Script draft, then compare calculations and confirmed-bar behavior in TradingView.

Draft the specified estimator

Frequently asked questions

Educational statistical examples, not investment advice. Numerical fixtures and simulations use hypothetical data. No market performance has been tested; estimated persistence and statistical significance do not guarantee trading returns.

Sources and verification

Published by Pineify. Pineify is an independent product and is not affiliated with TradingView. Sources support the technical explanations; examples do not establish trading performance.