this.LongOrder = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.Limit, this.OrderQuantity, longPrice, 0, oco, "Long Order");
In my case, this.OrderQuantity = 1, longPrice = 4140.25 and was submitted at a current price of 4130 on a candle with a high of 4131.25. The problem is that the Strategy Analyzer is immediately filling the long limit order at the high of the current candle instead of waiting for the target price to hit.
This is the dump of the order object from the above code:
orderId='NT-00000-137' account='Backtest' name='Long Order' orderState=Working instrument='ES 06-23' orderAction=Buy orderType='Limit' limitPrice=4140.25 stopPrice=0 quantity=1 tif=Gtc oco='oco1120290241' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-04-13 09:30:00' gtd='2099-12-01' statementDate='2023-04-18'
And this is the dump of the filled order from OnExecutionUpdate():
orderId='NT-00000-137' account='Backtest' name='Long Order' orderState=Filled instrument='ES 06-23' orderAction=Buy orderType='Limit' limitPrice=4140.25 stopPrice=0 quantity=1 tif=Gtc oco='oco1120290241' filled=1 averageFillPrice=4131.25 onBehalfOf='' id=-1 time='2023-04-13 09:30:00' gtd='2099-12-01' statementDate='2023-04-18'
Note the limitPrice of 4140.25 and the averageFillPrice of 4131.25 -- that is not correct as far as I can tell, I'm calling SubmitOrderUnmanaged correctly for a long limit order. The only way I can get it work correctly is to change it to a stop limit order and use the same price in the limitPrice and stopPrice parameters, like so:
this.LongOrder = SubmitOrderUnmanaged(0, OrderAction.Buy, OrderType.StopLimit, this.OrderQuantity, longPrice, longPrice, oco, "Long Order");
Comment