Number of bars from lowest low within last 20 bars

I have a long strategy which does a buy when a pullback happens in a uptrend. So when i got a buy signal, i want to know how many bars the previous lowest low within 20 bars did occur, because i want the lowest low within 20 bars to be at least 15 bars away to be this buy signal valid

So i have something like:

Buy = RSI(2) < 38 AND
C >MA(c,50) AND
BarsSince(Ref(LLV(L,18),-2) == L) > 15

But this is not working somehow.

I use ref(xxx,-2) because maybe this is a new low, but i want to know how if the previous low within 20 bars, is 15 bars away

Can anybody help me with this

Thanks in advance

Maybe this picture clarifies the issue even more:


Get rid of the Ref in your code.

condition = BarsSince( LLV( L, 18 ) == L ) > 15;
Plot( condition, "condition", colorRed, styleLine );

thx for your answer, why is the ref wrong?


Look at this example when i have a buy trigger at point 1, then this point is already lower than the Lowest low 20 days ago, but here the number of bars is 14, so if i dont use ref(xx,-2), i think llv wil pick the current low = buy trigger as starting point... please correct me if i am wrong

i have the condition as you said

condition = BarsSince( LLV( L, 18 ) == L ) >= 15;
PlotShapes(condition*shapedigit9, colorGreen, 0, Low,-30);


but as you can see it is not working correctly. At point 1 it says its more than 15 bars from the lowest low within 18 bars, but that is not true, because it's only 12 bars away...

That's all what you need to know if lowest low is far by 15 bar away from your potential buy signal

TL = IIf(LLVBars(L,20)>=15,True,False);

You don't need that kind of IIfs.

TL = IIf(LLVBars(L,20)>=15,True,False);

is exactly the same as just this:

TL = LLVBars(L,20) >= 15; // you DO NOT need IIf as >= already returns True/False

Thanks Tomasz for the correction

Thx for the answers its very helpful