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

OnOrderUpdate Versus OnExecution

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

    OnOrderUpdate Versus OnExecution

    Under what circumstances is it better to pull Price data by looking at IExecution objects versus IOrder objects.

    I understand that for some instruments a single order may have multiple executions. However, if I am trading a single futures contract is the Price data that comes from the IExecution object for the single execution for the order accurate than the information that might come from the corresponding IOrder object?

    I can see that one should always use IOrder objects and OnOrderUpdate to determine when the order officially reaches the filled state according to NT.

    I can also see that even though NT calls OnOrderUpdate before OnExecution, is it not true that the IExecution object for the order will be updated before the IOrder object reaches the filled state, and therefore the time from the IExecution object better reflects the time that my single contract order was filled?

    Are there other reasons to use OnExecution and IExecution objects in addition to OmOrderUpdate and IOrder objects?

    Thanks

    #2
    Hello x703jko,

    Thank you for your inquiry.

    Can you please clarify what you mean by "is the Price data that comes from the IExecution object for the single execution for the order accurate than the information that might come from the corresponding IOrder object?"

    What are you referring to by "price data"? Are you referring to AvgFillPrice in regards to IOrder objects vs Price in regards to IExecution objects?

    OnExecution() is always called after OnOrderUpdate() is called. If you're checking to see the time an order completely fills, both methods will return the same time. I would suggest testing this so you can see on your own.

    As an example:
    Code:
    private IOrder theOrder = null;
    
    protected override void OnBarUpdate()
    {
         if (theOrder == null && /*other entry conditions*/)
              EnterLong();
    }
    
    protected override void OnOrderUpdate(IOrder o)
    {
         if (o == theOrder && o.OrderState == OrderState.Filled)
              Print("OOU filled at: " + o.Time);
    }
    
    protected override void OnExecution(IExecution e)
    {
         if (e.Order == theOrder && e.Order.OrderState == OrderState.Filled)
              Print("OE filled at: " + e.Time);
    }
    Zachary G.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ZacharyG View Post
      Hello x703jko,

      Thank you for your inquiry.

      Can you please clarify what you mean by "is the Price data that comes from the IExecution object for the single execution for the order accurate than the information that might come from the corresponding IOrder object?"

      What are you referring to by "price data"? Are you referring to AvgFillPrice in regards to IOrder objects vs Price in regards to IExecution objects?

      OnExecution() is always called after OnOrderUpdate() is called. If you're checking to see the time an order completely fills, both methods will return the same time. I would suggest testing this so you can see on your own.

      As an example:
      Code:
      private IOrder theOrder = null;
      
      protected override void OnBarUpdate()
      {
           if (theOrder == null && /*other entry conditions*/)
                EnterLong();
      }
      
      protected override void OnOrderUpdate(IOrder o)
      {
           if (o == theOrder && o.OrderState == OrderState.Filled)
                Print("OOU filled at: " + o.Time);
      }
      
      protected override void OnExecution(IExecution e)
      {
           if (e.Order == theOrder && e.Order.OrderState == OrderState.Filled)
                Print("OE filled at: " + e.Time);
      }
      Zachary. Thanks for your response.

      I haven't tried the code you supplied yet. However, you may have partially answered my question. You state that both methods return the same fill time.

      However, which method gets me the fill information faster? We know that OnOrderUpdate is always called before OnExecution.

      If I only trade a single contract I can see a situation where my algorithms can commence monitoring the trade faster if my alg code is in OnExecute rather than in OnOrderUpdate since it's possible that the order executes after OnOrderUpdate is called.

      Is my thinking correct or am I missing something?

      Thanks

      Comment


        #4
        x703jko,

        The execution report would call the OnExecution method and the order report would call the OnOrderUpdate. Truly the order does not update until OnOrderUpdate is called. So OnExecution would show the execution and technically the previous order state before OnOrderUpdate is called.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by junkone, Today, 11:37 AM
        2 responses
        14 views
        0 likes
        Last Post junkone
        by junkone
         
        Started by frankthearm, Yesterday, 09:08 AM
        12 responses
        44 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by quantismo, 04-17-2024, 05:13 PM
        5 responses
        35 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by proptrade13, Today, 11:06 AM
        1 response
        7 views
        0 likes
        Last Post NinjaTrader_Clayton  
        Started by love2code2trade, 04-17-2024, 01:45 PM
        4 responses
        35 views
        0 likes
        Last Post love2code2trade  
        Working...
        X