I couldn't figure out exactly what you need but I know what you wanted to do. I also wanted to start this project when my account expired for the umpteenth time. Well, from the point of view of a programmer, it seems that you are reinventing the wheel. Why didn't you use zigzag to find the swings and you went into the dark well of calculations? Just save its data and start checking with numbers close to the price. One of its advantages is that in the backtest you can increase and decrease the value of swings and calculate smaller swings.