Hurst Diamond Notation Pivots for ThinkOrSwim

samer800

Moderator - Expert
VIP
Lifetime
Il3SYAC.png

Author Message:
This is a fairly simple indicator for diamond notation of past hi/lo pivot points , a common method in Hurst analysis. The diamonds mark the troughs/peaks of each cycle. They are offset by their lookback and thus will not 'paint' until after they happen so anticipate accordingly. Practically, traders can use the average length of past pivot periods to forecast future pivot periods in time🔮. For example, if the average/dominant number of bars in an 80-bar pivot point period/cycle is 76, then a trader might forecast that the next pivot could occur 76-ish bars after the last confirmed pivot . The numbers/labels on the y-axis display the cycle length used for pivot detection. This indicator doesn't repaint, but it has a lot of lag; Please use it for forecasting instead of entry signals. This indicator scans for new pivots in the form of a rainbow line and circle; once the hi/lo has happened and the lookback has passed then the pivot will be plotted. The rainbow color per wavelength theme seems to be authentic to Hurst (or modern Hurst software) and has been included as a default.

CODE:
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © BarefootJoey
#indicator("Hurst Diamond Notation Pivots", overlay=false)
# Converted by Sam4Cok@Samer800 - 01/2023
declare lower;
input HighsOrLows = {Highs, default Lows}; # "Highs or Lows?"
input HalfCycleLength = 5;   # "Half Cycle Length"
input FullCycleLength = 10;  # "Full Cycle Length"
input x2CycleLength = 20;    # "2x Cycle Length"
input x4CycleLength = 40;    # "4x Cycle Length"
input x8CycleLength = 80;    # "8x Cycle Length"
input x16CycleLength = 160;  # "16x Cycle Length")
input x32CycleLength = 320;  # "32x Cycle Length")
 
def na = Double.NaN;
def highLow = HighsOrLows == HighsOrLows.Highs;
#---- Color
#DefineGlobalColor("linecolor"  , Color.GRAY);
DefineGlobalColor("hcol", Color.MAGENTA);
DefineGlobalColor("col" , CreateColor(33,150,243));
DefineGlobalColor("col2"  , Color.CYAN);
DefineGlobalColor("col4"  , CreateColor(76,175,80));
DefineGlobalColor("col8"  , CreateColor(255,235,59));
DefineGlobalColor("col16" , CreateColor(255,152,0));
DefineGlobalColor("col32" , CreateColor(255,82,82));

DefineGlobalColor("shcol"  , CreateColor(179,0,179));
DefineGlobalColor("scol"   , CreateColor(10,110,189));
DefineGlobalColor("scol2"  , CreateColor(0,179,179));
DefineGlobalColor("scol4"  , CreateColor(53,122,56));
DefineGlobalColor("scol8"  , CreateColor(238,213,0));
DefineGlobalColor("scol16" , CreateColor(179,106,0));
DefineGlobalColor("scol32" , CreateColor(255,5,5));
#barssince(Condition) =>
script barssince {
input Condition = 0;
def barssince = if Condition then 1 else barssince[1] + 1;
plot return = barssince;
}
script FindPivots {
    input dat = close; # default data or study being evaluated
    input HL  = 0;    # default high or low pivot designation, -1 low, +1 high
    input lbL  = 5;    # default Pivot Lookback Left
    input lbR  = 5;    # default Pivot Lookback Right
    ##############
    def _nan;    # used for non-number returns
    def _BN;     # the current barnumber
    def _VStop;  # confirms that the lookforward period continues the pivot trend
    def _V;      # the Value at the actual pivot point
    ##############
    _BN  = BarNumber();
    _nan = Double.NaN;
    _VStop = if !IsNaN(dat) and lbR > 0 and lbL > 0 then
                fold a = 1 to lbR + 1 with b=1 while b do
                    if HL > 0 then dat > GetValue(dat, -a) else dat < GetValue(dat, -a) else _nan;
    if (HL > 0) {
        _V = if _BN > lbL and dat == Highest(dat, lbL + 1) and _VStop
            then dat else _nan;
    } else {
        _V = if _BN > lbL and dat == Lowest(dat, lbL + 1) and _VStop
            then dat else _nan;
    }
    plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}

#// Input/2 (Default 5) Length Pivot Cycle
def ph =  findpivots(high, 1, HalfCycleLength, HalfCycleLength);
def pl =  findpivots(low, -1, HalfCycleLength, HalfCycleLength);
def plh  = if highLow then ph else pl;
def plhy = if highLow then -0.5 else 0.5;
def plhi = barssince(!isNaN(plh));
def plhp = plhi > HalfCycleLength;

plot HalfCycleLine = if isNaN(close[-HalfCycleLength]) or !plhp then na else plhy;
HalfCycleLine.SetDefaultColor(GlobalColor("hcol"));
AddCloud(HalfCycleLine+0.05, HalfCycleLine-0.05, GlobalColor("hcol"));

plot HalfCycleConfirmed = if !isNaN(plh) then plhy else na;
HalfCycleConfirmed.SetLineWeight(2);
HalfCycleConfirmed.SetDefaultColor(GlobalColor("hcol"));
HalfCycleConfirmed.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

plot HalfCycleUnconfirmed = if isNaN(close[-HalfCycleLength-1]) and !isNaN(HalfCycleLine) then plhy else na;
HalfCycleUnconfirmed.SetLineWeight(4);
HalfCycleUnconfirmed.SetDefaultColor(GlobalColor("hcol"));
HalfCycleUnconfirmed.SetPaintingStrategy(PaintingStrategy.POINTS);

#// Input (Default 10) Length Pivot Cycle

def ph1 =  findpivots(high, 1, FullCycleLength, FullCycleLength);
def pl1 =  findpivots(low, -1, FullCycleLength, FullCycleLength);
def pll = if highLow then ph1 else pl1;
def ply = if highLow then -1 else 1;
def pli = barssince(!isNaN(pll));
def plp = pli>FullCycleLength;

plot FullCycleLine = if isNaN(close[-FullCycleLength]) or !plp then na else ply;
FullCycleLine.SetDefaultColor(GlobalColor("col"));
AddCloud(FullCycleLine+0.05, FullCycleLine-0.05, GlobalColor("scol"));

plot FullCycleConfirmed = if isNaN(pll) then na else ply;
FullCycleConfirmed.SetLineWeight(2);
FullCycleConfirmed.SetDefaultColor(GlobalColor("col"));
FullCycleConfirmed.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

plot FullCycleUnconfirmed = if isNaN(close[-FullCycleLength-1]) and !isNaN(FullCycleLine) then ply else na;
FullCycleUnconfirmed.SetLineWeight(4);
FullCycleUnconfirmed.SetDefaultColor(GlobalColor("col"));
FullCycleUnconfirmed.SetPaintingStrategy(PaintingStrategy.POINTS);

#// Input x2 (Default 20) Length Pivot Cycle

def ph2 =  findpivots(high, 1, x2CycleLength, x2CycleLength);
def pl2 =  findpivots(low, -1, x2CycleLength, x2CycleLength);
def pll2 = if highLow then ph2 else pl2;
def pl2y = if highLow then -1.5 else 1.5;
def pl2i = barssince(!isNaN(pll2));
def pl2p = pl2i>x2CycleLength;

plot x2CycleLine = if isNaN(close[-x2CycleLength]) or !pl2p then na else pl2y;
x2CycleLine.SetDefaultColor(GlobalColor("col2"));
AddCloud(x2CycleLine+0.05, x2CycleLine-0.05, GlobalColor("scol2"));

plot x2CycleConfirmed = if isNaN(pll2) then na else pl2y;
x2CycleConfirmed.SetLineWeight(2);
x2CycleConfirmed.SetDefaultColor(GlobalColor("col2"));
x2CycleConfirmed.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

plot x2CycleUnconfirmed = if isNaN(close[-x2CycleLength-1]) and !isNaN(x2CycleLine) then pl2y else na;
x2CycleUnconfirmed.SetLineWeight(4);
x2CycleUnconfirmed.SetDefaultColor(GlobalColor("col2"));
x2CycleUnconfirmed.SetPaintingStrategy(PaintingStrategy.POINTS);

#// Input x4 (Default 40) Length Pivot Cycle

def ph4  =  findpivots(high, 1, x4CycleLength, x4CycleLength);
def pl4  =  findpivots(low, -1, x4CycleLength, x4CycleLength);
def pll4 = if highLow then ph4 else pl4;
def pl4y = if highLow then -2 else 2;
def pl4i = barssince(!isNaN(pll4));
def pl4p = pl4i>x4CycleLength;

plot x4CycleLine = if isNaN(close[-x4CycleLength]) or !pl4p then na else pl4y;
x4CycleLine.SetDefaultColor(GlobalColor("col4"));
AddCloud(x4CycleLine+0.05, x4CycleLine-0.05, GlobalColor("scol4"));

plot x4CycleConfirmed = if isNaN(pll4) then na else pl4y;
x4CycleConfirmed.SetLineWeight(2);
x4CycleConfirmed.SetDefaultColor(GlobalColor("col4"));
x4CycleConfirmed.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

plot x4CycleUnconfirmed = if isNaN(close[-x4CycleLength-1]) and !isNaN(x4CycleLine) then pl4y else na;
x4CycleUnconfirmed.SetLineWeight(4);
x4CycleUnconfirmed.SetDefaultColor(GlobalColor("col4"));
x4CycleUnconfirmed.SetPaintingStrategy(PaintingStrategy.POINTS);

#// Input x8 (Default 80) Length Pivot Cycle

def ph8 =  findpivots(high, 1, x8CycleLength, x8CycleLength);
def pl8 =  findpivots(low, -1, x8CycleLength, x8CycleLength);
def pll8 = if highLow then ph8 else pl8;
def pl8y = if highLow then -2.5 else 2.5;
def pl8i = barssince(!isNaN(pll8));
def pl8p = pl8i>x8CycleLength;

plot x8CycleLine =  if isNaN(close[-x8CycleLength]) or !pl8p then na else pl8y;
x8CycleLine.SetDefaultColor(GlobalColor("col8"));
AddCloud(x8CycleLine+0.05, x8CycleLine-0.05, GlobalColor("scol8"));

plot x8CycleConfirmed = if isNaN(pll8) then na else pl8y;
x8CycleConfirmed.SetLineWeight(2);
x8CycleConfirmed.SetDefaultColor(GlobalColor("col8"));
x8CycleConfirmed.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

plot x8CycleUnconfirmed = if isNaN(close[-x8CycleLength-1]) and !isNaN(x8CycleLine) then pl8y else na;
x8CycleUnconfirmed.SetLineWeight(4);
x8CycleUnconfirmed.SetDefaultColor(GlobalColor("col8"));
x8CycleUnconfirmed.SetPaintingStrategy(PaintingStrategy.POINTS);

#// Input x16 (Default 160) Length Pivot Cycle

def ph16 =  findpivots(high, 1, x16CycleLength, x16CycleLength);
def pl16 =  findpivots(low, -1, x16CycleLength, x16CycleLength);
def pll16 = if highLow then ph16 else pl16;
def pl16y = if highLow then -3 else 3;
def pl16i = barssince(!isNaN(pll16));
def pl16p = pl16i>x16CycleLength;

