Repaints Local Hurst Exponent for ThinkorSwim

Repaints
I found a code for hurts channel

Code:
# Hurst_Channels
#
# www.trendxplorer.info
# [email protected]
#
# Build: July 25, 2012
# Rev 1: July 27, 2012: ExtrapolatedMA based on Kirills code
# Rev 2: July 29, 2012: FlowPrice value for better extremes
# Rev 3: Sept  9, 2012: Coloring for ExtrapolatedCMA added
#

#
# --- script begin ----
#

declare upper;

input price = hl2;
input length = 10;
input InnerValue = 1.6;
input OuterValue = 2.6;
input ExtremeValue = 4.2;
input showFlowPrice = NO;
input showPriceBar = YES;
input smooth = 1;

def displacement = (-length / 2) + 1;
def dPrice = price[displacement];

rec CMA = if !IsNaN(dPrice) then Average(dPrice, AbsValue(length)) else CMA[1] + (CMA[1] - CMA[2]);

plot CenteredMA = if !IsNaN(dPrice) then CMA else Double.NaN;
CenteredMA.SetDefaultColor(GetColor(1));
CenteredMA.SetLineWeight(2);

plot ExtrapolatedMA = if !IsNaN(price) and IsNaN(dprice[-1]) then CMA else
Double.NaN;
ExtrapolatedMA.SetDefaultColor(GetColor(0));
ExtrapolatedMA.SetLineWeight(2);
ExtrapolatedMA.SetStyle(Curve.SHORT_DASH);
ExtrapolatedMA.DefineColor("Up", Color.Magenta);
ExtrapolatedMA.DefineColor("Down", Color.Yellow);
ExtrapolatedMA.AssignValueColor(if ExtrapolatedMA >= ExtrapolatedMA[1] then ExtrapolatedMA.color("Up") else ExtrapolatedMA.color("Down"));

def ExtremeBand = CMA * ExtremeValue / 100;;
def OuterBand   = CMA * OuterValue / 100;
def InnerBand   = CMA * InnerValue / 100;

plot UpperExtremeBand = if !IsNaN(price) then CMA + ExtremeBand else Double.Nan;
plot LowerExtremeBand = if !IsNaN(price) then CMA - ExtremeBand else Double.Nan;
plot UpperOuterBand   = if !IsNaN(price) then CMA + OuterBand else Double.Nan;
plot LowerOuterBand   = if !IsNaN(price) then CMA - OuterBand else Double.Nan;
plot UpperInnerBand   = if !IsNaN(price) then CMA + InnerBand else Double.Nan;
plot LowerInnerBand   = if !IsNaN(price) then CMA - InnerBand else Double.Nan;

UpperExtremeBand.SetDefaultColor(GetColor(4));
UpperExtremeBand.SetLineWeight(2);
LowerExtremeBand.SetDefaultColor(GetColor(4));
LowerExtremeBand.SetLineWeight(2);
UpperExtremeBand.hide();
LowerExtremeBand.hide();

UpperOuterBand.SetDefaultColor(GetColor(5));
UpperOuterBand.SetLineWeight(2);
LowerOuterBand.SetDefaultColor(GetColor(6));
LowerOuterBand.SetLineWeight(2);

UpperInnerBand.SetDefaultColor(GetColor(5));
UpperInnerBand.SetLineWeight(1);
UpperInnerBand.SetStyle(Curve.SHORT_DASH);
LowerInnerBand.SetDefaultColor(GetColor(6));
LowerInnerBand.SetLineWeight(1);
LowerInnerBand.SetStyle(Curve.SHORT_DASH);

# Turn AddClouds off by putting a #-sign at the first position of the lines
AddCloud(UpperOuterBand, UpperInnerBand, color.red);
AddCloud(LowerInnerBand, LowerOuterBand, color.green);

#Rev 2:
#def FlowValue = if close > close[1] then high else if close < close[1] then low else (high + low)/2;
def FlowValue =
    if high >= high[1] and low <= low[1]
    then
        if close >= close[1] #or high >= high[2]
        then high
        else low
    else
        if high > high[1]
        then high
        else
            if low < low[1]
            then low
            else
                if close > close[1]
                then high
                else
                    if close < close[1]
                    then low
                    else (high + low) / 2;

plot FlowPrice = if showFlowPrice then Average(FlowValue, smooth) else double.nan;
FlowPrice.SetDefaultColor(GetColor(9));
FlowPrice.SetLineWeight(2);

hidePricePlot(!showPriceBar);

#
# --- script end ----
#
 
@sniktau if you ever come back to the site I'd like to chat. I've used your code as the core of an algorithm I've mad and was able to work with the issue of it calculating for only one length. I have some more ideas but I don't have the math mind to implement them, so I came back to this post hoping I could talk.
 
@sniktau if you ever come back to the site I'd like to chat. I've used your code as the core of an algorithm I've mad and was able to work with the issue of it calculating for only one length. I have some more ideas but I don't have the math mind to implement them, so I came back to this post hoping I could talk.
@sniktau you write so elegantly it was very nice to meet you. I won't spam your post with artwork but you open excellent thoughts of what is within an order or what is separated into isolated chaotic events...
My human eyes are limited in understanding order or chaos, but I may try for an understanding with enthalpy, entropy, dynamics etc...

Thank you for sharing.
 
Hahah! I stopped trading for a long bit to focus on work. Sorry for going dark, but I'm not dead (yet).

I've been interested in just implementing some of the ideas discussed in Mandelbrot's book. Hurst Exponent tells you the kind of memory that might be at work, but like all TA, I think choice of scale is critical and I'm not sure how to tune it. If tuned right, Hurst exponent could tell you the type of feedback that's going on (positive or negative). It's been a while since I've read it.... and I've also bought a few other books that might help me more dangerous to my own portfolio.

I have been trying to make sense of the Hurst exponent, but I think it needs to be paired with a notion of "trading time". I've been using thinkorswim's candle mode that stretches the candles when volume is big and compresses them when volume is small (equivolume), where volume is an (inverted) proxy for time compression. I wonder if this is backwards for the purposes of Hurst, but I would like to feed that "trading time" to the Hurst calculation.

I'm interested how Yung Trader Montana has been incpororating the result since I've last been active, and if there's any better ways to get a hint when there's a hustle on (fear or greed) in the market apart from Volume, and if I can make my own candle style where large volume/volatility/etc. squeezes time and boring periods are stretched, or at least favor exponents calculated at different scales as appropriate.

TLDR: Anyway, thermo+equivolume is close to what I wanted and I wanted to trade with it on my own for a while, and also work. Sorry for being quiet!

Here's my messy setup right now:
http://tos.mx/lW1aewK
 
I agree that Volume can be a natural accompaniment to Hurst.

In thermodynamics you take an energy balance or entropy balance 0 = 0 and so I would propose taking a disorder balance across competing events rather than favoring Hurst=1.

We should have some phone conference later... I offered @YungTraderFromMontana an NDA after he requested some very minor coding requests but he skipped town lol... I think he will turn up later as well.
https://usethinkscript.com/threads/yungtraders-relative-volume.5243/#post-50262
 
I agree that Volume can be a natural accompaniment to Hurst.

In thermodynamics you take an energy balance or entropy balance 0 = 0 and so I would propose taking a disorder balance across competing events rather than favoring Hurst=1.

We should have some phone conference later... I offered @YungTraderFromMontana an NDA after he requested some very minor coding requests but he skipped town lol... I think he will turn up later as well.
https://usethinkscript.com/threads/yungtraders-relative-volume.5243/#post-50262
I'm not sure I could give you much to work with, as I'm still a budding thinkscripter, and often frustrated by the limitations of my ignorance and the quirks of the tooling. I have some forum reading to catch up on still, I hope you've had a good month :)
 
I'm not sure I could give you much to work with
You have no obligation to spend hours as my librarian. It's nice to find others to discuss these sort of goals

I was happy to make the last breakout detectors for @YungTraderFromMontana. Penny stock breakouts are mostly useless now but he will probably be able use those when the FED settles it's 10 year Treasury Debts (TNX) and the next Bull market begins.
He is either busy or intent on keeping those to himself 🤫 but wherever he is I hope he is well.


