I've recently started with algorithmic trading, helping some forex friends of mine to code their successful strategy.

I began by recreating the strategy in a research notebook, making sure to feed the market data into the algorithm with a loop, to prevent the possibility of look-forward bias, and I calculated the profit or loss of each trade by subtracting the closing price at the trade exit by the closing price of the entry. 

After optimization we were quite happy with how reliable and profitable the strategy was, and we ended up testing it in the research notebook over 200,000+ bars.

The next step was to then rewrite it in the backtesting environment using the Lean engine, and even after meticulously double checking that they were essentially identical, the results differed between the two.


If you can give me more insight as to what I might be failing to take in to account, or what I might be missing, I'd greatly appreciate it. Thanks.