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: