Using an indicator you can only cancel a pending order (not market order):
// Order is pending to be executed
protected override void OnNewOrder(Order order)
{
base.OnNewOrder(order);
/**
* We can only cancel LIMIT/STOP orders. The MARKET orders cannot be canceled using an indicator. Must be using an exit strategy.
*
* On `OnNewMyTrade`, `OnNewOrder` and on `OnOrderChanged` we can't cancel order.
* On `OnNewOrder` we got this error message (for a MARKET order which cannot be canceled): (on the other methods we got no errors and can't cancel MARKET orders)
*
* ERROR: Notification title 'Order 1188105086/637764480088210017 Buy Market MNQH2@CME_Ind on DEMO0BF34 at 0/0 vol 1/0 exp 30.12.2021 Done cancel failed' message 'Order 637764480088210017/1188105086 for cancel not found.'.
*/
if (order.Type != OrderTypes.Market)
{
this.TradingManager.CancelOrder(order);
this.LogInfo($"[OnNewOrder] Cancelling order: price: { order.Price }, vol: { order.QuantityToFill }, direction: { order.Direction }");
}
}
It seems that you can close an active order if you implement an exit strategy, not as an indicator. I hope it helps!
Using an indicator you can only cancel a pending order (not market order):
It seems that you can close an active order if you implement an exit strategy, not as an indicator. I hope it helps!