Ok guys, thanks to some friends of mine, it came out that I was wrongly using bracket orders.
I should have used the following logic:

if buy_condition: self.buy(size=self.p.size) self.limitOrderSL = self.sell(size=self.p.size, exectype=Order.Stop, price=stop_price) self.limitOrderTP = self.sell(size=self.p.size, exectype=Order.Limit, price=profit_price) if close_condition: self.close() self.cancel(self.limitOrderSL) self.cancel(self.limitOrderTP)

Regards