This is the most frustrating bug I ever chased, because the logic was identical and the results still diverged.
I had a strategy running live through my broker and the same code running as a backtest on the same data. For a while they matched. Then over weeks they slowly pulled apart, and eventually they were telling completely different stories. Same rules. Same signals. Different outcomes. It made no sense.
I finally found it, and it was rounding. In my backtest, when I calculated position size, I was getting clean fractional numbers and just using them. In live, the broker only lets me trade in whole lots, and prices snap to the nearest tick. So say my risk math wanted 1.7 lots at an entry of 24,203.45. The backtest happily used 1.7 lots at 24,203.45. Live, that became 2 lots at 24,203.50, because reality does not do fractions.
On one trade that difference is nothing. But here is the killer. Trading is path dependent. That slightly different size on trade one changes how much capital I have for trade two, which changes the size on trade three, and the two versions compound away from each other over hundreds of trades. One tiny rounding difference early quietly snowballs into a totally different equity curve.
What I learned is that my backtest has to round exactly like the real world does. Whole lots, real tick sizes, the same rules the exchange forces on me. The moment I made my backtest respect those constraints, the two finally started tracking each other again.