Hi All! The following code is for a watchlist column Im using intraday. In lines 60 and 61 of my code below (def priorRevLong and def priorRevShort) I am trying to identify older occasions when RevShort and RevLong has occurred. I don't think my code is working as I have it written. Can anyone help point me in the right direction? Thanks in advance and, as always, you guys ROCK!!
Code:
def H = high;
def L = low;
def C = close;
def O = open;
def bn = BarNumber();
def isRollover = GetYYYYMMDD() != GetYYYYMMDD()[1];
def beforeStart = GetTime() < RegularTradingStart(GetYYYYMMDD());
def firstBarOfDay = if (beforeStart[1] == 1 and beforeStart == 0) or (isRollover and beforeStart == 0) then bn else firstBarOfDay[1];
def DayOpen = if bn == firstbarofday then open else DayOpen[1];
def DayUp = c > DayOpen;
def DayDn = c < DayOpen;
def inside = H < H[1] and L > L[1] ;
#for reversal back to long side
def twodnbullish = H < H[1] and L < L[1];# and (c > fiftypct or c > o); #for reversal back to long side
def twoupbearish = L > L[1] and H > H[1];# and (c < fiftypct or c < o); #for reversal back to short side
#def risk = 10;
def longsig = twodnbullish or inside;
def shortsig = twoupbearish or inside;
def sequenceCount = 2;
def maxSideLength = sequenceCount + 10;
def upRightSide = fold i1 = 1 to maxSideLength + 1 with count1 while count1 != sequenceCount and count1 != -1 do
if GetValue(H, -i1, -maxSideLength) > H or (GetValue(H, -i1, -maxSideLength) == H and count1 == 0) then -1
else if GetValue(H, -i1, -maxSideLength) < H then count1 + 1 else count1;
def upLeftSide = fold i2 = 1 to maxSideLength + 1 with count2 while count2 != sequenceCount and count2 != -1 do
if GetValue(H, i2, maxSideLength) > H or (GetValue(H, i2, maxSideLength) == H and count2 >= 1) then -1
else if GetValue(H, i2, maxSideLength) < H then count2 + 1 else count2;
def downRightSide = fold i3 = 1 to maxSideLength + 1 with count3 while count3 != sequenceCount and count3 != -1 do
if GetValue(L, -i3, -maxSideLength) < L or (GetValue(L, -i3, -maxSideLength) == L and count3 == 0) then -1
else if GetValue(H, -i3, -maxSideLength) > L then count3 + 1 else count3;
def downLeftSide = fold i4 = 1 to maxSideLength + 1 with count4 while count4 != sequenceCount and count4 != -1 do
if GetValue(L, i4, maxSideLength) < L or (GetValue(L, i4, maxSideLength) == L and count4 >= 1) then -1
else if GetValue(L, i4, maxSideLength) > L then count4 + 1 else count4;
def UpFractal = if upRightSide == sequenceCount and upLeftSide == sequenceCount then H else Double.NaN;
def DownFractal = if downRightSide == sequenceCount and downLeftSide == sequenceCount then L else Double.NaN;
def UpFractalBN = if !IsNaN(UpFractal) then bn else UpFractalBN[1];
def DnFractalBN = if !IsNaN(DownFractal) then bn else DnFractalBN[1];
def UpH = GetValue(H, bn - UpFractalBN); #if bn == UpFractalBN then H else UpH[1];
def DnL = GetValue(L, bn - DnFractalBN); #if bn == DnFractalBN then L else DnL[1];
def BFrange = UpH - DnL;
def NormalizedClose = C - DnL;
def calc = (NormalizedClose / BFrange)*100;
def Above = calc >= 100;
#def Seventy = calc >= 70 and calc < 100;
#def Mid = calc >= 30 and calc < 70;
#def Thirty = calc >0 and calc < 30;
def Below = calc <= 0;
def revshort = daydn and Above and shortsig;
def revlong = dayup and Below and longsig ;
def priorRevLong = if revlong then 777 else if revlong[1] then 1 else if revlong[2] then 2 else if revlong[3] then 3 else if revlong[4] then 4 else if revlong[5] then 5 else if revlong[6] then 6 else if revlong[7] then 7 else 0;
def priorRevshort = if revshort then 888 else if revshort[1] then 1 else if revshort[2] then 2 else if revshort[3] then 3 else if revshort[4] then 4 else if revshort[5] then 5 else if revshort[6] then 6 else if revshort[7] then 7 else 0;
addlabel(yes,if dayup and priorrevlong == 777 then "🔃" else if dayup and priorrevlong != 0 then "👆" else if daydn and priorrevshort == 888 then "🔃" else if daydn and priorrevshort != 0 then "👇" else " ", if dayup and priorrevlong == 777 then color.cyan else if dayup and priorrevlong != 0 then color.green else if daydn and priorrevshort == 888 then color.magenta else if daydn and priorrevshort != 0 then color.red else color.black );