plot x16CycleLine = if isNaN(close[-x16CycleLength]) or !pl16p then na else pl16y;
x16CycleLine.SetDefaultColor(GlobalColor("col16"));
AddCloud(x16CycleLine+0.05, x16CycleLine-0.05, GlobalColor("scol16"));

plot x16CycleConfirmed = if !isNaN(pll16) then pl16y else na;
x16CycleConfirmed.SetLineWeight(2);
x16CycleConfirmed.SetDefaultColor(GlobalColor("col16"));
x16CycleConfirmed.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

plot x16CycleUnconfirmed = if isNaN(close[-x16CycleLength-1]) and !isNaN(x16CycleLine) then pl16y else na;
x16CycleUnconfirmed.SetLineWeight(4);
x16CycleUnconfirmed.SetDefaultColor(GlobalColor("col16"));
x16CycleUnconfirmed.SetPaintingStrategy(PaintingStrategy.POINTS);

#// Input x32 (Default 230) Length Pivot Cycle

def ph32 =  findpivots(high, 1, x32CycleLength, x32CycleLength);
def pl32 =  findpivots(low, -1, x32CycleLength, x32CycleLength);
def pll32 = if highLow then ph32 else pl32;
def pl32y = if highLow then -3.5 else 3.5;
def pl32i = barssince(!isNaN(pll32));
def pl32p = pl32i>x32CycleLength;

plot x32CycleLine = if isNaN(close[-x32CycleLength]) or !pl32p then na else pl32y;
x32CycleLine.SetDefaultColor(GlobalColor("col32"));
AddCloud(x32CycleLine+0.05, x32CycleLine-0.05, GlobalColor("scol32"));

plot x32CycleConfirmed = if !isNaN(pll32) then pl32y else na;
x32CycleConfirmed.SetLineWeight(2);
x32CycleConfirmed.SetDefaultColor(GlobalColor("col32"));
x32CycleConfirmed.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

plot x32CycleUnconfirmed = if isNaN(close[-x32CycleLength-1]) and !isNaN(x32CycleLine) then pl32y else na;
x32CycleUnconfirmed.SetLineWeight(4);
x32CycleUnconfirmed.SetDefaultColor(GlobalColor("col32"));
x32CycleUnconfirmed.SetPaintingStrategy(PaintingStrategy.POINTS);


#--- END CODE
 
Last edited by a moderator:
Excellent @samer800 and thank you @BarefootJoey.

@samer800, while reviewing the original on TV, I noticed that BarefootJoey made 3 important updates, in Feb, including a bug fix. Since yours was done in Jan, not sure if the above version includes the updates and a fix. Can we request a review of the changes on the TV site:

https://www.tradingview.com/script/DaukfrmD-Hurst-Diamond-Notation-Pivots/

Feb 4 Release Notes:
Thank you everyone for the incredible amount of feedback & love since the original release of this indicator. This major update includes the much-anticipated forecast/prediction of the time range of the next pivot point. The calculation of the average cycle and next pivot point was made possible by just 6 lines of code from the Pivot High/Low Analysis & Forecast by . Many thanks to @LuxAlgo for the code snippet!


Feb 10 Release Notes:
This update provides a temporary fix for plotting the range line for each of the next pivot forecasts. For now, the lines have been removed and the range can only be found when hovering over the forecast diamond. Second, the forecast calculations were updated for accuracy. Third, all of the version 1 and version 2 features are now available (except forecast lines) and can be toggled in the settings.


Feb 13 Release Notes:
The candle close critical error has been fixed; shout out to @upslidedown for the troubleshooting help. All features (from Versions 1 and 2) have been enabled. Please remove and reload this indicator from your charts in order to receive these important updates.
 
Excellent @samer800 and thank you @BarefootJoey.

@samer800, while reviewing the original on TV, I noticed that BarefootJoey made 3 important updates, in Feb, including a bug fix. Since yours was done in Jan, not sure if the above version includes the updates and a fix. Can we request a review of the changes on the TV site:

https://www.tradingview.com/script/DaukfrmD-Hurst-Diamond-Notation-Pivots/

Feb 4 Release Notes:
Thank you everyone for the incredible amount of feedback & love since the original release of this indicator. This major update includes the much-anticipated forecast/prediction of the time range of the next pivot point. The calculation of the average cycle and next pivot point was made possible by just 6 lines of code from the Pivot High/Low Analysis & Forecast by . Many thanks to @LuxAlgo for the code snippet!


Feb 10 Release Notes:
This update provides a temporary fix for plotting the range line for each of the next pivot forecasts. For now, the lines have been removed and the range can only be found when hovering over the forecast diamond. Second, the forecast calculations were updated for accuracy. Third, all of the version 1 and version 2 features are now available (except forecast lines) and can be toggled in the settings.


Feb 13 Release Notes:
The candle close critical error has been fixed; shout out to @upslidedown for the troubleshooting help. All features (from Versions 1 and 2) have been enabled. Please remove and reload this indicator from your charts in order to receive these important updates.
the code converted on Jan, 2023 before the updates. I will look to the new code and see if can be converted.
 
Il3SYAC.png

