I've got pandas dataframe with candle highs and lows. I've made new column, which shows pivot points (if the value in cell is lowest\highest between two above it an two below it, it has value 1 for lowest or 2 for highest , else 0) example:
| date | high | low | pivot | takes pivot |
|---|---|---|---|---|
| 01.01.2020 | 207 | 204 | 0 | |
| 02.01.2020 | 208 | 205 | 0 | |
| 03.01.2020 | 209 | 205 | 2 | |
| 04.01.2020 | 207 | 203 | 0 | |
| 05.01.2020 | 206 | 202 | 0 | |
| 06.01.2020 | 205 | 200 | 0 | |
| 07.01.2020 | 204 | 199 | 1 | |
| 08.01.2020 | 206 | 201 | 0 | |
| 09.01.2020 | 207 | 202 | 0 | |
| 10.01.2020 | 208 | 205 | 0 | |
| 11.01.2020 | 210 | 207 | 0 | |
| 12.01.2020 | 212 | 209 | 0 | |
| 13.01.2020 | 214 | 210 | 2 | |
| 14.01.2020 | 207 | 204 | 0 | |
| 15.01.2020 | 203 | 202 | 0 | |
| 16.01.2020 | 201 | 198 | 0 | |
| 17.01.2020 | 199 | 196 | 0 |
i need to find exact candles that made new high or low(according to pivotpoints,not all candles), something like this: for example in this table takes pivot=1 for 16.01.2020 and takes pivot=2 for 11.01.2020 only(takes pivot = 1 for lows and 2 for highs)
I've tried to make a loop, but cant really understand how exactly it should look
Code
rollingand usenp.selectdf
Example Code