Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Can OnOrderUpdate() track two IOrder objects?

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

    Can OnOrderUpdate() track two IOrder objects?

    Hi,

    I'm posting a lot of questions today, apologies, but I've been pushing myself to self-learn as much as possible, but in this question I'm sure someone has an immediate answer ready:

    I want to track two IOrder objects, one is EntryOrder, and one is ExitOrder

    I just found out that you can't do this:

    protected override void OnOrderUpdate(IOrder EntryOrder)
    {
    process entryorder state changes
    }

    AND at the same time have

    protected override void OnOrderUpdate(IOrder ExitOrder)
    {
    process exit order state changes and then submit new entry order
    }


    And you also can't do this:

    protected override void OnOrderUpdate(IOrder EntryOrder, ExitOrder)
    {
    process entryorder and exitorder state changes
    }


    And the only thing I can think of is to keep updating the single IOrder values with entry and exit information, but then once I've filled IOrder object with exit order values, I won't be able to reference things like my entry order quantity without creating new variables to hold them.

    So then, does anyone know a way to create and track the updates of two IOrder objects?

    Thank you again!

    #2
    Hello RunnrX,
    Yes, you can track multiple orders. You can for example assign a name to the order and can track the order in the OnOrderUpdate with that name.

    For example if your entry and exit orders are
    Code:
    EnterLong("Long Entry");
    ExitLong("Exit Long", "Long Entry");
    Then you can track the orders in the OnBarUpdate as:
    Code:
    protected override void OnOrderUpdate(IOrder order)
    {
    	if (order != null)
    	{
    		if (order.Name == "Long Entry")
    		{
    			//do something
    		}
    		else if (order.Name == "Exit Long")
    		{
    		 //do something
    		}
    	}
    }
    Please let me know if I can assist you any further.
    JoydeepNinjaTrader Customer Service

    Comment


      #3
      Thank you for replying..

      so I can do it like how you explained, I'll just have to change my code to work that way.. so I won't be able to do what I was first hoping to do, which was have two order objects, like this:

      IOrder EntryOrder...

      EntryOrder = SubmitOrder ( buy stop for 10,000 etc etc);

      then IOrder ExitOrder

      OnOrderUpdate (IOrder EntryOrder)
      {
      if (EntryOrder.OrderState = OrderState.Filled)
      ExitOrder = SubmitOrder(0, OrderAction.Sell, OrderType.Stop, EntryOrder.Quantity, 0, (EntryOrder.AvgFillPrice * (1 - userstoplosspercent)), "", "Stop Loss");
      }

      and then

      OnOrderUpdate (IOrder ExitOrder)
      {
      if (ExitOrder.OrderState = OrderState.Filled)
      EntryOrder = SubmitOrder(get back in again)
      }


      It looks like I'll have to crate a set of variables to hold the values of entry order that I wanted to reference, before I overwrite the order object values with the new stop loss order values, if I want my exit order to get its quantity and price information from the avgfillprice and quantity of the entry order is that all correct? Thanks!

      Comment


        #4
        Hello RunnrX,
        You can directly check for the orders if you have assigned an IOrder object to your orders. Please use the below code as a reference
        Code:
        protected override void OnOrderUpdate(IOrder order)
        {
        	if (order != null)
        	{
        		if (order == EnteyOrder)
        		{
        			//do something
        		}
        		else if (order == ExitOrder)
        		{
        			//do something
        		}
        		
        	}
        }
        JoydeepNinjaTrader Customer Service

        Comment


          #5
          That's great to hear! Thank you!

          Comment


            #6
            Originally posted by RunnrX View Post
            Thank you for replying..

            so I can do it like how you explained, I'll just have to change my code to work that way.. so I won't be able to do what I was first hoping to do, which was have two order objects, like this:

            IOrder EntryOrder...

            EntryOrder = SubmitOrder ( buy stop for 10,000 etc etc);

            then IOrder ExitOrder

            OnOrderUpdate (IOrder EntryOrder)
            {
            if (EntryOrder.OrderState = OrderState.Filled)
            ExitOrder = SubmitOrder(0, OrderAction.Sell, OrderType.Stop, EntryOrder.Quantity, 0, (EntryOrder.AvgFillPrice * (1 - userstoplosspercent)), "", "Stop Loss");
            }

            and then

            OnOrderUpdate (IOrder ExitOrder)
            {
            if (ExitOrder.OrderState = OrderState.Filled)
            EntryOrder = SubmitOrder(get back in again)
            }


            It looks like I'll have to crate a set of variables to hold the values of entry order that I wanted to reference, before I overwrite the order object values with the new stop loss order values, if I want my exit order to get its quantity and price information from the avgfillprice and quantity of the entry order is that all correct? Thanks!
            OnOrderUpdate(), from its description (and even from the connotations of its name as well) would seem to be an event handler, rather than a method, so you cannot pass OnOrderUpdate() a specific object. (I am aware that the NT docs call it a method. I am just saying ...)

            Comment


              #7
              Originally posted by koganam View Post
              OnOrderUpdate(), from its description (and even from the connotations of its name as well) would seem to be an event handler, rather than a method, so you cannot pass OnOrderUpdate() a specific object. (I am aware that the NT docs call it a method. I am just saying ...)
              You're right that it's an event handler. I am frankly totally new to C# and just have a little basic experience in C++ and Delphi, so I was just following the NT7 help documentation, where it looked like you were supposed to pass the IOrder object "EntryOrder" into OnOrderUpdate like this

              OnOrderUpdate(IOrder EntryOrder)

              because if I left the brackets blank I got a compile error. I only have a loose conceptual grasp on order objects, event handlers, and how they work, but I have been able to get my strategy to properly manage at least one order object and check for updates like being OrderState.Filled, being OrderState.Working, but as for how to watch two order objects at once, had no idea until NinjaTrader_Joydeep posted the part below that I'm going to try out when I get back home today.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by Geovanny Suaza, 02-11-2026, 06:32 PM
              0 responses
              652 views
              0 likes
              Last Post Geovanny Suaza  
              Started by Geovanny Suaza, 02-11-2026, 05:51 PM
              0 responses
              370 views
              1 like
              Last Post Geovanny Suaza  
              Started by Mindset, 02-09-2026, 11:44 AM
              0 responses
              109 views
              0 likes
              Last Post Mindset
              by Mindset
               
              Started by Geovanny Suaza, 02-02-2026, 12:30 PM
              0 responses
              574 views
              1 like
              Last Post Geovanny Suaza  
              Started by RFrosty, 01-28-2026, 06:49 PM
              0 responses
              577 views
              1 like
              Last Post RFrosty
              by RFrosty
               
              Working...
              X