For some reason I continue to have trouble itenditying the lowest bar number after the variable YZ. I tried 7 different ways. I am trying to isolate only the first pink bubble after the yellow bubble which is what ZZ is supposed to do. Anyone know what Im doing wrong? Thank you as always!
Code:
input LBPeriod = 5;
def BN = barnumber();
def HH = Highest(high, LBPeriod);
def marketHigh1 = if HH > HH[-LBPeriod] then HH else HH[-LBPeriod];
def markedHigh1 = high == marketHigh1;
def lastMarkedHigh1 = CompoundValue(1, if IsNaN( markedHigh1) then lastMarkedHigh1[1] else if markedHigh1 then high else lastMarkedHigh1[1], high);
#-------------------------------------------------------------
def Resistance1 = lastMarkedHigh1;
def ResistanceBN = if Resistance1 then bn else ResistanceBN[1];
#--------------------------------------------------------------
def LL = Lowest(low, LBPeriod);
#--------------------------------------------------------------
def marketLow1 = if LL < LL[-LBPeriod] then LL else LL[-LBPeriod];
def markedLow1 = low == marketLow1;
def lastMarkedLow1 = CompoundValue(1, if IsNaN(markedLow1) then lastMarkedLow1[1] else if markedLow1 then low else lastMarkedLow1[1], low);
def Support1 = lastMarkedLow1 ;
def stronglow = if Support1 < Support1[1] then low else stronglow[1];
def Prevstronglow = if stronglow != stronglow[1] then stronglow[1] else Prevstronglow[1];
def weaklow = if low > stronglow and Support1 != stronglow then Support1 else weaklow[1];
def prevweaklow = if weaklow != weaklow[1] then weaklow[1] else prevweaklow[1];
def strongHigh = if Resistance1 > Resistance1[1] then high else strongHigh[1];
def prevstronghigh = if strongHigh != strongHigh[1] then strongHigh[1] else prevstronghigh[1];
def weakHigh = if high < strongHigh and Resistance1 != strongHigh then Resistance1 else weakHigh[1];
def prevweakhigh = if weakHigh != weakHigh[1] then weakHigh[1] else prevweakhigh[1];
def peak = high > high[1] and high[-1] < high;
def valley = low < low[1] and low[-1] > low;
def y = if high crosses above stronghigh and peak then bn else y[1];
def yz = highestall(y);
def yy = if bn > yz and valley then bn else yy[1];
def zz = if bn == lowestall(yy) then bn else zz[1];
addchartbubble(bn==y, high,y,color.yellow);
addchartbubble(bn==yy, low,yy,color.pink);
addchartbubble(bn == zz, low,zz,color.magenta);