Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Bar(Series).Count vs CurrentBar Error

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

    Bar(Series).Count vs CurrentBar Error

    I am using the XXXXX.Count property for the Open/Time parameters on a multi-series timeframe. I haven't checked this on a single TimeFrame, but the results don't seem to line up with the instructions (or how NT7 handled this property):
    http://ninjatrader.com/support/helpG...s/?seriest.htm

    The .Count property returns over 2000 values in the Series, but when I try to access a value that is 17 bars back, I get the "Object Referenced not set to an instance of an object". This number was very suspect to begin with since I am only on BAR 6. Is this being fixed, or do I need to change my code to monitor "CurrentBar" for the max index values?



    CurrentBar:6 CurrentBars[1]:6
    Open.Count:2343
    Opens[0].Count:2343
    Opens[0][4]:-3
    Opens[0][6]:0
    Opens[0][7]:-23
    TIME CurrentBar:6 CurrentBars[1]:6
    Time.Count:2343
    Times[0].Count:2343
    Times[0][4]:8/11/2015 6:06:00 PM
    Times[0][6]:8/11/2015 6:01:00 PM
    Times[0][7]:8/11/2015 4:45:00 PM
    Indicator 'MyIndicator': Error on calling 'OnBarUpdate' method on bar 6: Object reference not set to an instance of an object.

    #2
    same problem...

    thank you NJ_AMC for this point...I had the same error...
    just hoping it may be fixed...

    Comment


      #3
      Hello,

      Am I correct in assuming that you are on Bar # 6 on historical data when this error occurs, or is Bar # 6 a realtime bar? Opens[0].Count will return a count based upon all of the bars on the chart, even when processing historical data. So, if you are loading 2343 bars on your chart total, then during the historical data processing you are checking 17 bars back on Bar # 6, then there would not be anything to look for at that point in the historical data.

      So Opens[0].Count is not being incremented as each historical bar is processed, but is set once when the script loads, and is incremented only by real-time bars.
      Dave I.NinjaTrader Product Management

      Comment


        #4
        Originally posted by NinjaTrader_Dave View Post
        Hello,

        Am I correct in assuming that you are on Bar # 6 on historical data when this error occurs, or is Bar # 6 a realtime bar? Opens[0].Count will return a count based upon all of the bars on the chart, even when processing historical data. So, if you are loading 2343 bars on your chart total, then during the historical data processing you are checking 17 bars back on Bar # 6, then there would not be anything to look for at that point in the historical data.

        So Opens[0].Count is not being incremented as each historical bar is processed, but is set once when the script loads, and is incremented only by real-time bars.
        Thanks, it was historical. This needs to go into the code breaking section as NT7 didn't handle historical data the same way. Also, the instructions need to be updated to state it is only valid for real-time.

        I will have to figure out how to pass the CurrentBar value into the subroutines as this is a new requirement.

        Comment


          #5
          I've just tested in NinjaTrader 7 to be sure, and this particular behavior is present in 7 as well. Rather than iterating from 0 on historical data, things like Opens[0].Count return the total number of bars on the chart right away. We do this to avoid the extra processing work of updating multiple collections on each historical bar loaded on a chart. This would not have too much of an impact if you are loading 50 bars or so, but for people who load hundreds or thousands of bars at once, you can imagine the impact it could have.

          I am going to add a note to various help guide pages to make this more clear, so I'm glad that you were able to identify this as a potential point of confusion.

          As you mentioned, the best way to avoid this issue is to check CurrentBar to ensure that there are enough bars back when processing historical data. If you're going to look 7 bars back on historical data, for example, adding an "if(CurrentBar > 7)" condition can avoid that kind of error.

          Also, CurrentBar can be used as a reliable gauge of the number of bars available to look look back at any point when processing historical data.
          Dave I.NinjaTrader Product Management

          Comment


            #6
            Thanks Dave,

            Some of us don't use charts as I just need to launch something into the strategy tab. The code I am using worked under NT7, so the only think I can figure is maybe the "DateTime" isn't initialized for the entire "Count" of the series under NT8 where it may have been on NT7.

            Your proposal works fine if my ninja script code was Flat, but unfortunately, there are multiple classes and now I have a new requirement I need to work into the structure.

            Comment


              #7
              Originally posted by NJA_MC View Post
              Thanks Dave,

              Some of us don't use charts as I just need to launch something into the strategy tab. The code I am using worked under NT7, so the only think I can figure is maybe the "DateTime" isn't initialized for the entire "Count" of the series under NT8 where it may have been on NT7.

              Your proposal works fine if my ninja script code was Flat, but unfortunately, there are multiple classes and now I have a new requirement I need to work into the structure.
              Not to quibble. but the Bars objects do not depend on the strategy being on a chart: they exist regardless, and can be processed. Am I confused?

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by corman, Today, 02:02 PM
              1 response
              10 views
              0 likes
              Last Post NinjaTrader_ChelseaB  
              Started by Uregon, Today, 12:12 PM
              1 response
              7 views
              0 likes
              Last Post NinjaTrader_Kate  
              Started by kerplunk1899, Today, 10:03 AM
              1 response
              19 views
              0 likes
              Last Post NinjaTrader_Kate  
              Started by rexsole, Today, 10:20 AM
              1 response
              11 views
              0 likes
              Last Post NinjaTrader_RyanS  
              Started by pjsmith, Today, 03:01 AM
              6 responses
              18 views
              0 likes
              Last Post bltdavid  
              Working...
              X