I am using a managed approach to submit orders.
My strategy throws an exception when a position is not closed by the expected stop-loss or take-profit order.
At bar 6240 order "lG.18" was submitted (buy on stop).
At bar 6245 the strategy opened a new short position via order "sG.15" and submitted the bracket orders "sG.15.sl" and "sG.15.tp" in OnExecutionUpdate.
At each following bar, the stop price for the orders are adjusted.
According to the log output, the orders are changed at bar 6260:
- Order "sG.15.sl", BuyToCover, StopMarket at 56.53
- Order "lG18", Buy, StopMarket at 56.53.
But in fact, order "lG18" was executed before order "sG.15.sl" (this happens when using historical data, strategy was not used with realtime data yet).
Finally, such a scenario happens multiple times (e.g., when using different instruments or time frames) but this is the only case where the orders are not executed in the expected order.
So my question is:
- Is my assumption regarding the order of order execution correct?
- Is this only an issue with historical data?
Thanks!
[SIZE=8px][FONT=courier new][6260] OnBarUpdate Time=02/20/2019 15:26:00 -> Close=56.44 OnOrderUpdate NT-00095-34: Name=sG.15.sl; limit=0.0; StopPrice=56.53; Qty=1; Filled=0; State=ChangeSubmitted; Time=15:00:02; Err=NoError OnOrderUpdate NT-00095-34: Name=sG.15.sl; limit=0.0; StopPrice=56.53; Qty=1; Filled=0; State=Accepted; Time=15:00:02; Err=NoError OnOrderUpdate NT-00095-34: Name=sG.15.sl; limit=0.0; StopPrice=56.53; Qty=1; Filled=0; State=Working; Time=15:00:02; Err=NoError OnOrderUpdate NT-00094-34: Name=lG.18; limit=0.0; StopPrice=56.53; Qty=1; Filled=0; State=ChangeSubmitted; Time=15:00:02; Err=NoError OnOrderUpdate NT-00094-34: Name=lG.18; limit=0.0; StopPrice=56.53; Qty=1; Filled=0; State=Accepted; Time=15:00:02; Err=NoError OnOrderUpdate NT-00094-34: Name=lG.18; limit=0.0; StopPrice=56.53; Qty=1; Filled=0; State=Working; Time=15:00:02; Err=NoError [6261] OnBarUpdate Time=02/20/2019 15:28:33 -> Close=56.44 OnOrderUpdate NT-00094-34: Name=lG.18; limit=0.; StopPrice=56.5300; Qty=1; Filled=1; AvgP=56.53; State=Filled; Time=15:00:02; Err=NoError; Comment= Strategy 'G201902S/-1': Error on calling 'OnOrderUpdate' method on bar 6261: The names of opening and closing order do not match: opening name=sG.15 closing name=lG.18 but shall be sG.15.sl or sG.15.tp[/FONT][/SIZE]
Comment