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

Index out of range error

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

    Index out of range error

    I have a couple of indicators with the same error: index out of range, must be non-negative and less than the size of the collection; parameter name 'index'.

    I have printed out every single dataseries in the code and cannot see any negatives or zeros. I have made the initial if currentbar < x up to 200 when the code is only referencing 20-50 bars back.

    I have no idea how to find out what is going on when this error msg pops up.

    In both cases, it works fine with Calc on bar close, and the error msg occurs when that is false.

    Any tips for how to find out what the problem is? (The two indicators are completely separate and neither uses code from the other).

    #2
    cclsys,

    Try using try-catch blocks throughout your code to isolate where exactly it is breaking and then slowly add print statements throughout to isolate further.
    Josh P.NinjaTrader Customer Service

    Comment


      #3
      Originally posted by NinjaTrader_Josh View Post
      cclsys,

      Try using try-catch blocks throughout your code to isolate where exactly it is breaking and then slowly add print statements throughout to isolate further.
      Do you have any references with examples? I have never done that and don't really know what a 'catch-block' is exactly.

      I have the SampleTryCatch, but have absolutely no idea what to do with it, not understanding either the explanation or the code itself.
      Last edited by cclsys; 11-30-2009, 12:07 PM.

      Comment


        #4
        Please see this reference: http://www.ninjatrader-support2.com/...ead.php?t=9825
        Josh P.NinjaTrader Customer Service

        Comment


          #5
          Originally posted by NinjaTrader_Josh View Post
          Yes, I have that. I tried using it for first section of my code thusly:


          protected override void OnBarUpdate()
          {
          try
          {
          if (CurrentBar < Math.Max(Period*3,90)) return;

          DR.Set (MAX(High,Period)[0] - MIN(Low,Period)[0]);
          DRAv.Set ( SMA(DR,Period)[0]);

          // BackColor Section
          }
          catch (Exception e)
          {
          /* With our caught exception we are able to generate log entries that go to the Control Center logs and also print more detailed information
          about the error to the Output Window. */

          // Submits an entry into the Control Center logs to inform the user of an error
          Log("TryCatchAsh Error: Please check your indicator for errors.", LogLevel.Error);

          // Prints the caught exception in the Output Window
          Print(Time[0] + " " + e.ToString());
          }

          The error msg states that System.Log is inaccessible due to protection level. 2nd msg that system.log does not contain a definition for error.

          ++++++

          Or: Are you supposed to write a completely different parallel version of the code and insert any variables or dataseries into try catch in order to use it? I find the lack of explanation too opaque for my limited experience with programming issues like this.

          I also don't understand why
          a) it can compile if it won't work properly and
          b) it can't have more precise error messages than 'parameter = index' which doesn't say very much - at least to me.

          Comment


            #6
            Try just removing the Log() line. You can just view the output in the Output Window.

            You should try-catch various objects individually and then whichever one of the try-catch blocks trips will notify you as to which one of the objects has issues. Then you will need to use Print()s and slowly walk through the object's states to find where the logic breaks.
            Josh P.NinjaTrader Customer Service

            Comment

            Latest Posts

            Collapse

            Topics Statistics Last Post
            Started by ScottWalsh, Today, 04:52 PM
            0 responses
            1 view
            0 likes
            Last Post ScottWalsh  
            Started by ScottWalsh, Today, 04:29 PM
            0 responses
            5 views
            0 likes
            Last Post ScottWalsh  
            Started by rtwave, 04-12-2024, 09:30 AM
            2 responses
            22 views
            0 likes
            Last Post rtwave
            by rtwave
             
            Started by tsantospinto, 04-12-2024, 07:04 PM
            5 responses
            70 views
            0 likes
            Last Post tsantospinto  
            Started by cre8able, Today, 03:20 PM
            0 responses
            7 views
            0 likes
            Last Post cre8able  
            Working...
            X