I am having trouble understanding why my stop isnt getting triggered.
Here is my strategy code.
1) I have a short position that was initiated using
EnterShort(trade_quantity,"entry")
protected override void OnBarUpdate() {//ON BAR STARTS // Handling Existing Shorts if (Position.MarketPosition == MarketPosition.Short) { // Stop Loss Adding if ( conditions for placing the stop loss) { ExitShortStopMarket(trade_quantity,fill_track,"stop","entry"); Print("stop placed"); Print(Times[0][0]); Print(stopOrder.ToString());}
2023-11-16 10:42:00 AM
orderId='NT-00028-1175' account='Backtest' name='stop' orderState=Working instrument='QQQ' orderAction=BuyToCover orderType='Stop Market' limitPrice=0 stopPrice=385.05 quantity=64 tif=Gtc oco='' filled=0 averageFillPrice=0 onBehalfOf='' id=-1 time='2023-11-16 10:42:00' gtd='2099-12-01' statementDate='2024-04-27'
Now notice the stopPrice for the order which is 385.05.
The below is a screenshot from the strategy. I highlighted in yellow where the "entry" short position was initiated, and then I am highlighting the wick of the candle at 10:48 that goes way pass the 385.05 stop price of the order.
So why is that stop order not triggered then?
Here is also how I assign names for the orders. Including it for completing purposes.
protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError) { // Assign order name if (order.Name == "entry") { entryOrder = order;} else if (order.Name == "stop") { stopOrder = order;} // Reset stopOrder to null if (stopOrder == order && (order.OrderState == OrderState.Filled || stopOrder.OrderState == OrderState.Cancelled)) { stopOrder = null;} }
Comment