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

Coding order updates

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

    Coding order updates

    I'm aware of the OnOrderUpdate() and OnExecution() methods to call the info for any IObject order. In the help guide is said that :

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

    - OnExecution() will be triggered always after OnOrderUpdate()

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

    Thus, it seems that if you're monitoring the state an order, OnExecution(), using the correct IObject property, is the method that guarantees to have the most current and reliable state for internal strategy logic. With that said I have a big doubt:

    - Is there some case where actually will be better OnOrderUpdate() than OnExecution() ?

    - Why would it be important to know the state change in sequence, where it seems that having the most current state is more important ?
    Last edited by pstrusi; 12-18-2013, 06:28 AM.

    #2
    Further questions:

    - How do I call the quantity that has been partially filled within the OnExecution() method? will this give me that quantity : execution.Order.PartFilled as a numerical value ? This quantity is important to me cause I need to change Stop order quantity according to

    - How do I call the AvePrice for a partially or full filled within the OnExecution() method?

    - Where can I find all properties available when using OnExecution() method? Such as: execution.Order.OrderState == OrderState.Filled, execution.Order.OrderState == OrderState.PartFilled, execution.Order.OrderState == OrderState.Cancelled....etc ?
    Last edited by pstrusi; 12-18-2013, 09:00 AM.

    Comment


      #3
      Hello pstrusi,

      Thank you for your post.

      On your question about using OnOrderUpdate or OnExecution, the OnOrderUpdate() method is updated whenever the state of an order changes while the OnExecution() method is updated whenever you receive an execution or a fill on your orders.

      By using OnExecution this will ensure that your strategy has received the execution information from the broker which is used for internal signal tracking.

      You can print the part filled amount with execution.Quantity.

      For example:
      Code:
      if (execution.Order.OrderState == OrderState.PartFilled)
      {
      Print(execution.Quantity);
      }
      You can find the price of the fill with execution.Price. You can find the AvgFillPrice for the order with execution.Order.AvgFillPrice.

      For example:
      Code:
      Print(execution.Price + " - " + execution.Order.AvgFillPrice);
      You can find the available properties and methods available to an object with Intellisense. After typing the object variable name hit the period "." and a menu will appear. This menu is the Intellisense and lists the available properties and methods available. On a function, type the open parenthesis "(" and this will open the intellisense with the overloads for that method or function.

      Below is a link to the help guide on Intellisense.
      http://www.ninjatrader.com/support/h...tellisense.htm
      Chelsea B.NinjaTrader Customer Service

      Comment


        #4
        Hi Chelsea, thank you for your complete response, very instructive.

        Regarding cancelling orders procedure, I've seen that generally this is done in the OnOrderUpdate(), but I've done this snippet through OnExecution() cause I wouldn't like to receive a state of cancelled while in fact the order could be filled miliseconds before. Reading your response, it seems that if I want to cancel an order is better or the only way using OnOrderUpdate() than OnExecution(), what do you think?

        Code:
        protected override void OnExecution(IExecution execution)				
        {							
        	if (MyEntryOrder != null && MyEntryOrder == execution.Order)			
        	{			.		
        		if ( MyEntryOrder.OrderState == OrderState.Cancelled )		
        		{			
        			MyEntryOrder = null;
        		}	
        	}		
        }
        Last edited by pstrusi; 12-18-2013, 11:46 AM.

        Comment


          #5
          Hello pstrusi,

          An order being cancelled would be an order update and should be checked in OnOrderUpdate.

          Also, an order being cancelled does not trigger OnExecution. (At least I'm pretty sure after testing this).
          Chelsea B.NinjaTrader Customer Service

          Comment


            #6
            Thanks a lot Chelsea, that's what I needed to confirm and continue with my script

            Comment


              #7
              Chelsea,

              In regards to calling the quantity filled of an order:

              Is it the same set this: MyEntryOrder.Filled

              than this: execution.Quantity or MyEntry.Quantity

              Comment


                #8
                Hello pstrusi,

                No, MyEntryOrder.Filled and execution.Quantity would not be the same.

                The IOrder handle object MyEntryOrder.Filled will show the total that has been filled. So if there have been a part fill of 4, a part fill of 3, and a part fill of 2, this number would be 9.

                The execution object .Quantity will be the fill amount of that execution. So if the original order is already part filled to 10 and then another part fill of 4 is received, this number will be 4 as this is the quantity of this particular part fill.
                Chelsea B.NinjaTrader Customer Service

                Comment

                Latest Posts

                Collapse

                Topics Statistics Last Post
                Started by SantoshXX, Today, 03:09 AM
                0 responses
                11 views
                0 likes
                Last Post SantoshXX  
                Started by DanielTynera, Today, 01:14 AM
                0 responses
                2 views
                0 likes
                Last Post DanielTynera  
                Started by yertle, 04-18-2024, 08:38 AM
                9 responses
                41 views
                0 likes
                Last Post yertle
                by yertle
                 
                Started by techgetgame, Yesterday, 11:42 PM
                0 responses
                12 views
                0 likes
                Last Post techgetgame  
                Started by sephichapdson, Yesterday, 11:36 PM
                0 responses
                2 views
                0 likes
                Last Post sephichapdson  
                Working...
                X