I'm trying to deal with a problem that shouldn't be too difficult to solve, but i'm having a very hard time figuring out an approach to work on.
Basically, i have a set of OHLC data:
>>print(df)
Open High Low Close Volume Date
Date
2020-11-02 00:00:00 396.68 401.01 396.44 400.70 41468.48318 2020-11-02 00:00:00
2020-11-02 00:30:00 400.68 404.50 400.61 402.45 35209.25068 2020-11-02 00:30:00
2020-11-02 01:00:00 402.48 403.14 400.62 401.89 18107.53656 2020-11-02 01:00:00
2020-11-02 01:30:00 401.88 402.88 401.26 402.48 13852.17215 2020-11-02 01:30:00
2020-11-02 02:00:00 402.49 403.85 398.82 401.17 21853.35028 2020-11-02 02:00:00
... ... ... ... ... ... ...
2020-11-04 19:30:00 401.88 403.88 401.88 402.46 17944.49509 2020-11-04 19:30:00
2020-11-04 20:00:00 402.50 404.23 397.72 399.59 41674.44864 2020-11-04 20:00:00
2020-11-04 20:30:00 399.60 402.26 399.40 401.21 18606.38545 2020-11-04 20:30:00
2020-11-04 21:00:00 401.20 403.15 400.79 402.70 14408.66482 2020-11-04 21:00:00
2020-11-04 21:30:00 402.69 403.01 401.74 402.71 8873.15569 2020-11-04 21:30:00
Given a fixed range that can be of 10 (so from 350 to 360, 351 to 361 and so on) detect when more than N number of candles closed inside that range. So basically this range needs to "slide" through the whole chart and find zones that meet the criteria i described above (more than N number of candles closed inside that range).
In this case, there are 6 candles closing in the white box, so it's what i'm looking for, note that the candle must not go through the box, it needs to only "start" there.
I tried to make it as clear and detailed as possible. I would like to post more code but i'm really struggling to find a way for this, even though i'm pretty sure it should be easy with Pandas, Numpy or scipy. Can anyone help me find a direction on this? Any kind of advice is welcome