Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

OnBarUpdate() / OnMarketData() Priority

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

    OnBarUpdate() / OnMarketData() Priority

    Hey Guys,

    My question has to do with the effects of an incoming tick on a Range Bar chart.

    Lets say a new tick completes the current bar. In this event, which Function Event will get fired first?

    The OnBarUpdate() event since the bar was just closed
    -or-
    The OnMarketData() event since new MarketData just came in.

    This is for a strategy with CalculateOnBarClose = true.

    Thanks
    mrlogik
    NinjaTrader Ecosystem Vendor - Purelogik Trading

    #2
    mrlogik,

    There is no guaranteed sequence. One or the other can come first.
    Last edited by NinjaTrader_JoshP; 09-16-2008, 08:54 AM.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Thank you Josh.

      My inquiry was to avoid a race condition within my own code. I will code based on your answer.

      mrLogik
      mrlogik
      NinjaTrader Ecosystem Vendor - Purelogik Trading

      Comment


        #4
        I'm wondering if one couldn't just have OnMarketData() call OnBarUpdate() when CalculateOnBarClose=true.
        -Alex

        Comment


          #5
          Alex,

          I am not sure what you mean. CalculateOnBarClose does not affect OnMarketData() so you can still do whatever you want in there even with CalculateOnBarClose = true.
          Josh P.NinjaTrader Customer Service

          Comment


            #6
            Originally posted by NinjaTrader_Josh View Post
            I am not sure what you mean. CalculateOnBarClose does not affect OnMarketData() so you can still do whatever you want in there even with CalculateOnBarClose = true.
            I was referring to your comment that there is no guaranteed sequence regarding which executes first, OnBarUpdate() or OnMarketData().

            I suggested a way toward guaranteeing a sequence, although I wasn't clear about it.

            Basically, if you want to guarantee the order of execution, you need to have OnBarUpdate() do nothing if OnMarketData() hasn't set a certain flag. OnMarketData() would set this flag and call OnBarUpdate() when needed. OnBarUpdate() would un-set the flag when finished.

            You would still need CalculateOnBarClose=true for efficiency, so that a do-nothing OnBarUpdate() doesn't get called multiple times per bar.

            Does that sound correct?

            -Alex

            Comment


              #7
              Alex,

              Not having a guaranteed sequence is the way multi-threaded programming works. Unfortunately this change will not be possible for various internal reasons. This is why the new methods are recommended for advanced programmers only.
              Josh P.NinjaTrader Customer Service

              Comment


                #8
                Josh, I don't understand why you seem to think I am suggesting a change. I'm well aware of how multithreading works; been doing that since before MS Windows ever existed.

                All I suggested was a way for a NinjaTrader user to guarantee the sequence, if that is what's desired. The coding method I suggested above should do it.

                -Alex

                Comment


                  #9
                  Thanks for the suggestion, we will take it under consideration.
                  RayNinjaTrader Customer Service

                  Comment


                    #10
                    Um, what...? Take what under consideration? Where did I suggest a change to NinjaTrader? I suggested a way that a user can get around the unpredicatbility inherent in multithreading.
                    -Alex

                    Comment


                      #11
                      Originally posted by anachronist View Post
                      I was referring to your comment that there is no guaranteed sequence regarding which executes first, OnBarUpdate() or OnMarketData().

                      I suggested a way toward guaranteeing a sequence, although I wasn't clear about it.

                      Basically, if you want to guarantee the order of execution, you need to have OnBarUpdate() do nothing if OnMarketData() hasn't set a certain flag. OnMarketData() would set this flag and call OnBarUpdate() when needed. OnBarUpdate() would un-set the flag when finished.

                      You would still need CalculateOnBarClose=true for efficiency, so that a do-nothing OnBarUpdate() doesn't get called multiple times per bar.

                      -Alex
                      I believe this is what Ray is talking about.
                      mrlogik
                      NinjaTrader Ecosystem Vendor - Purelogik Trading

                      Comment


                        #12
                        I thought so too, but that was really more a suggestion for you and other users, not for an internal change to NT. I thought that was clear.
                        -Alex

                        Comment

                        Latest Posts

                        Collapse

                        Topics Statistics Last Post
                        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                        0 responses
                        656 views
                        0 likes
                        Last Post Geovanny Suaza  
                        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                        0 responses
                        371 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
                        578 views
                        1 like
                        Last Post RFrosty
                        by RFrosty
                         
                        Working...
                        X