Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error barsAgo when optimizing

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

    Error barsAgo when optimizing

    Hello,

    When optimizing a strategy I get the error:
    "Strategy 'TestStrategy': Error on calling 'OnBarUpdate' method on bar 63: 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.​"

    If the strategy is executing the 63th bar, why it says "when there are only 4 bars on the chart"?

    Thanks

    #2
    Hello guillembm,

    The error gives a generic example of a reason that would be caused, you would need to debug your code to see what specifically happened in your use case. The error does provide details that the error happened in OnBarUpdate and on bar 63 so you have some information to go on for debugging. Its generally suggested to use prints to diagnose this type of error, place prints in the code in various locations and then when you hit the error check what the last print was, that was the last code that successfully executed.



    Comment


      #3
      I am also getting the error "'SMA' tried to load additional data. All data must first be loaded by the hosting NinjaScript in its configure state. Attempted to load AUDUSD Default: 15 Minute"

      My code is :

      else if (State == State.Configure)
      {
      AddDataSeries(BarsPeriodType.Minute, 15);
      }​

      Comment


        #4
        Hello guillembm,

        From the details I would be unsure why that message would appear, the SMA does not use a secondary series. We would need a much more specific example of what code is being used to know why that may be happening. Generally you will see that message if your parent script calls an indicator that uses AddDataSeries in its code but the parent script did not add the same data.

        If your primary instrument is not AUDUSD then you would additionally need to do

        AddDataSeries("AUDUSD", BarsPeriodType.Minute, 15);

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by argusthome, 03-08-2026, 10:06 AM
        0 responses
        69 views
        0 likes
        Last Post argusthome  
        Started by NabilKhattabi, 03-06-2026, 11:18 AM
        0 responses
        42 views
        0 likes
        Last Post NabilKhattabi  
        Started by Deep42, 03-06-2026, 12:28 AM
        0 responses
        24 views
        0 likes
        Last Post Deep42
        by Deep42
         
        Started by TheRealMorford, 03-05-2026, 06:15 PM
        0 responses
        27 views
        0 likes
        Last Post TheRealMorford  
        Started by Mindset, 02-28-2026, 06:16 AM
        0 responses
        54 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Working...
        X