Python trading bot problem

I built a trading robot with the MetaTrader 5 api. Everything works great until the system crashes every few hours. It opens about 20 or 30 trades at a time on a currency pair in a candlestick, which often does not include SL or TP. In these cases, everything is wrong. The point of entry into trading, determining the volume, the interval between entry and paying attention to profits, everything is wrong.
I checked all parts of the program several times, but I did not find any problems. What can I do?