the reason why this code is able to predict peaks and troughs very well is because it uses the behavior at time T to buy and sell at time T. And the input data of T is obtained from the difference between the closing price of T on that day and the closing price of T-1. Therefore, future information is included. If in doubt, do two things: 1. Move the input window forward by one day, 2. Write a backtest program to test it.
the reason why this code is able to predict peaks and troughs very well is because it uses the behavior at time T to buy and sell at time T. And the input data of T is obtained from the difference between the closing price of T on that day and the closing price of T-1. Therefore, future information is included. If in doubt, do two things: 1. Move the input window forward by one day, 2. Write a backtest program to test it.