Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Is OnBarClose triggered on bar open?

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

    Is OnBarClose triggered on bar open?

    Hopefully this topic has not already been covered, but when I try to search this forum, it gives me a Forbidden error.

    I am using OnBarClose in my strategy, but I am wondering some details about how this really works, from the platform side.

    It is nearly impossible to tell (at least on most candle types) when the is last tick of a bar. On normal timed bars, you cannot really know until the new bar time. So if on a 1-minute chart, and it's the open candle, which will close at 12:35, then until 12:35 strikes, the platform cannot know whether another tick will slip in. So the first tick at/after 12:35:00 is really bar open.

    Or in my case, using range bars, when the range is full, you are on the last tick, unless it retraces. It it continues, then the next tick starts a new bar, and that means it's really OnBarOpen.

    So why does Ninja do OnBarClose, and what is the nitty-gritty of how it operates?

    I presume that really OnBarClose is triggered on bar open, but that it's called bar close to signify that functions like OnBarUpdate() will be called first, before any processing of the new tick which confirmed the old bar was done.

    Is that correct?

    #2
    Hello DerkWehler,

    A bar closes as a new bar opens. These happen at the same time.

    Yes, OnBarUpdate() will update with Calculate.OnBarClose after a bar has closed and a new bar has opened.

    You would be correct, it would impossible to predict which tick is the last tick of a bar as the tick is received. A bar will close and a new bar will open with the first tick received of the new bar.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_ChelseaB View Post
      Hello DerkWehler,

      A bar closes as a new bar opens. These happen at the same time.

      Yes, OnBarUpdate() will update with Calculate.OnBarClose after a bar has closed and a new bar has opened.

      You would be correct, it would impossible to predict which tick is the last tick of a bar as the tick is received. A bar will close and a new bar will open with the first tick received of the new bar.
      Thank you.
      Do you know why NT chose to do OnBarClose instead of OnBarOpen, which seems more realistic?

      Comment


        #4
        Hello DerkWehler,

        While I wouldn't have insight into decisions made by the development team years ago, I can give my opinions.

        If you were to call OnBarUpdate() once with Calculate.OnBarOpen it wouldn't have any information about the bar after that point. The high, low, close, and volume would only be for the first tick of the bar.

        Historical data is provided with the close time of the bar, open, high, low, close, and volume.

        Further, there are times a bar will close and update when there is no new bar to open. For example the last bar processed for a backtest in the Strategy Analyzer.

        As it is with OnBarClose, the bar closes and then runs logic over that bar, as at the same a new bar is constructed. This gives the final information about the bar.
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          Yes, I see your point. I guess what I really did not expect was that the information for an open bar would not exist (on my primary) before the bar closes. I would have thought that the bar is built (somewhere in the background), such that all the information existed [to be referenced], but my OnBarUpdate() was only called once at the end / beginning-of-new bar.

          Comment


            #6
            Hello DerkWehler,

            The price series itself is updated when OnBarUpdate() updates.
            Chelsea B.NinjaTrader Customer Service

            Comment


              #7
              Originally posted by DerkWehler View Post
              Yes, I see your point. I guess what I really did not expect was that the information for an open bar would not exist (on my primary) before the bar closes. I would have thought that the bar is built (somewhere in the background), such that all the information existed [to be referenced], but my OnBarUpdate() was only called once at the end / beginning-of-new bar.
              You can set Calculate to one of 3 settings.

              Try using Calculate.OnEachTick/OnPriceChange
              to see all price movements happening inside the
              bar (that is, while the bar is being built).

              The Calculate setting actually controls the frequency
              of how often your OnBarUpdate will be called.


              Comment


                #8
                Originally posted by DerkWehler View Post
                Hopefully this topic has not already been covered, but when I try to search this forum, it gives me a Forbidden error.
                The builtin search feature in this forum software
                truly sucks big donkey titties.

                Try using Google instead.

                -=o=-

                TIP: Always prefix your search with 'NinjaTrader'
                and you'd be amazed at what Google can find on
                these forums.

                For example, using Google and searching for
                'NinjaTrader OnBarUpdate' returns a wealth of
                information on these forums (and returns links
                to the help guide, too).

                Also, for all things C# related, I still use Google,
                but preface the search with 'C#', eg, 'C# DateTime'.

                Using Google is my goto for all things NinjaTrader
                and NinjaScript and C#.

                ​Just my 2˘.

                Comment


                  #9
                  Thanks David, good idea.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  Started by NullPointStrategies, Today, 05:17 AM
                  0 responses
                  35 views
                  0 likes
                  Last Post NullPointStrategies  
                  Started by argusthome, 03-08-2026, 10:06 AM
                  0 responses
                  124 views
                  0 likes
                  Last Post argusthome  
                  Started by NabilKhattabi, 03-06-2026, 11:18 AM
                  0 responses
                  64 views
                  0 likes
                  Last Post NabilKhattabi  
                  Started by Deep42, 03-06-2026, 12:28 AM
                  0 responses
                  41 views
                  0 likes
                  Last Post Deep42
                  by Deep42
                   
                  Started by TheRealMorford, 03-05-2026, 06:15 PM
                  0 responses
                  46 views
                  0 likes
                  Last Post TheRealMorford  
                  Working...
                  X