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 and OnExecutionUpdate Context

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

    OnOrderUpdate and OnExecutionUpdate Context

    Hi,

    I have a strategy uses two bars series of differing time frames. The first (primary) series uses a five minute time frame. The second series uses a one second time frame. I place all my orders on the secondary series with the one second time frame.

    I have noticed that event calls to OnOrderUpdate and OnExecutionUpdate seem to execute in the context of the primary series, even though I entered the orders against the secondary series. In other words, when my strategy receives the call into OnOrderUpdate, the BarsInProgress value is always 0. I am curious as to why this is. It does not make sense. It is not a big deal since I can still access the secondary bar series data using the BarsArray object and the higher level Closes, Opens, Times, etc. objects. But it surprised me when I attempted to access bar data within these event procedures. I assumed the context would be the series that the orders were placed against.

    Thanks,

    CJ

    #2
    Hello CJ,

    OnOrderUpdate and OnExecutionUpdate() are not data driven events. These are not being triggered from either series. These are triggered when the order changes states. An order may be submitted and may not fill for a while. It may fill when no bar is closing. It's not tied to the data. It's tied to the order updating and this is in another thread that runs independently of the data subscription thread.

    If BarsInProgress is 0 when OnOrderUpdate() is triggered, then that just happens to be what the series was that most recently updated OnBarUpdate(). This could be either series.

    You can use prints to check when the order is being submitted and what BarsInProgress is when the order is submitted.

    if (Close[0] > Open[0])
    {
    Print(string.Format("{0} | Submitting order, BarsInProgress is: {1}", Time[0], BarsInProgress));
    EnterLong();
    }

    Below is a link to a forum post that demonstrates using prints to understand behavior.


    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Hi Chelsea,

      That's exactly how I discovered this issue. I have debug statements in OnOrderUpdate() that print out the Bar time (Time[0].ToString()) and it always showed the time of the primary series bars when I used Time[0], never the secondary series which is what I place my orders on. If it happens to be based on what series most recently updated OnBarUpdate(). then I would expect many more log entries displaying the secondary series times given one-second vs five minutes.

      It is not a big deal since I got what I needed by referencing the secondary series time (Time[1][0].ToString()) in my Debug.Print statement. I was just curious about this.

      Anyway, thanks for the reply.

      CJ

      Comment


        #4
        Hello CJ,

        If Calculate is OnBarClose, the Close bar is not the bar used for the order fill. The Closed bar is evaluated after it is closed. Then the order is submitted as the new bar opens. The order appears on the open of the next bar.

        Chelsea B.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by WaleeTheRobot, 01-07-2024, 10:07 AM
        18 responses
        501 views
        2 likes
        Last Post EllisEdi  
        Started by SteveReiza, Today, 09:41 PM
        0 responses
        2 views
        0 likes
        Last Post SteveReiza  
        Started by astor, Today, 09:20 PM
        1 response
        8 views
        0 likes
        Last Post astor
        by astor
         
        Started by astor, Today, 09:19 PM
        0 responses
        2 views
        0 likes
        Last Post astor
        by astor
         
        Started by Kraken29, 02-26-2024, 10:40 AM
        2 responses
        18 views
        0 likes
        Last Post Kraken29  
        Working...
        X