PDA

View Full Version : Orders not fully canceled


heech
11-03-2010, 03:35 PM
Hi there,

I'm still working on figuring out some of the odd behaviors behind CancelOrder... this is in reference to version 6.5.1000.17. There are still various times where CancelOrder() doesn't seem to clear Ninja's internal order tracking.

Meaning:

- say I have an ExitLongLimit() order...

- say I later cancel this order using CancelOrder()... (or, at the end of the day the exchange automatically cancels the order)...

- if, in the same strategy execution, I try to re-submit a ExitLongLimit() order (with the same signal names), NinjaTrader will reject the order while saying "a matching exit order already exists".

I don't really want to get into the exercise of creating an example, but I will if I have to. I'm just wondering if you guys have any insider tips about what else I can do, on version 6, to "clear" Ninja's internal view of these orders... that would allow me to resubmit.

NinjaTrader_RyanM
11-03-2010, 03:41 PM
Hello heech,

This reference sample should help with all the steps needed when using CancelOrder() (http://www.ninjatrader-support2.com/vb/showthread.php?t=18890)

Using CancelOrder() method to cancel orders

If you issue CancelOrder(), you also need to reset this order object to a null state before trying to submit again.

protected override void OnOrderUpdate(IOrder order)
{
// Checks for all updates to entryOrder.
if (entryOrder != null && entryOrder.Token == order.Token)
{
// Check if entryOrder is cancelled.
if (order.OrderState == OrderState.Cancelled)
{
// Reset entryOrder back to null
entryOrder = null;

// Replace entry limit order with a market order.
marketOrder = EnterLong(1, "market order");
}
}
}

heech
11-03-2010, 03:52 PM
Hi,

I'm already doing this...

And unless garbage collection is involved some how (and that doesn't make any sense), I don't see how me setting my applications' reference to null or not would affect whether Ninja doesn't allow me to submit another order.

heech
11-03-2010, 04:04 PM
If I understand how Ninja is designed, there's only a single thread for everything... including events. So, I don't have to worry about possible race conditions in OnOrderUpdate(), do I? Do I need to synchronize access?

NinjaTrader_RyanM
11-03-2010, 04:48 PM
We're not aware of issues in this area. I would evaluate the same strategy with version 7. If you run into anything, please share a simple strategy that we can use to see the issue.


OnOrderUpdate() (http://www.ninjatrader.com/support/helpGuides/nt7/onorderupdate.htm)

NinjaTrader is a multi-threaded application and therefore it is extremely important to understand (http://www.ninjatrader.com/support/helpGuides/nt7/onorderupdate.htm)

•This method guarantees that you will see each order state change in sequence
•This method does not provide an update for the most current state of an order but instead provides you an event notifying you of each state change in sequence and the relevant information on the order at the time the state changed
•CRITICAL: If you want to drive your strategy logic based on order fills you must use OnExecution() (http://www.ninjatrader.com/support/helpGuides/nt7/onexecution.htm) instead of OnOrderUpdate(). OnExecution() is always triggered after OnOrderUpdate(). There is internal strategy logic that is triggered after OnOrderUpdate() is called but before OnExecution() that can adversely affect your strategy if you are relying on tracking fills within OnOrderUpdate().