Check for squeeze in last 20 candles in 5 mins

I have been struggling with barcount and havent been able to get a grip on it. I know how to check for lowest bollinger bandwidth (volatility squeeze) as on date but dont know how to loop back 20 candles from the current one to check for this condition and also to get a count of how many times it has occured.

@sudarshandujari without seeing your code and where you are failing to find a solution, it is difficult to be specific with an answer. I doubt that you need a loop for anything. A non-specific example,

Condition    =   // your indicator or condition
CountCondition = Sum( Condition, 20 );  // count of times it occured in past 20 bars

But this post is really where you need to begin,

Noted. Please see the code below :slightly_smiling_face:


middle = MA(C,20);
Plot(bandwidth,"Bollinger Bandwidth",colorRed,styleLine);



This will check for the condition in the most recent candle, i want to check whether this has occurred in the last 20 candles and hence the need to run a loop.


Only users with License Verified Badge are allowed to post on this forum.

@sudarshandujari did you test the solution I gave you? What was the problem with the attempted solution? Did it not count the occurrences of your condition in the most recent 20 bars? It works for me.

upper     = BBandTop(C,20,2);
lower     = BBandBot(C,20,2);
middle    = MA(C,20);

bandwidth = (upper-lower)/middle;
arrow_100 = bandwidth <= LLV(bandwidth, 100);

CountCondition = Sum( arrow_100, 20 );

I give up, good luck.


1 Like

Ah..i got it ..finally... Thank you so much... really appreciated.