Can I please get some help with the below Algo. For some reason when take profit or stop loss is triggered it opens a new position in Oanda vs actually taking profit or closing the position if the price hits stop loss. It appears to work fine on the backtest but when I deploy it to a demo account it seems to have the above issue. As you can see from the code I use the limitOrder and StopMarketOrder for the triggers to set the stop loss / take profit price. In fact, even when I tried to liquidate the strategy to pause the algorithm it didn't work - I had to go into Oanda platform and manually close out the positions. 

marketOrderTicket = self.MarketOrder(symbol, quantity)

stopMarketOrderTicket = self.StopMarketOrder(symbol, -quantity, stop_loss)

limitOrderTicket = self.LimitOrder(symbol, -quantity, profit_target)

Any help would be much appreciated. Please excuse some messiness in the code I'm relatively new to this. 

Thank you in advance!