The Hurst exponent is used as a measure of long-term memory of time series. It relates to the autocorrelations of the time series and the rate at which these decrease as the lag between pairs of values increases
The Hurst exponent is referred to as the "index of dependence" or "index of long-range dependence". It quantifies the relative tendency of a time series either to regress strongly to the mean or to cluster in a direction.
In short, depending on the value you can spot the trending / reversing market.
- Values 0.5 to 1 - market trending
- Values 0 to 0.5 - market tend to mean revert
Hurst Exponent is computed using Rescaled range (R/S) analysis.
I split the lookback period (N) in the number of shorter samples (for ex. N/2, N/4, N/8, etc.). Then I calculate rescaled range for each sample size.
The Hurst exponent is estimated by fitting the power law. Basically finding the slope of log(samples_size) to log( RS ).
You can choose lookback and sample sizes yourself. Max 8 possible at the moment, if you want to use less use 0 in inputs.
It's pretty computational intensive, so I added an input so you can limit from what date you want it to be calculated. If you hit the time limit in PineScript - limit the history you're using for calculations.
Please remember that past performance may not be indicative of future results.
Due to various factors, including changing market conditions, the strategy may no longer perform as good as in historical backtesting.
This post and the script don’t provide any financial advice.
I sann TradingView-anda har författaren till detta skript publicerat det som öppen källkod, så att handlare kan förstå och verifiera det. Skål för författaren! Du kan använda den gratis men återanvändning av den här koden i en publikation regleras av våra Ordningsregler. Du kan göra den till favorit för att använda den i ett diagram.
Some small suggestions:
Regression slope is best when there are ten or more points on log-log plot.
For rescaled range HE, you can't really tell if there's significant autocorrelation by just looking at if it's above or below 0.5. There's an expected value for rescaled range HE, for 1024 lookback you used, it should be around 0.54. Then you can calculate the standard error of the regression and divide it by the absolute value of HE - 0.54 (expected value) to get the Z score. Or you can just compute a confidence interval around the expected value.
I probably have to optimize code bit more for 10 > points. It can easily hit 200ms bar limit with it.
I'll continue working on it. Confidence interval can be a really nice addition. Will keep you posted with future updates.
In the name of all TradingViewers, thank you for your valuable contribution to the community, and congrats!