Indicator · Pine Script v6 · Own pane

Hurst Exponent (HURST)

by mihakralj

Calculates and plots the Hurst Exponent to quantify the persistence, mean-reverting tendencies, or random walk characteristics of a time series.

View on GitHub

GitHub stars99on the repository
Pine versionv6current
Lines of code86
Settings2inputs
LicenceApache-2.0
Last update4 weeks ago27 Sep 2026

Add It to Your TradingView Chart

  1. 1Copy the scriptPress Copy script above, or the copy button on the code below.
  2. 2Open the Pine EditorOpen a TradingView chart and choose Pine Editor at the bottom of the screen.
  3. 3Paste over the templateCreate a new indicator, select all of the template text and paste. Press Save and give it a name.
  4. 4Add it to the chartPress Add to chart, then adjust the settings with the gear icon next to its name.

Source Code

86 lines of Pine Script v6 from lib/statistics/hurst/hurst.pine, published under Apache-2.0. Keep the author's credit and licence lines when you reuse it.

hurst.pine
// Licensed under the Apache License, Version 2.0
// © mihakralj
//@version=6
indicator("Hurst Exponent (HURST)", "HURST", overlay=false, precision=4)

//@function Calculates the Hurst Exponent for a given series and lookback period.
//@param source series float The input series.
//@param length int The lookback period for Hurst Exponent calculation.
//@returns series float The Hurst Exponent value.
hurst(series float source, simple int length) =>
    if length <= 10 
        runtime.error("Length must be greater than 10 for Hurst Exponent.")
        na
    log_returns = math.log(source / source[1])
    min_n = 10
    max_n = length / 2
    if max_n < min_n
        runtime.error("Length too short for sub-period division.")
        na
    array<float> log_n_values = array.new_float(0)
    array<float> log_rs_values = array.new_float(0)
    for n = min_n to max_n
        if n == 0
            continue
        num_sub_periods = math.floor(length / n)
        if num_sub_periods == 0
            continue
        rs_sum = 0.0
        for i = 0 to num_sub_periods - 1
            start_index = i * n
            float[] sub_period_returns = array.new_float(n)
            for j = 0 to n - 1
                array.set(sub_period_returns, j, log_returns[start_index + j])
            sub_period_sum = 0.0
            for k_val = 0 to n - 1
                sub_period_sum += array.get(sub_period_returns, k_val)
            sub_mean = sub_period_sum / n
            float[] cum_dev = array.new_float(n)
            current_sum = 0.0
            for j = 0 to n - 1
                current_sum += (array.get(sub_period_returns, j) - sub_mean)
                array.set(cum_dev, j, current_sum)
            range_val = array.max(cum_dev) - array.min(cum_dev)
            variance_sum = 0.0
            for j = 0 to n - 1
                variance_sum += math.pow(array.get(sub_period_returns, j) - sub_mean, 2)
            std_dev_val_corrected = math.sqrt(variance_sum / n)
            if std_dev_val_corrected > 0
                rs_sum += range_val / std_dev_val_corrected
        if num_sub_periods > 0
            avg_rs = rs_sum / num_sub_periods
            if avg_rs > 0 
                array.push(log_n_values, math.log(n))
                array.push(log_rs_values, math.log(avg_rs))
    if array.size(log_n_values) < 2 
        na
    else
        m = array.size(log_n_values)
        sum_x = 0.0
        sum_y = 0.0
        sum_xy = 0.0
        sum_x_sq = 0.0
        for i = 0 to m - 1
            xi = array.get(log_n_values, i)
            yi = array.get(log_rs_values, i)
            sum_x += xi
            sum_y += yi
            sum_xy += xi * yi
            sum_x_sq += xi * xi
        denominator = m * sum_x_sq - math.pow(sum_x, 2)
        if denominator == 0
            na 
        else
            (m * sum_xy - sum_x * sum_y) / denominator

// ---------- Main loop ----------

