You can use the keyword “summation” for this, let’s say you want to check how many candles during the past 25 ones have a close>open, then this number would be returned with:
1
N=summation[25](close>open)
From there, you can adapt to what you really want, replace 25 with the fixed or calculated number of candles you want to look back in time, or replace close>open with conditions for another type of candle you want…