OnOrderUpdate()
Previous Topic  Next Topic 

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.



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



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.



Method Return Value

This method does not return a value.


Method Parameters

IOrder order


Syntax
You must override the method in your strategy with the following syntax.


protected override void OnOrderUpdate(IOrder order)
{

}


Examples

private IOrder entryOrder = null;

protected override void OnBarUpdate()
{
    if (entryOrder == null && Close[0] > Open[0])
        entryOrder = EnterLong();
}

protected override void OnOrderUpdate(IOrder order)
{
    if (entryOrder != null && entryOrder.Token == order.Token)
    {
        Print(order.ToString());
        if (order.OrderState == OrderState.Cancelled)
        {
            // Do something here
            entryOrder = null;
        }
    }
}


Additional Reference Samples
Additional reference code samples are available the NinjaScript Educational Resources section of our support forum.