It’s likely more of a coding problem. You may need to add print statements to make sure everything is being assigned how you are wanting them to, and turn traceorders on to analyze what’s going on and when. When it comes to orders, in real time and market replay your code may be activating before the orders are submitted, causing errors. You’ll have to debug to find out where things are going wrong.