Author Message:
This is a fairly simple indicator for diamond notation of past hi/lo pivot points , a common method in Hurst analysis. The diamonds mark the troughs/peaks of each cycle. They are offset by their lookback and thus will not 'paint' until after they happen so anticipate accordingly. Practically, traders can use the average length of past pivot periods to forecast future pivot periods in time🔮. For example, if the average/dominant number of bars in an 80-bar pivot point period/cycle is 76, then a trader might forecast that the next pivot could occur 76-ish bars after the last confirmed pivot . The numbers/labels on the y-axis display the cycle length used for pivot detection. This indicator doesn't repaint, but it has a lot of lag; Please use it for forecasting instead of entry signals. This indicator scans for new pivots in the form of a rainbow line and circle; once the hi/lo has happened and the lookback has passed then the pivot will be plotted. The rainbow color per wavelength theme seems to be authentic to Hurst (or modern Hurst software) and has been included as a default.

CODE:
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © BarefootJoey
#indicator("Hurst Diamond Notation Pivots", overlay=false)
# Converted by Sam4Cok@Samer800 - 01/2023
declare lower;
input HighsOrLows = {Highs, default Lows}; # "Highs or Lows?"
input HalfCycleLength = 5;   # "Half Cycle Length"
input FullCycleLength = 10;  # "Full Cycle Length"
input x2CycleLength = 20;    # "2x Cycle Length"
input x4CycleLength = 40;    # "4x Cycle Length"
input x8CycleLength = 80;    # "8x Cycle Length"
input x16CycleLength = 160;  # "16x Cycle Length")
input x32CycleLength = 320;  # "32x Cycle Length")
 
def na = Double.NaN;
def highLow = HighsOrLows == HighsOrLows.Highs;
#---- Color
#DefineGlobalColor("linecolor"  , Color.GRAY);
DefineGlobalColor("hcol", Color.MAGENTA);
DefineGlobalColor("col" , CreateColor(33,150,243));
DefineGlobalColor("col2"  , Color.CYAN);
DefineGlobalColor("col4"  , CreateColor(76,175,80));
DefineGlobalColor("col8"  , CreateColor(255,235,59));
DefineGlobalColor("col16" , CreateColor(255,152,0));
DefineGlobalColor("col32" , CreateColor(255,82,82));

DefineGlobalColor("shcol"  , CreateColor(179,0,179));
DefineGlobalColor("scol"   , CreateColor(10,110,189));
DefineGlobalColor("scol2"  , CreateColor(0,179,179));
DefineGlobalColor("scol4"  , CreateColor(53,122,56));
DefineGlobalColor("scol8"  , CreateColor(238,213,0));
DefineGlobalColor("scol16" , CreateColor(179,106,0));
DefineGlobalColor("scol32" , CreateColor(255,5,5));
#barssince(Condition) =>
script barssince {
input Condition = 0;
def barssince = if Condition then 1 else barssince[1] + 1;
plot return = barssince;
}
script FindPivots {
    input dat = close; # default data or study being evaluated
    input HL  = 0;    # default high or low pivot designation, -1 low, +1 high
    input lbL  = 5;    # default Pivot Lookback Left
    input lbR  = 5;    # default Pivot Lookback Right
    ##############
    def _nan;    # used for non-number returns
    def _BN;     # the current barnumber
    def _VStop;  # confirms that the lookforward period continues the pivot trend
    def _V;      # the Value at the actual pivot point
    ##############
    _BN  = BarNumber();
    _nan = Double.NaN;
    _VStop = if !IsNaN(dat) and lbR > 0 and lbL > 0 then
                fold a = 1 to lbR + 1 with b=1 while b do
                    if HL > 0 then dat > GetValue(dat, -a) else dat < GetValue(dat, -a) else _nan;
    if (HL > 0) {
        _V = if _BN > lbL and dat == Highest(dat, lbL + 1) and _VStop
            then dat else _nan;
    } else {
        _V = if _BN > lbL and dat == Lowest(dat, lbL + 1) and _VStop
            then dat else _nan;
    }
    plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}

#// Input/2 (Default 5) Length Pivot Cycle
def ph =  findpivots(high, 1, HalfCycleLength, HalfCycleLength);
def pl =  findpivots(low, -1, HalfCycleLength, HalfCycleLength);
def plh  = if highLow then ph else pl;
def plhy = if highLow then -0.5 else 0.5;
def plhi = barssince(!isNaN(plh));
def plhp = plhi > HalfCycleLength;

plot HalfCycleLine = if isNaN(close[-HalfCycleLength]) or !plhp then na else plhy;
HalfCycleLine.SetDefaultColor(GlobalColor("hcol"));
AddCloud(HalfCycleLine+0.05, HalfCycleLine-0.05, GlobalColor("hcol"));

plot HalfCycleConfirmed = if !isNaN(plh) then plhy else na;
HalfCycleConfirmed.SetLineWeight(2);
HalfCycleConfirmed.SetDefaultColor(GlobalColor("hcol"));
HalfCycleConfirmed.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

plot HalfCycleUnconfirmed = if isNaN(close[-HalfCycleLength-1]) and !isNaN(HalfCycleLine) then plhy else na;
HalfCycleUnconfirmed.SetLineWeight(4);
HalfCycleUnconfirmed.SetDefaultColor(GlobalColor("hcol"));
HalfCycleUnconfirmed.SetPaintingStrategy(PaintingStrategy.POINTS);

#// Input (Default 10) Length Pivot Cycle

def ph1 =  findpivots(high, 1, FullCycleLength, FullCycleLength);
def pl1 =  findpivots(low, -1, FullCycleLength, FullCycleLength);
def pll = if highLow then ph1 else pl1;
def ply = if highLow then -1 else 1;
def pli = barssince(!isNaN(pll));
def plp = pli>FullCycleLength;

plot FullCycleLine = if isNaN(close[-FullCycleLength]) or !plp then na else ply;
FullCycleLine.SetDefaultColor(GlobalColor("col"));
AddCloud(FullCycleLine+0.05, FullCycleLine-0.05, GlobalColor("scol"));

