#### sniktau

##### New member

Hello forum members,

I am happy to release the first pass at a simple, local approximation of the Hurst exponent. This is a work in progress and this post is already taking up too much of my lunch hour.

The equation from Wikipedia is as follows:

Hurst used the following equation for the Nile. He found it to be ~0.73 for that river.

Mandelbrot suggests the following for

(LaTeX because it was a pain to write: \frac{R( n)}{S( n)} = \frac {\max\limits_{1 \leq k \leq n} \sum\limits_{j=1}^k (r_j - \bar{r_n}) - \min\limits_{1 \leq k \leq n} \sum\limits_{j=1}^k (r_j - \bar{r_n})} {\bigg( \sum\limits_{j} (r_j - \bar{r_n})^2\bigg)^\frac{1}{2}} )

I suggest you run it in thermo mode. I've been using a range of 3-32. I tried making defaults in the above script but it breaks ToS...

I am happy to release the first pass at a simple, local approximation of the Hurst exponent. This is a work in progress and this post is already taking up too much of my lunch hour.

**It's a measure of a time-series' feedback on itself, or its memory. If the exponent is found to be 1/2, the time series is moving "truly" randomly, and towards 1 or 0 it is either displaying positive feedback or negative feedback, respectively. It was developed by the hydrologist Harol Edwin Hurst in the 1950's to figure out how large to make a dam to deal with all of the possible flooding outcomes. It is directly related to the fractal dimension**### What is the Hurst Exponent?

*D*. Please read more from Wikipedia or*(Mis)Behavior of Markets*by Mandelbrot.The equation from Wikipedia is as follows:

Hurst used the following equation for the Nile. He found it to be ~0.73 for that river.

*R( n)*is the range of the first*n*cumulative deviations from the mean, and*S*( n) their standard deviation, in the case of Hurst's research, the regular standard distribution is used. Mandelbrot cautions again and again in his book about being wary of such a measure because he claims markets are not governed by Gaussians, but by a mix of Cauchy and Gaussian distributions.**E**s the expected value*n*is the time span of the observation (number of data points in a time series)*C*is a constant.

Mandelbrot suggests the following for

*R/S*from p. 288 of the referenced book*:*(LaTeX because it was a pain to write: \frac{R( n)}{S( n)} = \frac {\max\limits_{1 \leq k \leq n} \sum\limits_{j=1}^k (r_j - \bar{r_n}) - \min\limits_{1 \leq k \leq n} \sum\limits_{j=1}^k (r_j - \bar{r_n})} {\bigg( \sum\limits_{j} (r_j - \bar{r_n})^2\bigg)^\frac{1}{2}} )

*r*is the return*r*bar is the average return*n*is the max time range*k*is the index for the sums

### ... What?

Okay what does it mean that it's related to the fractal dimension? It basically means that for a time series, the value of*H*corresponds to how rough the time series is. Let me break it down:- When
*H*is near 1 is implies**persistency:**- positive feedback is at work
- all investors are bullish or bearish
- what to watch for: volume dropping off since everyone has made their bets, the market losing steam and going sideways

- When
*H*is exactly 1/2 is implies**random:**- The stochastic time-series events are independent of each other. No memory or feedback
- What to watch for: conventional finance theories rejoicing temporarily

- When
*H*is near 0 it implies**reversion:**- negative feedback
- tug-of-war, choppy, rough
- what to watch for: chartists mentioning the market coiling up, possibly a change in volatility

### That seems like that math takes ages to do in thinkscript, is there a faster way?

As mentioned in another post, here is a local approximation of the Hurst exponent which can be used:- Where
*h*is the*highest high*in the time range, *l*is the*lowest low*in the time range,*t*is the time period over which measurements are taken- average_*true*_range is the average true
*price range* *C*is a correction factor... ExtremeHurst has some other part that considers log-periodic oscillations... not going into that

### Plotting Hurst in ThinkorSwim

Here is the thinkscript study:
Rich (BB code):

```
input length = 4;
input averageType = AverageType.EXPONENTIAL;
def ll = Lowest(low[1], length);
def hh = Highest(high[1], length);
def atr = MovingAverage(averageType, TrueRange(high, close, low), length);
plot H;
def tmp_H = (Log(hh - ll) - Log(atr)) / (Log(length));
if H > 1 then {
H = 1;
} else if H < 0 {
H = 0;
} else {
H = tmp_H;
}
```

I suggest you run it in thermo mode. I've been using a range of 3-32. I tried making defaults in the above script but it breaks ToS...

**TL;DR: Shared link.**This is on top of @YungTraderFromMontana's wonderful charting setup, FYI: https://tos.mx/mFd0SQZ### What about that correction factor? Where's the _______ ?

This script sucks. I have the following improvements to make:- Make it work over multiple time frames. Right now it just descends some
*length*ticks into the past at the current timescale. This limits the utility - Make defaults. Especially the mid color and range for the thermo plot
- Make it display semilog data; we want to peek deep deep into the time series and see what's frothing in the short term.
- Make alerts for when persistency or antipersistency is appearing across multiple timescales.
- Model log-periodic oscillations, esp. near binary events
- Account for the multifractal nature of trading time

Last edited: