InvestorsHub Logo
Followers 11
Posts 2529
Boards Moderated 1
Alias Born 04/03/2009

Re: None

Sunday, 10/02/2022 2:35:59 PM

Sunday, October 02, 2022 2:35:59 PM

Post# of 3631
Hurst Cycles code (found on internet)

# Hurst_Channels
#
# www.trendxplorer.info
# trendxplorer@gmail.com
#
# 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 ----
#

Join the InvestorsHub Community

Register for free to join our community of investors and share your ideas. You will also get access to streaming quotes, interactive charts, trades, portfolio, live options flow and more tools.