plot FullCycleConfirmed = if isNaN(pll) then na else ply;
FullCycleConfirmed.SetLineWeight(2);
FullCycleConfirmed.SetDefaultColor(GlobalColor("col"));
FullCycleConfirmed.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

plot FullCycleUnconfirmed = if isNaN(close[-FullCycleLength-1]) and !isNaN(FullCycleLine) then ply else na;
FullCycleUnconfirmed.SetLineWeight(4);
FullCycleUnconfirmed.SetDefaultColor(GlobalColor("col"));
FullCycleUnconfirmed.SetPaintingStrategy(PaintingStrategy.POINTS);

#// Input x2 (Default 20) Length Pivot Cycle

def ph2 =  findpivots(high, 1, x2CycleLength, x2CycleLength);
def pl2 =  findpivots(low, -1, x2CycleLength, x2CycleLength);
def pll2 = if highLow then ph2 else pl2;
def pl2y = if highLow then -1.5 else 1.5;
def pl2i = barssince(!isNaN(pll2));
def pl2p = pl2i>x2CycleLength;

plot x2CycleLine = if isNaN(close[-x2CycleLength]) or !pl2p then na else pl2y;
x2CycleLine.SetDefaultColor(GlobalColor("col2"));
AddCloud(x2CycleLine+0.05, x2CycleLine-0.05, GlobalColor("scol2"));

plot x2CycleConfirmed = if isNaN(pll2) then na else pl2y;
x2CycleConfirmed.SetLineWeight(2);
x2CycleConfirmed.SetDefaultColor(GlobalColor("col2"));
x2CycleConfirmed.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

plot x2CycleUnconfirmed = if isNaN(close[-x2CycleLength-1]) and !isNaN(x2CycleLine) then pl2y else na;
x2CycleUnconfirmed.SetLineWeight(4);
x2CycleUnconfirmed.SetDefaultColor(GlobalColor("col2"));
x2CycleUnconfirmed.SetPaintingStrategy(PaintingStrategy.POINTS);

#// Input x4 (Default 40) Length Pivot Cycle

def ph4  =  findpivots(high, 1, x4CycleLength, x4CycleLength);
def pl4  =  findpivots(low, -1, x4CycleLength, x4CycleLength);
def pll4 = if highLow then ph4 else pl4;
def pl4y = if highLow then -2 else 2;
def pl4i = barssince(!isNaN(pll4));
def pl4p = pl4i>x4CycleLength;

plot x4CycleLine = if isNaN(close[-x4CycleLength]) or !pl4p then na else pl4y;
x4CycleLine.SetDefaultColor(GlobalColor("col4"));
AddCloud(x4CycleLine+0.05, x4CycleLine-0.05, GlobalColor("scol4"));

plot x4CycleConfirmed = if isNaN(pll4) then na else pl4y;
x4CycleConfirmed.SetLineWeight(2);
x4CycleConfirmed.SetDefaultColor(GlobalColor("col4"));
x4CycleConfirmed.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

plot x4CycleUnconfirmed = if isNaN(close[-x4CycleLength-1]) and !isNaN(x4CycleLine) then pl4y else na;
x4CycleUnconfirmed.SetLineWeight(4);
x4CycleUnconfirmed.SetDefaultColor(GlobalColor("col4"));
x4CycleUnconfirmed.SetPaintingStrategy(PaintingStrategy.POINTS);

#// Input x8 (Default 80) Length Pivot Cycle

def ph8 =  findpivots(high, 1, x8CycleLength, x8CycleLength);
def pl8 =  findpivots(low, -1, x8CycleLength, x8CycleLength);
def pll8 = if highLow then ph8 else pl8;
def pl8y = if highLow then -2.5 else 2.5;
def pl8i = barssince(!isNaN(pll8));
def pl8p = pl8i>x8CycleLength;

plot x8CycleLine =  if isNaN(close[-x8CycleLength]) or !pl8p then na else pl8y;
x8CycleLine.SetDefaultColor(GlobalColor("col8"));
AddCloud(x8CycleLine+0.05, x8CycleLine-0.05, GlobalColor("scol8"));

plot x8CycleConfirmed = if isNaN(pll8) then na else pl8y;
x8CycleConfirmed.SetLineWeight(2);
x8CycleConfirmed.SetDefaultColor(GlobalColor("col8"));
x8CycleConfirmed.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

plot x8CycleUnconfirmed = if isNaN(close[-x8CycleLength-1]) and !isNaN(x8CycleLine) then pl8y else na;
x8CycleUnconfirmed.SetLineWeight(4);
x8CycleUnconfirmed.SetDefaultColor(GlobalColor("col8"));
x8CycleUnconfirmed.SetPaintingStrategy(PaintingStrategy.POINTS);

#// Input x16 (Default 160) Length Pivot Cycle

def ph16 =  findpivots(high, 1, x16CycleLength, x16CycleLength);
def pl16 =  findpivots(low, -1, x16CycleLength, x16CycleLength);
def pll16 = if highLow then ph16 else pl16;
def pl16y = if highLow then -3 else 3;
def pl16i = barssince(!isNaN(pll16));
def pl16p = pl16i>x16CycleLength;

plot x16CycleLine = if isNaN(close[-x16CycleLength]) or !pl16p then na else pl16y;
x16CycleLine.SetDefaultColor(GlobalColor("col16"));
AddCloud(x16CycleLine+0.05, x16CycleLine-0.05, GlobalColor("scol16"));

plot x16CycleConfirmed = if !isNaN(pll16) then pl16y else na;
x16CycleConfirmed.SetLineWeight(2);
x16CycleConfirmed.SetDefaultColor(GlobalColor("col16"));
x16CycleConfirmed.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

