Definition
The OnOrderUpdate() method is called everytime an order managed by a strategy changes state. An order will change state when a change in order quantity, price or state (working to filled) occurs.

•

Programming to this method is considered advanced programming and exposed for experienced programmers

NinjaTrader is a multi-threaded application and therefore it is extremely important to understand

•

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() 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().

•

As an example, the NinjaTrader core may have received "Working" and then "PartFilled" order state change events back from the broker API on thread "B" and at some point in time (milliseconds later) the NinjaTrader core will take these events and trigger the OnOrderUpdate() method in the strategy on thread "A". Thus, when the strategy receives the first "Working" state for an order, the IOrder object passed in will reflect the "Working" state although the actual order is really in a state of "Part Filled" which is truly reflected in the original IOrder object returned in any of the order methods such as EnterLong(). Of course, the OnOrderUpdate() method will subsequently receive the event for "PartFilled" state.

•

When connected to the Market Replay Connection, calling market order based methods such as EnterLong() and EnterShort() will result in order state events being fired prior to the order method return an IOrder object. This is done to ensure that all events are in sync at high speed market replays.

If you are relying on the OnOrderUpdate() method to trigger actions such as the submission of a stop loss order when your entry order is filled ALWAYS reference the properties on the IOrder object passed into the OnOrderUpdate() method.