Indicator · Pine Script v4 · Own pane

Simple Hurst Exponent

by Anderson-ALGO· code credited to balipour

This indicator estimates a simple Hurst exponent from the length of the scaled price path over a user-set lookback and plots it in a separate pane.

View on GitHub

GitHub stars9on the repository
Pine versionv4older, still runs
Lines of code58
Settings6inputs
LicenceNone statedfile: MPL-2.0
Last update5 years ago30 Nov 2020

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

58 lines of Pine Script v4 from Pine/Pine Wizards/Balipur/Hurst Exponent (Simple).pine, published under MPL-2.0 (file header). Keep the author's credit and licence lines when you reuse it.

Hurst Exponent (Simple).pine
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © balipour

//@version=4
study("Simple Hurst Exponent [pig]", "BA🐷 HE(S)", false, format.inherit, precision=3, resolution = "")

//Background Color
bgcolor(#000000c0)

//Functions
ss(Series, Period) => // Super Smoother Function
    var PI    = 2.0 * asin(1.0)
    var SQRT2 = sqrt(2.0)
    lambda = PI * SQRT2 / Period
    a1     = exp(-lambda)
    coeff2 = 2.0 * a1 * cos(lambda)
    coeff3 = - pow(a1, 2.0)
    coeff1 = 1.0 - coeff2 - coeff3
    filt1  = 0.0
    filt1 := coeff1 * (Series + nz(Series[1])) * 0.5 + coeff2 * nz(filt1[1]) + coeff3 * nz(filt1[2])
    filt1

//Settings
y     = input(close,           "===== Source =====", input.source)
N     = input(   30,                     "Lookback", input.integer, minval = 2, step = 2)
lower = input(   10,        "Super Smoother Period", input.float,   minval = 2, step = 0.5)
sh    = input( true,          "Show Hurst Exponent", input.bool)
sm    = input( true, "Show Smoothed Hurst Exponent", input.bool)
lT    = input(    2,       "--- Line Thickness ---", input.integer, options=[1,2,3])
  
//Hurst Exponent Calculation
ymin =  lowest(y, N)
ymax = highest(y, N)
yscl = ymax - ymin

lngth = 0.0
if (N < 2 or ymax == ymin)
    lngth := 1.0
else
    lngth := 0.0
    dx2 = 1.0 / (N * N)
    for j = 1 to N
        dy = (nz(y[j]) - nz(y[j - 1])) / yscl
        lngth := lngth + sqrt(dx2 + (dy * dy))

var LOG2 = log(2.0)
FDI   = 1.0 + (log(lngth) + LOG2) / log(2.0 * N)
Hurst = 2.0 - FDI
filt1 = ss(Hurst, lower)

//Colors
c  = Hurst > 0.5 ?  color.aqua   : #FF0080ff
c2 = filt1 > 0.5 ?  color.orange : color.lime

//Plot
plot(sh ? Hurst : na, "Hurst Exponent", c , transp=0, linewidth=lT)
plot(sm ? filt1 : na,             "ma", c2, transp=0, linewidth=lT)
hline(0.5, "threshold", color.white, hline.style_dotted)

Overview

A value above 0.5 is colored differently from a value below 0.5, with a dotted horizontal line at 0.5. An optional super smoother plots a filtered version of the same series. The source, lookback, smoother period, line thickness, and visibility of each line are adjustable. It does not generate trade entries or exits.

Details

Published by

Anderson-ALGO on GitHub

Code credit

balipour, as written in the script's header

Type

Indicator, Pine Script v4

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.

Settings

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

SettingTypeDefaultVariable
===== Source =====sourceclosey
Lookbackint30N
Super Smoother Periodfloat10lower
Show Hurst Exponentbooltruesh
Show Smoothed Hurst Exponentbooltruesm
--- Line Thickness ---int2lT
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

99 stars

The Augmented Dickey-Fuller indicator calculates statistical stationarity and tests for unit roots in price series over a rolling window. It performs ordinary least squares regression on differenced historical price data to compute a t-statistic and an estimat

Indicator v6 Mean reversionTrend
Updated 4 weeks ago · Apache-2.0 GitHub repository of ADF - Augmented Dickey-Fuller Test

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]
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

Peak Reversal v3

by Zettt
43 stars

Peak Reversal v3 identifies potential mean-reversion points by plotting configurable Keltner Channels alongside a squeeze detector directly on the price chart. It detects momentum extremes when candles cross or trade completely outside the inner or outer chann

Indicator v6 Mean reversionVolatility & bands
Updated 1 year ago · None stated GitHub repository of Peak Reversal v3
6 stars

This indicator classifies price action into four distinct market regimes: Trend, Expansion, Compression, or Mean Reversion. It determines states using a simplified Hurst exponent estimate, ADX slope thresholds, and realized volatility measurements. Based on th

Indicator v6 TrendVolatility & bands
Updated 8 weeks ago · MIT GitHub repository of Capital41 Regime Matrix v3

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