Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Wrong bar index in OnOrderUpdate

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

    Wrong bar index in OnOrderUpdate

    Not a big issue but I thought I'd point it out anyway:

    Let's say for example I place (while backtesting) an entry order on bar n which is then filled on bar n+1. After the order has been filled OnBarUpdate is called (with the appropriate OrderState). However, in this method all data (CurrentBar, Time[0], ...) still contains the values from the last bar (n) where the order was placed.

    So when for example printing the date with each order placement and execution, it looks like the order has been placed and filled in the same bar. The order execution is however plotted on the correct bar in the chart.

    So far this has not been a big issue for me, it only messes up the debug output a bit. This might however become a problem if any actions are to be performed after the order has been executed (e.g. place another order) which depend on data of the bar on which the first order was filled (e.g. opening price).

    #2
    Not sure I follow.

    In a backtest, OnBarUdpate() is only called once for each bar thus, if you submit an order on bar n, the next time OnBarUpdate is called it will be bar n+1.
    RayNinjaTrader Customer Service

    Comment


      #3
      Yes, but let's say I place an order on bar n which is then filled on bar n+1 and OnOrderUpdate is called. The only problem is now that CurrentBar (and any other bar-related data) still contains the value n (even though we're at bar n+1 now).

      I hope my explanation makes more sense now.

      Comment


        #4
        To make it more clear: I access CurrentBar (or Time[0] or whatever) in OnOrderUpdate and I get the values from the previous bar.

        Edit: Typo, I wrote OnBarUpdate but meant on OnOrderUpdate!
        Last edited by terenyi; 08-21-2008, 08:06 PM.

        Comment


          #5
          I see..In your original post you said OnBarUpdate() not OnOrderUpdate() . In a backtest, things have to have a sequence and so OnOrderUpdate() can't be called after the close of the bar n+1 thus it needs to be called before bar n+1 is closed. I see your point but I don't think there is anything that can be done. In real-time, you can't count on any sequence since OnOrdeUpdate() will be called when NT received order state changes from the broker API.
          RayNinjaTrader Customer Service

          Comment


            #6
            Yes, what you say makes sense and it's not really an issue anyway since it only affects my debug output which is not that important. As I said, it might only be a problem if someone really needed to do something after an order has been filled which needs the data of the same bar.

            But since I came across this issue and I don't know much about the inner workings of NT, I thought it can't hurt to point it out.

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by cocoescala, 10-12-2018, 11:02 PM
            6 responses
            939 views
            0 likes
            Last Post Jquiroz1975  
            Started by gbourque, Today, 06:39 AM
            1 response
            4 views
            0 likes
            Last Post NinjaTrader_Erick  
            Started by cmtjoancolmenero, Yesterday, 03:58 PM
            1 response
            17 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by benmarkal, Yesterday, 12:52 PM
            3 responses
            23 views
            0 likes
            Last Post NinjaTrader_Gaby  
            Started by helpwanted, Today, 03:06 AM
            1 response
            20 views
            0 likes
            Last Post sarafuenonly123  
            Working...
            X