Currently I wish to focus directly on Order Flow not when a security passes AllTimeHighs because I am not as knowledgeable as Yung on breakout behaviors...

I imagine almost anything will increase in value if the FED jumps in to manage their debts.
 
I found a code for hurts channel

Code:
# Hurst_Channels
#
# www.trendxplorer.info
# [email protected]
#
# Build: July 25, 2012
# Rev 1: July 27, 2012: ExtrapolatedMA based on Kirills code
# Rev 2: July 29, 2012: FlowPrice value for better extremes
# Rev 3: Sept  9, 2012: Coloring for ExtrapolatedCMA added
#

#
# --- script begin ----
#

declare upper;

input price = hl2;
input length = 10;
input InnerValue = 1.6;
input OuterValue = 2.6;
input ExtremeValue = 4.2;
input showFlowPrice = NO;
input showPriceBar = YES;
input smooth = 1;

def displacement = (-length / 2) + 1;
def dPrice = price[displacement];

rec CMA = if !IsNaN(dPrice) then Average(dPrice, AbsValue(length)) else CMA[1] + (CMA[1] - CMA[2]);

plot CenteredMA = if !IsNaN(dPrice) then CMA else Double.NaN;
CenteredMA.SetDefaultColor(GetColor(1));
CenteredMA.SetLineWeight(2);

plot ExtrapolatedMA = if !IsNaN(price) and IsNaN(dprice[-1]) then CMA else
Double.NaN;
ExtrapolatedMA.SetDefaultColor(GetColor(0));
ExtrapolatedMA.SetLineWeight(2);
ExtrapolatedMA.SetStyle(Curve.SHORT_DASH);
ExtrapolatedMA.DefineColor("Up", Color.Magenta);
ExtrapolatedMA.DefineColor("Down", Color.Yellow);
ExtrapolatedMA.AssignValueColor(if ExtrapolatedMA >= ExtrapolatedMA[1] then ExtrapolatedMA.color("Up") else ExtrapolatedMA.color("Down"));

def ExtremeBand = CMA * ExtremeValue / 100;;
def OuterBand   = CMA * OuterValue / 100;
def InnerBand   = CMA * InnerValue / 100;

plot UpperExtremeBand = if !IsNaN(price) then CMA + ExtremeBand else Double.Nan;
plot LowerExtremeBand = if !IsNaN(price) then CMA - ExtremeBand else Double.Nan;
plot UpperOuterBand   = if !IsNaN(price) then CMA + OuterBand else Double.Nan;
plot LowerOuterBand   = if !IsNaN(price) then CMA - OuterBand else Double.Nan;
plot UpperInnerBand   = if !IsNaN(price) then CMA + InnerBand else Double.Nan;
plot LowerInnerBand   = if !IsNaN(price) then CMA - InnerBand else Double.Nan;

UpperExtremeBand.SetDefaultColor(GetColor(4));
UpperExtremeBand.SetLineWeight(2);
LowerExtremeBand.SetDefaultColor(GetColor(4));
LowerExtremeBand.SetLineWeight(2);
UpperExtremeBand.hide();
LowerExtremeBand.hide();

UpperOuterBand.SetDefaultColor(GetColor(5));
UpperOuterBand.SetLineWeight(2);
LowerOuterBand.SetDefaultColor(GetColor(6));
LowerOuterBand.SetLineWeight(2);

UpperInnerBand.SetDefaultColor(GetColor(5));
UpperInnerBand.SetLineWeight(1);
UpperInnerBand.SetStyle(Curve.SHORT_DASH);
LowerInnerBand.SetDefaultColor(GetColor(6));
LowerInnerBand.SetLineWeight(1);
LowerInnerBand.SetStyle(Curve.SHORT_DASH);

# Turn AddClouds off by putting a #-sign at the first position of the lines
AddCloud(UpperOuterBand, UpperInnerBand, color.red);
AddCloud(LowerInnerBand, LowerOuterBand, color.green);