// Inputs
i_source = input.source(close, "Source")
i_length = input.int(100, "Length", minval=20, tooltip="Lookback period for Hurst Exponent calculation. Min 20.")

// Calculation
hurstValue = hurst(i_source, i_length)

// Plot
plot(hurstValue, "Hurst Exponent", color=color.yellow, linewidth=2)

Overview

Hurst Exponent (HURST) computes logarithmic returns, segments the lookback window into sub-periods to determine rescaled range statistics, and calculates the linear regression slope in log-log space. Configurable inputs include the price source and lookback length (minimum 20). The indicator renders a line in a separate pane and provides statistical measurements without trading signals.

Details

Published by

mihakralj on GitHub

Type

Indicator, Pine Script v6

Draws

Separate pane below the chart

Category

Trend, Mean reversion

Markets

Any symbol

Timeframes

Any timeframe

Risk Notes

No repainting, lookahead or stacked entries were found in its code or README. That says nothing about how well it works: test it first.

Topics

algorithmic-tradingcsharpdotnetpinescriptpythonquantitative-financesimdta-libtechnical-analysistechnical-indicators

Settings

The inputs you can change from the gear icon on the chart. Defaults are the author's.

SettingTypeDefaultVariable
Sourcesourceclosei_source
Lengthint100i_length
Third-party code. ForexR did not write, test or endorse this script, and the summary above was generated automatically from its code and README. Indicators describe the past, and a strategy's backtest can look better than live trading, especially when a script repaints. Check it in the Strategy Tester and on a demo account before you rely on it.

Similar Pine Scripts

AutoCorrelation Function

by Anderson-ALGO
9 stars

This indicator calculates sample autocorrelation across multiple lag intervals for a selected price series. It computes correlation values over a user-specified lookback period using raw prices, log returns, absolute log returns, or squared log returns. Plotte

Indicator v4 TrendMean reversion
Updated 5 years ago · None stated GitHub repository of AutoCorrelation Function

Calculates a composite carry and decay oscillator fusing impulse-autocorrelation half-life, a Hurst exponent approximation, path efficiency, and range expansion ratios. It evaluates whether an impulse is likely to persist or mean-revert, plotting the oscillato

Indicator v6 TrendOscillators & momentum
Updated yesterday · MIT GitHub repository of Market Memory & Decay Oscillator [WavesUnchained]

MACD x RSI Study

by jerryinyang
5 stars

This indicator combines MACD and RSI to generate pullback signals on forex pairs. It plots MACD line, signal line and histogram alongside RSI and Wave Trend oscillator. Higher-timeframe MACD provides trend bias while RSI identifies overbought and oversold zone

Indicator v4 Oscillators & momentumMoving averages
Updated 2 years ago · None stated GitHub repository of MACD x RSI Study
2 stars

Rolling Z-Score Trend [QuantAlgo] calculates a rolling Z-score using mean and standard deviation over a user-defined lookback window to evaluate statistical price deviations and momentum. Plotted in a separate indicator pane, it displays the rolling Z-score li

Indicator v6 TrendOscillators & momentum
Updated 8 months ago · None stated GitHub repository of Rolling Z-Score Trend [QuantAlgo]
1 stars

This indicator tracks Tom DeMark TD Sequential setup counts in a separate pane. It compares the current close to the close four bars earlier, accumulating positive counts during upward momentum and negative counts during downward momentum. The values display a

Indicator v5 TrendMean reversion
Updated 1 year ago · None stated GitHub repository of TD Sequential Number
257 stars

This indicator plots auto trade signals for E-mini S&P 500 futures on the price chart. It computes an EMA200 filter along with day ETH RTH session levels and percentage-based entry zones. Signals trigger CALL or PUT cases when price crosses defined thresholds

Indicator v6 TrendSupport & resistance
Updated 6 weeks ago · None stated GitHub repository of Auto Trade Futures ES

More indicators

Trade Your Charts With a Regulated Broker

Compare brokers that connect to TradingView, with spreads, minimum deposits and leverage side by side.

Compare brokers