I have tried to Cancel a working stop Loss order and it is not working.
Have tried a ton of different ways and will attach code below.
I am essentially trying to cancel a stop loss order that is working/accepted so that it does not fill overnight.
If there is an easier way to do this let me know, but ninja is filling stop loss orders during Trading Hours that I would not like to trade.
I realize it is just a working order so it is just doing what it is told, just giving you some background.
Would all be remedied if this order was able to be canceled and I could resend it on the first bar of the next trading day.
Let me know what the issue is please!
This is in my OnOrderUpdate()
if (order.Name == "Stop loss"){
myEntryOrder = order;
MyOrdersList.Add(order);
}
if (myEntryOrder != null && myEntryOrder == order){
// Check if myEntryOrder is cancelled.
if (myEntryOrder.OrderState == OrderState.Cancelled){
// Reset myEntryOrder back to null
myEntryOrder = null;
}
}
This is in my OnBarUpdate()
if(Time[0].Minute == 16){
foreach(Order order in MyOrdersList){
if(order.OrderState == OrderState.Working || order.OrderState == OrderState.Accepted){
CancelOrder(order);
}
}
Print("Should Cancel");
}
Also just in case, of course I have initialized the list
Comment