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

Confused by error log

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

    Confused by error log

    I'm getting the following error on an indicator I developed, but I can't make sense out of it. As you see, I'm on bar 28 from my chart but it says there are only 4 bars on the chart. The other element of what makes this strange is that it only happens when I restart NinjaTrader on a chart with this indicator already defined. It doesn't happen if I start the indicator from the GUI. I have a test on CurrentBar to ensure it is greater than any series. Any idea why this might happen?

    "Error on calling 'OnBarUpdate' method on bar 28: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."
    Attached Files

    #2
    Hello dweems,

    Strategies and indicators start processing from the first bar, CurrentBar 0, in OnBarUpdate() when processing the historical data. They don't start with the last bar, in your case CurrentBar 28.

    If you call Close[1] when CurrentBar is 0, this is the error you will get.

    Below is a link to a forum post on index errors.
    Hello, I want to create an indicator that show data in a chart but calculate in other charttime different to the time of the chart where is showed. For example:


    Make sure CurrentBar is greater than any barsAgo indexes you use.
    Chelsea B.NinjaTrader Customer Service

    Comment


      #3
      I'm confused why you say my "last" bar starting at 28. As the error message states, CurrentBar is 28, not 4. I have code that returns from OnBarUpdate() if CurrentBar is less than 28. This seems to be something to do with restarting a chart after shutdown since it works fine if I start it after the chart has loaded. I thought CurrentBar indicates what bar the chart is on when entering OnBarUpdate(). And in no situation do I have a barsAgo field that exceeds 28. Indeed, the error message indicates it fails on barsAgo = 5. Indeed, as a test, I doubled the test value to 56 and it still fails. Another oddity : even though the message appears in the log, the indicator runs to completion anyway. Is it possible the indicator is running once before the chart loads, fails at that point, and then runs again afterward?

      Comment


        #4
        Hello dweems,

        What is the specific line of code with the index that is causing the error?
        (Meaning if you comment that line out, the error stops)

        Also, no, I would not expect the indicator to continue working after experiencing an index error.

        Can you reproduce after closing all workspaces and opening a new blank workspace with a new blank chart, with only this one indicator added?

        Can you copy the line of code (and the check for enough bars) to a new script without copying any other code and still reproduce?
        Chelsea B.NinjaTrader Customer Service

        Comment


          #5
          And no, the error is not on bar 5. That is just an example of that type of error. Your error is on bar 28.
          eDanny
          NinjaTrader Ecosystem Vendor - Integrity Traders

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Option Whisperer, Today, 09:05 AM
          0 responses
          1 view
          0 likes
          Last Post Option Whisperer  
          Started by cre8able, Yesterday, 01:16 PM
          3 responses
          11 views
          0 likes
          Last Post cre8able  
          Started by Harry, 05-02-2018, 01:54 PM
          10 responses
          3,203 views
          0 likes
          Last Post tharton3  
          Started by ChartTourist, Today, 08:22 AM
          0 responses
          6 views
          0 likes
          Last Post ChartTourist  
          Started by LiamTwine, Today, 08:10 AM
          0 responses
          2 views
          0 likes
          Last Post LiamTwine  
          Working...
          X