Hi Team

I am running a code to set up a Take Profit (TP) and Stop Limit (SL) Order. Using second level data in the backtest, it seems there will be time when both the TP and SL will be filled within the same second slice. This is a problem obviously as I basically end up taking a Loss when there may not have been any need for (assumuing for instant that the TP would have been filled first). One way to adress this would be to use Tick data in the back test , but I think this is not possible (would love to be wrong on this and it would be great to see an example in python example if so).

Is there a workaround available to avoid this "simultaneity" problem so that only one of either the SL or the TP gets filled: 

Below is the code I run:

def OnOrderEvent(self, orderEvent): if orderEvent.Status == OrderStatus.Filled: order = self.Transactions.GetOrderById(orderEvent.OrderId) if orderEvent.FillQuantity>0: # SETTING Take Proit and Stop Loss Prices following Long Stop Order (in OnData section) self.TP =d.Decimal(orderEvent.FillPrice + d.Decimal(0.00005)).quantize(d.Decimal('1e-5')) self.SL =d.Decimal(orderEvent.FillPrice - d.Decimal(0.00005)).quantize(d.Decimal('1e-5')) self.StopLimitOrder(self.pair,-350000, self.TP ,self.TP ,"TP: {0}".format(self.TP)) self.LimitOrder(self.pair ,-350000, self.SL ,"SL: {0}".format(self.SL)) self.TPFILL=0 self.Log("D1: ENTRY FILL->TP/SL CREATED: TP: {0} SL: {1}".format(self.TP,self.SL)) elif orderEvent.FillQuantity<0 and order.Type ==OrderType.StopLimit: self.Debug("Canceling SL") self.Transactions.CancelOpenOrders(order.Symbol) elif orderEvent.FillQuantity<0 and order.Type ==OrderType.Limit: self.Debug("Canceling TP") self.Transactions.CancelOpenOrders(order.Symbol)

Example below from that Trade Log:

TimeSymbolPriceQuantityTypeStatus2017-02-03 13:32:06EURUSD1.07707-3500001Filled2017-02-03 13:32:06EURUSD1.07728-3500003Filled

 How would you address this issue?

Author