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 ageeholdings, Today, 07:43 AM
    0 responses
    6 views
    0 likes
    Last Post ageeholdings  
    Started by pibrew, Today, 06:37 AM
    0 responses
    4 views
    0 likes
    Last Post pibrew
    by pibrew
     
    Started by rbeckmann05, Yesterday, 06:48 PM
    1 response
    14 views
    0 likes
    Last Post bltdavid  
    Started by llanqui, Today, 03:53 AM
    0 responses
    6 views
    0 likes
    Last Post llanqui
    by llanqui
     
    Started by burtoninlondon, Today, 12:38 AM
    0 responses
    12 views
    0 likes
    Last Post burtoninlondon  
    Working...
    X