plot x16CycleUnconfirmed = if isNaN(close[-x16CycleLength-1]) and !isNaN(x16CycleLine) then pl16y else na;
x16CycleUnconfirmed.SetLineWeight(4);
x16CycleUnconfirmed.SetDefaultColor(GlobalColor("col16"));
x16CycleUnconfirmed.SetPaintingStrategy(PaintingStrategy.POINTS);

#// Input x32 (Default 230) Length Pivot Cycle

def ph32 =  findpivots(high, 1, x32CycleLength, x32CycleLength);
def pl32 =  findpivots(low, -1, x32CycleLength, x32CycleLength);
def pll32 = if highLow then ph32 else pl32;
def pl32y = if highLow then -3.5 else 3.5;
def pl32i = barssince(!isNaN(pll32));
def pl32p = pl32i>x32CycleLength;

plot x32CycleLine = if isNaN(close[-x32CycleLength]) or !pl32p then na else pl32y;
x32CycleLine.SetDefaultColor(GlobalColor("col32"));
AddCloud(x32CycleLine+0.05, x32CycleLine-0.05, GlobalColor("scol32"));

plot x32CycleConfirmed = if !isNaN(pll32) then pl32y else na;
x32CycleConfirmed.SetLineWeight(2);
x32CycleConfirmed.SetDefaultColor(GlobalColor("col32"));
x32CycleConfirmed.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

plot x32CycleUnconfirmed = if isNaN(close[-x32CycleLength-1]) and !isNaN(x32CycleLine) then pl32y else na;
x32CycleUnconfirmed.SetLineWeight(4);
x32CycleUnconfirmed.SetDefaultColor(GlobalColor("col32"));
x32CycleUnconfirmed.SetPaintingStrategy(PaintingStrategy.POINTS);


#--- END CODE
@samer800 Could you add a signal marker or an input for the price to get colored when there's an alignment? Thanks.

 
Thank you much for bringing these to TOS, it is very similar to what they use here. https://sentienttrader.com/blog/

here is how I'm setting it up right now, only forecast turn dates are still missing but looking great.

Bw7U9Vs.png
Hi I haven’t had any real-time with this code; could you or someone provide the amount of lag time there is after the data has been plotted; example on 5 time frame if the cycles align roughly how many bars after would there be for a confirmation? Any details much appreciated.
 
Il3SYAC.png

Author Message:
This is a fairly simple indicator for diamond notation of past hi/lo pivot points , a common method in Hurst analysis. The diamonds mark the troughs/peaks of each cycle. They are offset by their lookback and thus will not 'paint' until after they happen so anticipate accordingly. Practically, traders can use the average length of past pivot periods to forecast future pivot periods in time🔮. For example, if the average/dominant number of bars in an 80-bar pivot point period/cycle is 76, then a trader might forecast that the next pivot could occur 76-ish bars after the last confirmed pivot . The numbers/labels on the y-axis display the cycle length used for pivot detection. This indicator doesn't repaint, but it has a lot of lag; Please use it for forecasting instead of entry signals. This indicator scans for new pivots in the form of a rainbow line and circle; once the hi/lo has happened and the lookback has passed then the pivot will be plotted. The rainbow color per wavelength theme seems to be authentic to Hurst (or modern Hurst software) and has been included as a default.

CODE:
CSS:
#// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
#// © BarefootJoey
#indicator("Hurst Diamond Notation Pivots", overlay=false)
# Converted by Sam4Cok@Samer800 - 01/2023
declare lower;
input HighsOrLows = {Highs, default Lows}; # "Highs or Lows?"
input HalfCycleLength = 5;   # "Half Cycle Length"
input FullCycleLength = 10;  # "Full Cycle Length"
input x2CycleLength = 20;    # "2x Cycle Length"
input x4CycleLength = 40;    # "4x Cycle Length"
input x8CycleLength = 80;    # "8x Cycle Length"
input x16CycleLength = 160;  # "16x Cycle Length")
input x32CycleLength = 320;  # "32x Cycle Length")
 
def na = Double.NaN;
def highLow = HighsOrLows == HighsOrLows.Highs;
#---- Color
#DefineGlobalColor("linecolor"  , Color.GRAY);
DefineGlobalColor("hcol", Color.MAGENTA);
DefineGlobalColor("col" , CreateColor(33,150,243));
DefineGlobalColor("col2"  , Color.CYAN);
DefineGlobalColor("col4"  , CreateColor(76,175,80));
DefineGlobalColor("col8"  , CreateColor(255,235,59));
DefineGlobalColor("col16" , CreateColor(255,152,0));
DefineGlobalColor("col32" , CreateColor(255,82,82));

DefineGlobalColor("shcol"  , CreateColor(179,0,179));
DefineGlobalColor("scol"   , CreateColor(10,110,189));
DefineGlobalColor("scol2"  , CreateColor(0,179,179));
DefineGlobalColor("scol4"  , CreateColor(53,122,56));
DefineGlobalColor("scol8"  , CreateColor(238,213,0));
DefineGlobalColor("scol16" , CreateColor(179,106,0));
DefineGlobalColor("scol32" , CreateColor(255,5,5));
#barssince(Condition) =>
script barssince {
input Condition = 0;
def barssince = if Condition then 1 else barssince[1] + 1;
plot return = barssince;
}
script FindPivots {
    input dat = close; # default data or study being evaluated
    input HL  = 0;    # default high or low pivot designation, -1 low, +1 high
    input lbL  = 5;    # default Pivot Lookback Left
    input lbR  = 5;    # default Pivot Lookback Right
    ##############
    def _nan;    # used for non-number returns
    def _BN;     # the current barnumber
    def _VStop;  # confirms that the lookforward period continues the pivot trend
    def _V;      # the Value at the actual pivot point
    ##############
    _BN  = BarNumber();
    _nan = Double.NaN;
    _VStop = if !IsNaN(dat) and lbR > 0 and lbL > 0 then
                fold a = 1 to lbR + 1 with b=1 while b do
                    if HL > 0 then dat > GetValue(dat, -a) else dat < GetValue(dat, -a) else _nan;
    if (HL > 0) {
        _V = if _BN > lbL and dat == Highest(dat, lbL + 1) and _VStop
            then dat else _nan;
    } else {
        _V = if _BN > lbL and dat == Lowest(dat, lbL + 1) and _VStop
            then dat else _nan;
    }
    plot result = if !IsNaN(_V) and _VStop then _V else _nan;
}

