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

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 llanqui, Today, 03:53 AM
                        0 responses
                        2 views
                        0 likes
                        Last Post llanqui
                        by llanqui
                         
                        Started by burtoninlondon, Today, 12:38 AM
                        0 responses
                        10 views
                        0 likes
                        Last Post burtoninlondon  
                        Started by AaronKoRn, Yesterday, 09:49 PM
                        0 responses
                        14 views
                        0 likes
                        Last Post AaronKoRn  
                        Started by carnitron, Yesterday, 08:42 PM
                        0 responses
                        11 views
                        0 likes
                        Last Post carnitron  
                        Started by strategist007, Yesterday, 07:51 PM
                        0 responses
                        14 views
                        0 likes
                        Last Post strategist007  
                        Working...
                        X