Reading the documentation, "this method sends a cancel request to the broker and does not guarantee that an order is completely cancelled. Most of the time you can expect your order to come back 100% cancelled". However, in my case this doesn't seem to apply:
-----------------------------------
private static double LOT_SIZE = 100000.0;
protected override void Initialize()
{
CalculateOnBarClose = true;
}
protected override void OnStartUp()
{
Unmanaged = true;
}
/// <summary>
/// Called on each bar update event (incoming tick)
/// </summary>
protected override void OnBarUpdate()
{
if (Historical)
{
return;
}
start();
}
int cnt = 0;
IOrder myOrder = null;
void start()
{
cnt++;
Print("Try #" + cnt);
if (cnt == 1) {
double volume = 0.05;
myOrder = SubmitOrder(0, OrderAction.Buy, OrderType.Market, ((int)(LOT_SIZE * volume)), 0.0, 0.0, "", "Test cancel");
} else if (cnt >= 2){
CancelOrder(myOrder);
Print("state -> " + myOrder.OrderState);
}
}
protected override void OnOrderUpdate(IOrder order)
{
if (myOrder != null && myOrder == order)
{
Print("OnOrderUpdate => order = " + order.ToString());
Print("OnOrderUpdate => state = " + order.OrderState);
}
}
}
-----------------------------------
And the output is:
-----------------------------------
**NT** Enabling NinjaScript strategy 'ATest/cd6ee739e6d04ff8b91588ba085fad26' : On starting a real-time strategy - StrategySync=WaitUntilFlat SyncAccountPosition=False EntryHandling=AllEntries EntriesPerDirection=1 StopTargetHandling=PerEntryExecution ErrorHandling=StopStrategyCancelOrdersClosePositio ns ExitOnClose=True/ triggering 30 before close Set order quantity by=Strategy ConnectionLossHandling=KeepRunning DisconnectDelaySeconds=10 CancelEntryOrdersOnDisable=False CancelExitOrdersOnDisable=True CalculateOnBarClose=True MaxRestarts=4 in 5 minutes
Try #1
OnOrderUpdate => order = Order='04eaf61ec6ec4d29a0bddd0a47a298c0/Sim101' Name='Test cancel' State=PendingSubmit Instrument='$EURUSD' Action=Buy Limit price=0 Stop price=0 Quantity=5,000 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='04eaf61ec6ec4d29a0bddd0a47a298c0' Gtd='1/1/0001 12:00:00 AM'
OnOrderUpdate => state = PendingSubmit
OnOrderUpdate => order = Order='04eaf61ec6ec4d29a0bddd0a47a298c0/Sim101' Name='Test cancel' State=Accepted Instrument='$EURUSD' Action=Buy Limit price=0 Stop price=0 Quantity=5,000 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='04eaf61ec6ec4d29a0bddd0a47a298c0' Gtd='1/1/0001 12:00:00 AM'
OnOrderUpdate => state = Accepted
OnOrderUpdate => order = Order='04eaf61ec6ec4d29a0bddd0a47a298c0/Sim101' Name='Test cancel' State=Working Instrument='$EURUSD' Action=Buy Limit price=0 Stop price=0 Quantity=5,000 Type=Market Tif=Gtc OverFill=False Oco='' Filled=0 Fill price=0 Token='04eaf61ec6ec4d29a0bddd0a47a298c0' Gtd='1/1/0001 12:00:00 AM'
OnOrderUpdate => state = Working
OnOrderUpdate => order = Order='04eaf61ec6ec4d29a0bddd0a47a298c0/Sim101' Name='Test cancel' State=Filled Instrument='$EURUSD' Action=Buy Limit price=0 Stop price=0 Quantity=5,000 Type=Market Tif=Gtc OverFill=False Oco='' Filled=5000 Fill price=1.0906 Token='04eaf61ec6ec4d29a0bddd0a47a298c0' Gtd='1/1/0001 12:00:00 AM'
OnOrderUpdate => state = Filled
Try #2
state -> Filled
Try #3
state -> Filled
Try #4
state -> Filled
**NT** Disabling NinjaScript strategy 'ATest/cd6ee739e6d04ff8b91588ba085fad26'
-----------------------------------
... looks like the order never gets cancelled, no matter how much I wait. This was run on Simulation account with EURUSD chart on 1 min frequency.
Perhaps something is wrong with my account? ... Am I missing anything in the code?...
I appreciate any suggestion or explanation regarding this behavior,
Thanks,
Sorin
Comment