Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Odd Error

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

    Odd Error

    Hello,
    I have been developing in Ninjascript for a couple of years now and am very proficient.
    I am getting the error "Strategy '####': Error on calling 'OnBarUpdate' method on bar -1: 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.
    Obviously I have seen this before and normally it is an easy fix.

    The issue is my code is:
    Values[0][0] = 1;
    Values[1][0] = 2;​

    Called in OnBarUpdate this means that it is having trouble accessing Either the number 1 and 2 or the Values Array.
    My initial thought was that I didn't have enough plots so it is having trouble assigning a value to a plot that doesn't exist. But this is my code:
    AddPlot(Brushes.Orange, "MA1");
    AddPlot(Brushes.Linen, "MA2");​

    Called in the OnStateChange method in SetDefaults State.

    Could be an easy fix and I may be blind but please let me know if you see something. Cannot release code because it is proprietary but this should be all of the information you need.
    Also I am well aware of print statements and have isolated those lines as the problem lines so please god don't tell me about print statements

    Thanks!

    #2
    Hello, thanks for writing in. The issue is in your custom code that is not shared. You can use Visual Studio debugging to find the exact line of code that is causing this issue:

    Comment


      #3
      This is not the only code in the script, and it is not causing the unhandled exception for you. It can be demonstrated with a simple test script:

      Attached Files

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by NullPointStrategies, Yesterday, 05:17 AM
      0 responses
      62 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      134 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      75 views
      0 likes
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      45 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Started by TheRealMorford, 03-05-2026, 06:15 PM
      0 responses
      50 views
      0 likes
      Last Post TheRealMorford  
      Working...
      X