Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

Partner 728x90

Collapse

Referencing orders by name.

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Referencing orders by name.

    Hi there,

    Is it still the recommended approach in OnOrderUpdate/ExecutionUpdate to reference orders by their name rather than by an object reference?

    Such as in this example from from the UnmanagedStrategyTemplate?

    Code:
            protected override void OnOrderUpdate(Order order, double limitPrice, double stopPrice, int quantity, int filled, double averageFillPrice, OrderState orderState, DateTime time, ErrorCode error, string nativeError)
            {
                  // Assign Order objects here
                  // This is more reliable than assigning Order objects in OnBarUpdate, as the assignment is not guaranteed to be complete if it is referenced immediately after submitting
                  if (order.Name == "Short limit entry")
                      shortEntry = order;
                else if (order.Name == "Long limit entry")
                      longEntry = order;
                else if (order.Name == "StopLossLong")
                      stopLossLong = order;
                else if (order.Name == "TargetLong")
                      targetLong = order;
                else if (order.Name == "StopLossShort")
                      stopLossShort = order;
                else if (order.Name == "TargetShort")
                      targetShort = order;​

    #2
    Hello kevinenergy,

    Thank you for your post.

    Yes, since it is possible that when you call the order object from outside of OnOrderUpdate() it could be null. It is best practice to assign the order object by its name in OnOrderUpdate().

    From the Help Guide:

    OnOrderUpdate() will run inside of order methods such as EnterLong() or SubmitOrderUnmanaged(), therefore attempting to assign an order object outside of OnOrderUpdate() may not return as soon as expected. If your strategy is dependent on tracking the order object from the very first update, you should try to match your order objects by the order.Name (signal name) from during the OnOrderUpdate() as the order is first updated.


    OnOrderUpdate() - https://ninjatrader.com/support/help...rderupdate.htm

    Advanced Order Handling - https://ninjatrader.com/support/help...r_handling.htm

    Please let me know if you have any other questions.
    Gaby V.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by mishhh, 05-25-2010, 08:54 AM
    19 responses
    6,189 views
    0 likes
    Last Post rene69851  
    Started by gwenael, Today, 09:29 AM
    0 responses
    4 views
    0 likes
    Last Post gwenael
    by gwenael
     
    Started by Karado58, 11-26-2012, 02:57 PM
    8 responses
    14,830 views
    0 likes
    Last Post Option Whisperer  
    Started by Option Whisperer, Today, 09:05 AM
    0 responses
    2 views
    0 likes
    Last Post Option Whisperer  
    Started by cre8able, Yesterday, 01:16 PM
    3 responses
    11 views
    0 likes
    Last Post cre8able  
    Working...
    X