#// Input/2 (Default 5) Length Pivot Cycle
def ph =  findpivots(high, 1, HalfCycleLength, HalfCycleLength);
def pl =  findpivots(low, -1, HalfCycleLength, HalfCycleLength);
def plh  = if highLow then ph else pl;
def plhy = if highLow then -0.5 else 0.5;
def plhi = barssince(!isNaN(plh));
def plhp = plhi > HalfCycleLength;

plot HalfCycleLine = if isNaN(close[-HalfCycleLength]) or !plhp then na else plhy;
HalfCycleLine.SetDefaultColor(GlobalColor("hcol"));
AddCloud(HalfCycleLine+0.05, HalfCycleLine-0.05, GlobalColor("hcol"));

plot HalfCycleConfirmed = if !isNaN(plh) then plhy else na;
HalfCycleConfirmed.SetLineWeight(2);
HalfCycleConfirmed.SetDefaultColor(GlobalColor("hcol"));
HalfCycleConfirmed.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

plot HalfCycleUnconfirmed = if isNaN(close[-HalfCycleLength-1]) and !isNaN(HalfCycleLine) then plhy else na;
HalfCycleUnconfirmed.SetLineWeight(4);
HalfCycleUnconfirmed.SetDefaultColor(GlobalColor("hcol"));
HalfCycleUnconfirmed.SetPaintingStrategy(PaintingStrategy.POINTS);

#// Input (Default 10) Length Pivot Cycle

def ph1 =  findpivots(high, 1, FullCycleLength, FullCycleLength);
def pl1 =  findpivots(low, -1, FullCycleLength, FullCycleLength);
def pll = if highLow then ph1 else pl1;
def ply = if highLow then -1 else 1;
def pli = barssince(!isNaN(pll));
def plp = pli>FullCycleLength;

plot FullCycleLine = if isNaN(close[-FullCycleLength]) or !plp then na else ply;
FullCycleLine.SetDefaultColor(GlobalColor("col"));
AddCloud(FullCycleLine+0.05, FullCycleLine-0.05, GlobalColor("scol"));

plot FullCycleConfirmed = if isNaN(pll) then na else ply;
FullCycleConfirmed.SetLineWeight(2);
FullCycleConfirmed.SetDefaultColor(GlobalColor("col"));
FullCycleConfirmed.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

plot FullCycleUnconfirmed = if isNaN(close[-FullCycleLength-1]) and !isNaN(FullCycleLine) then ply else na;
FullCycleUnconfirmed.SetLineWeight(4);
FullCycleUnconfirmed.SetDefaultColor(GlobalColor("col"));
FullCycleUnconfirmed.SetPaintingStrategy(PaintingStrategy.POINTS);

#// Input x2 (Default 20) Length Pivot Cycle

def ph2 =  findpivots(high, 1, x2CycleLength, x2CycleLength);
def pl2 =  findpivots(low, -1, x2CycleLength, x2CycleLength);
def pll2 = if highLow then ph2 else pl2;
def pl2y = if highLow then -1.5 else 1.5;
def pl2i = barssince(!isNaN(pll2));
def pl2p = pl2i>x2CycleLength;

plot x2CycleLine = if isNaN(close[-x2CycleLength]) or !pl2p then na else pl2y;
x2CycleLine.SetDefaultColor(GlobalColor("col2"));
AddCloud(x2CycleLine+0.05, x2CycleLine-0.05, GlobalColor("scol2"));

plot x2CycleConfirmed = if isNaN(pll2) then na else pl2y;
x2CycleConfirmed.SetLineWeight(2);
x2CycleConfirmed.SetDefaultColor(GlobalColor("col2"));
x2CycleConfirmed.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

plot x2CycleUnconfirmed = if isNaN(close[-x2CycleLength-1]) and !isNaN(x2CycleLine) then pl2y else na;
x2CycleUnconfirmed.SetLineWeight(4);
x2CycleUnconfirmed.SetDefaultColor(GlobalColor("col2"));
x2CycleUnconfirmed.SetPaintingStrategy(PaintingStrategy.POINTS);

#// Input x4 (Default 40) Length Pivot Cycle

def ph4  =  findpivots(high, 1, x4CycleLength, x4CycleLength);
def pl4  =  findpivots(low, -1, x4CycleLength, x4CycleLength);
def pll4 = if highLow then ph4 else pl4;
def pl4y = if highLow then -2 else 2;
def pl4i = barssince(!isNaN(pll4));
def pl4p = pl4i>x4CycleLength;

plot x4CycleLine = if isNaN(close[-x4CycleLength]) or !pl4p then na else pl4y;
x4CycleLine.SetDefaultColor(GlobalColor("col4"));
AddCloud(x4CycleLine+0.05, x4CycleLine-0.05, GlobalColor("scol4"));

