HistorySelectByPosition freezing entire terminal

 

Hello,


I am testing on an old account with thousands of closed orders on MT5, that is more than 4 years old.


When using functions like HistorySelectByPosition, the entire terminal freezes.

I use this function to track the profit of the closed trades when they close.

I have also profiled the EA, and 99% of the CPU usage comes from this function.


How to circumvent this problem?

 
Probably it is freezing because there are too many historical trades to iterate. Reduce the execution to a week for example and do not go too much far back in time.