#Rev 2:
#def FlowValue = if close > close[1] then high else if close < close[1] then low else (high + low)/2;
def FlowValue =
    if high >= high[1] and low <= low[1]
    then
        if close >= close[1] #or high >= high[2]
        then high
        else low
    else
        if high > high[1]
        then high
        else
            if low < low[1]
            then low
            else
                if close > close[1]
                then high
                else
                    if close < close[1]
                    then low
                    else (high + low) / 2;

plot FlowPrice = if showFlowPrice then Average(FlowValue, smooth) else double.nan;
FlowPrice.SetDefaultColor(GetColor(9));
FlowPrice.SetLineWeight(2);

hidePricePlot(!showPriceBar);

#
# --- script end ----
#
GERMANB1990. I really like the plot except the repainting. Looks like it would work great for long-term investing. I've been observing its behavior over the last few crashes. I would really like to have the CenteredMA plot all the way to last data point and ExtrapolatedMA to extend to user specified number of periods. Is that possible? That kind of coding is beyond my capability. Can someone help and modify it it is possible?
 
GERMANB1990. I really like the plot except the repainting. Looks like it would work great for long-term investing. I've been observing its behavior over the last few crashes. I would really like to have the CenteredMA plot all the way to last data point and ExtrapolatedMA to extend to user specified number of periods. Is that possible? That kind of coding is beyond my capability. Can someone help and modify it it is possible?
It looks like centeredMA is just a SMA with displacement = half the selected length. If that's the case, it would have to repaint the second half of the displacement length which has to be extrapolated to reach last data point. Is that correct? .
 
It looks like centeredMA is just a SMA with displacement = half the selected length. If that's the case, it would have to repaint the second half of the displacement length which has to be extrapolated to reach last data point. Is that correct? .
im not sure what youre asking? can you simplify?
 
im not sure what youre asking? can you simplify?
Is it a simple moving average with displaced back by about half the length? IF yes, repainting the extrapolatedMA is required as new data comes in. I'm looking for a dx/dy^a type regression equation with a best fit for the value of a.
 
Does anyone have any info on Hurst cycles? I have some studies but I don't know how to use them?

Day traders use the Hurst Exponent to understand market behavior. A high value suggests a strong trend, so trend-following strategies work best. A low value indicates the market tends to return to its average, favoring mean-reversion strategies.

Hurst is favored by scalpers for its no-lag, price-action, attempts to predict the future.
However, day traders prefer Bollinger Bands, Keltner Channels, etc...
Or any of the non-repainting bands/channels because the prolific repainting and lag of any real signals with the Hurst Indicators.
 
Last edited by a moderator:

Join useThinkScript to post your question to a community of 21,000+ developers and traders.

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
399 Online
Create Post

The Market Trading Game Changer

Join 2,500+ subscribers inside the useThinkScript VIP Membership Club
  • Exclusive indicators
  • Proven strategies & setups
  • Private Discord community
  • ‘Buy The Dip’ signal alerts
  • Exclusive members-only content
  • Add-ons and resources
  • 1 full year of unlimited support

Frequently Asked Questions

What is useThinkScript?

useThinkScript is the #1 community of stock market investors using indicators and other tools to power their trading strategies. Traders of all skill levels use our forums to learn about scripting and indicators, help each other, and discover new ways to gain an edge in the markets.

How do I get started?

We get it. Our forum can be intimidating, if not overwhelming. With thousands of topics, tens of thousands of posts, our community has created an incredibly deep knowledge base for stock traders. No one can ever exhaust every resource provided on our site.

If you are new, or just looking for guidance, here are some helpful links to get you started.

What are the benefits of VIP Membership?
VIP members get exclusive access to these proven and tested premium indicators: Buy the Dip, Advanced Market Moves 2.0, Take Profit, and Volatility Trading Range. In addition, VIP members get access to over 50 VIP-only custom indicators, add-ons, and strategies, private VIP-only forums, private Discord channel to discuss trades and strategies in real-time, customer support, trade alerts, and much more. Learn all about VIP membership here.
How can I access the premium indicators?
To access the premium indicators, which are plug and play ready, sign up for VIP membership here.
Back
Top