plot x4CycleConfirmed = if isNaN(pll4) then na else pl4y;
x4CycleConfirmed.SetLineWeight(2);
x4CycleConfirmed.SetDefaultColor(GlobalColor("col4"));
x4CycleConfirmed.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

plot x4CycleUnconfirmed = if isNaN(close[-x4CycleLength-1]) and !isNaN(x4CycleLine) then pl4y else na;
x4CycleUnconfirmed.SetLineWeight(4);
x4CycleUnconfirmed.SetDefaultColor(GlobalColor("col4"));
x4CycleUnconfirmed.SetPaintingStrategy(PaintingStrategy.POINTS);

#// Input x8 (Default 80) Length Pivot Cycle

def ph8 =  findpivots(high, 1, x8CycleLength, x8CycleLength);
def pl8 =  findpivots(low, -1, x8CycleLength, x8CycleLength);
def pll8 = if highLow then ph8 else pl8;
def pl8y = if highLow then -2.5 else 2.5;
def pl8i = barssince(!isNaN(pll8));
def pl8p = pl8i>x8CycleLength;

plot x8CycleLine =  if isNaN(close[-x8CycleLength]) or !pl8p then na else pl8y;
x8CycleLine.SetDefaultColor(GlobalColor("col8"));
AddCloud(x8CycleLine+0.05, x8CycleLine-0.05, GlobalColor("scol8"));

plot x8CycleConfirmed = if isNaN(pll8) then na else pl8y;
x8CycleConfirmed.SetLineWeight(2);
x8CycleConfirmed.SetDefaultColor(GlobalColor("col8"));
x8CycleConfirmed.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

plot x8CycleUnconfirmed = if isNaN(close[-x8CycleLength-1]) and !isNaN(x8CycleLine) then pl8y else na;
x8CycleUnconfirmed.SetLineWeight(4);
x8CycleUnconfirmed.SetDefaultColor(GlobalColor("col8"));
x8CycleUnconfirmed.SetPaintingStrategy(PaintingStrategy.POINTS);

#// Input x16 (Default 160) Length Pivot Cycle

def ph16 =  findpivots(high, 1, x16CycleLength, x16CycleLength);
def pl16 =  findpivots(low, -1, x16CycleLength, x16CycleLength);
def pll16 = if highLow then ph16 else pl16;
def pl16y = if highLow then -3 else 3;
def pl16i = barssince(!isNaN(pll16));
def pl16p = pl16i>x16CycleLength;

plot x16CycleLine = if isNaN(close[-x16CycleLength]) or !pl16p then na else pl16y;
x16CycleLine.SetDefaultColor(GlobalColor("col16"));
AddCloud(x16CycleLine+0.05, x16CycleLine-0.05, GlobalColor("scol16"));

plot x16CycleConfirmed = if !isNaN(pll16) then pl16y else na;
x16CycleConfirmed.SetLineWeight(2);
x16CycleConfirmed.SetDefaultColor(GlobalColor("col16"));
x16CycleConfirmed.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

plot x16CycleUnconfirmed = if isNaN(close[-x16CycleLength-1]) and !isNaN(x16CycleLine) then pl16y else na;
x16CycleUnconfirmed.SetLineWeight(4);
x16CycleUnconfirmed.SetDefaultColor(GlobalColor("col16"));
x16CycleUnconfirmed.SetPaintingStrategy(PaintingStrategy.POINTS);

#// Input x32 (Default 230) Length Pivot Cycle

def ph32 =  findpivots(high, 1, x32CycleLength, x32CycleLength);
def pl32 =  findpivots(low, -1, x32CycleLength, x32CycleLength);
def pll32 = if highLow then ph32 else pl32;
def pl32y = if highLow then -3.5 else 3.5;
def pl32i = barssince(!isNaN(pll32));
def pl32p = pl32i>x32CycleLength;

plot x32CycleLine = if isNaN(close[-x32CycleLength]) or !pl32p then na else pl32y;
x32CycleLine.SetDefaultColor(GlobalColor("col32"));
AddCloud(x32CycleLine+0.05, x32CycleLine-0.05, GlobalColor("scol32"));

plot x32CycleConfirmed = if !isNaN(pll32) then pl32y else na;
x32CycleConfirmed.SetLineWeight(2);
x32CycleConfirmed.SetDefaultColor(GlobalColor("col32"));
x32CycleConfirmed.SetPaintingStrategy(PaintingStrategy.TRIANGLES);

plot x32CycleUnconfirmed = if isNaN(close[-x32CycleLength-1]) and !isNaN(x32CycleLine) then pl32y else na;
x32CycleUnconfirmed.SetLineWeight(4);
x32CycleUnconfirmed.SetDefaultColor(GlobalColor("col32"));
x32CycleUnconfirmed.SetPaintingStrategy(PaintingStrategy.POINTS);


#--- END CODE
Feedback on this data lags and most likely would add noise to your trading unless you use the larger time frames to confirm a turning point. It did not pass the more minor time frame futures test.
 
Feedback on this data lags and most likely would add noise to your trading unless you use the larger time frames to confirm a turning point. It did not pass the more minor time frame futures test.
I checked it out today and came to the same conclusion. It even looks laggy on daily charts. The historical charts looked too good to be true and it looks like they are too good to be true.
 

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

Thread starter Similar threads Forum Replies Date
L Repaints Hurst Spectral Analysis Oscillator For ThinkOrSwim Custom 2
M Hurst Cycle Channel Clone For ThinkOrSwim Custom 2

Similar threads

Not the exact question you're looking for?

Start a new thread and receive assistance from our community.

87k+ Posts
363 Online
Create Post

Similar threads

Similar threads

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