Need help in Debugging Days High & Days Low script

I wrote a small script which identifies days HIGH & days LOW, this part is working fine.
In the next step, I am trying to get barcount from the Day's HIGH and days LOW occurrences.

Though the barcounts from d's HIGH & d's LOW are different, the script returning value of the first occurrence for both.

code

y=hhv(h,x+1);
p=LLV(L,x+1);
z=iif(x==0,y,ref(y,-1));
q=iif(x==0,p,ref(p,-1));

maxbar=BarsSince(H==y);
minbar=BarsSince(L==q);

For debugging, screenshot given :
image

First line was not copied. Giving the piece of code again.

x=barssince(day()!=ref(day(),-1));
y=hhv(h,x+1);
p=LLV(L,x+1);
z=iif(x==0,y,ref(y,-1));
q=iif(x==0,p,ref(p,-1));

maxbar=BarsSince(H==z);
minbar=BarsSince(L==q);

How about using HighestSince and LowestSince?

x=day()!=ref(day(),-1);
y=HighestSince( x, H );
p=LowestSince(x, L );

hbar = HighestSinceBars(x,H) ;
lbars = LowestSinceBars(x, L);
1 Like

It works.
Thank you very much.