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

Identifying Close of Bar when CalculateOnBarClose = false

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

    Identifying Close of Bar when CalculateOnBarClose = false

    When CalculateOnBarClose = false the user guide states that on a tick by tick strategy the only way you know when a bar is closed is when the FirstTickOfBar is true. What about interval based bars? Is there a way to know when the last tick is being processed? Why not have an attribute LastTickOfBar ??

    #2
    The problem is you will not know if the tick is the last tick of the bar until the first tick of the new bar. This is the case for interval based bars too. The only way we know a new 1min bar is opening is when the incoming tick comes in with a timestamp of the new 1min. Until that tick comes in we have no idea if the current tick we are handling will be the last tick of the current 1min bar.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      (I realize that this is an old thread, but I'm dealing with this issue now...)

      Josh mentions that the only way that NT knows that a bar is closed is when the first tick of a new bar comes in.

      That does not seem to jive with the fact that if CalculateOnBarClose == true, then OnBarUpdate is called with (what is in effect) the last tick of the bar.

      I'm assuming that the NT internal code queues the OnBarUpdate event to the strategy code with the previous bar when it sees the first tick of a new bar and CalculateOnBarClose == true. Couldn't it do the same thing if CalculateOnBarClose == false and have a LastTickOfBar flag ?

      The way things currently work makes strategy code very messy if you want to handle both settings of CalculateOnBarClose. Lots of "if" statements like:

      if (CalculateOnBarClose == false && FirstTickOfBar == true) closingBarPrice = Close[1];
      else closingBarPrice = Close[0];

      Getting rid of the FirstTickOfBar flag and having a LastTickOfBar flag would eliminate all this messy code.

      Comment


        #4
        BAltman,

        CalculateOnBarClose = true triggers OnBarUpdate() events when the first tick of the next bar is received. The closing event of a bar is only determined when the next bar begins.

        If you want to use CalculateOnBarClose = false you can do so and then use if(FirstTickOfBar) and then offset all your [] indexing by 1. So [0] would be [1] to get the closing price of the previous bar. These are your two options available for checking the last tick of a bar.
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          FirstTickOfBar in multi-timeframe indicator/strategy

          Josh,

          Does FirstTickOfBar work in indicators as well as strategies ?
          What if the strategy/indicator has data series for multiple frames ? It seems to need an array FirstTickOfBars, so one can check each timeframe...

          Comment


            #6
            splat, it would be applicable to both - you can check it in the respective BarsInProgress context for MultiSeries use.
            BertrandNinjaTrader Customer Service

            Comment


              #7
              Thanks, Bertrand.

              I am still not quite clear about how that works though. I understand that when using CalculateOnBarClose = true with multiple timeframes, OnBarUpdate will be called for each bar close, so if (say) a 1min and 5min bar close at the same time, OnBarUpdate will be called twice (with different BarsInProgress values). But if CalculateOnBarClose = false, then OnBarUpdate will be called on "each incoming tick". Does it in fact get called on each incoming tick for *each* timeframe (e.g. N times on each tick, given N timeframes), with different BarsInProgress values? Or does it get called once on each incoming tick for the primary data series, plus an extra call whenever a secondary series bar has its first tick (with different BarsInProgress value) ? (If only called exactly once for each tick, I cannot see how your suggestion would work.)

              Comment


                #8
                splat,

                When using CalculateOnBarClose = false, it will be called once for every single tick for each BarsInProgress. If you have 1min and 5min, you will have the tick processed once for the 1min and once for the 5min.
                Josh P.NinjaTrader Customer Service

                Comment


                  #9
                  Thanks, Josh, that is clear to me now.

                  Comment

                  Latest Posts

                  Collapse

                  Topics Statistics Last Post
                  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  
                  Started by StockTrader88, 03-06-2021, 08:58 AM
                  44 responses
                  3,983 views
                  3 likes
                  Last Post jhudas88  
                  Working...
                  X