Difference in backtest and actual code execution

This is duplicate query. Quoting Tomasz from How to use this site :