How to count how many times an event occurred in a time frame? V5

Viewed 82

As the screenshot shows, I am trying to detect VWAP rebounds and if you may see, there's a huge bearish breakout on the right side of the image. My theory is, if I could count the number of how many times a bounce occurred then (combining with the trend of VWAP) I could be able to predict potential breakouts. Also in bullish context.

Is there a function to do this counting? Or any idea of a scripted workaround?

I can get the moment of Market Open, it could be the best start of the counting. Couldn't make ta.cum() work.

enter image description here

1 Answers

You can use this to count how many times your condition was true in the given length:

cnt = math.sum(cond ? 1 : 0, len)
Related