Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

index is out-of-range Error

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

    index is out-of-range Error

    Hi, Im testing a startegy and keep getting this "bar is out of range" error and i frankly don't know how to solve it cause i tried everything i could think of, kind help please?

    I start like this:


    if ( CurrentBars[1] <= spLength || CurrentBars[1] <= rangeBollPeriod || CurrentBars[1] <= vmaVolatilityPeriod ) return;
    {
    if (BarsInProgress == 1)
    {

    supertrend calculation from 4H bars

    if ( CurrentBar == 0 )
    {
    upTrend.Set(true);
    StopLine.Set ( Closes[1][0] );
    OuterLine.Set( Closes[1][0] );
    CenterLine.Set( Closes[1][0] );


    return;
    }


    if (FirstTickOfBar)
    {

    etc etc


    then a keltner

    RangeBollUpper.Set( KBT_KELTNER_V1( Closes[1] , rangeBollNumStdDev , rangeBollPeriod ).Upper[0] );
    RangeBollLower.Set( KBT_KELTNER_V1( Closes[1] , rangeBollNumStdDev , rangeBollPeriod ).Lower[0] );

    }

    and color areas

    if (BarsInProgress == 0)
    {


    if ( Closes[1][0] > StopLine[0] )
    {

    DrawRegion("SFColorRegion"+CurrentBar ,1,0, StopLine , FilterLine , Color.Transparent, Color.MediumSeaGreen, 1 );

    etc etc



    What im doing wrong?


    Thx!
    Last edited by kabott; 11-15-2018, 05:39 AM.

    #2
    Hello kabott,

    Thanks for your post.

    These type of issue are best dealt with by debugging your script with print statements. You would use print statements to see when and where the error is occurring. Debugging is tedious and time-consuming but it is the only way to ensure you understand what data the code is working with and making decisions upon. Please review our debugging tips here: https://ninjatrader.com/support/help...script_cod.htm

    The code you are showing appears partial but one area of concern I see is that you are checking for CurrentBars[1] and if not enough bars you are returning (which is usually fine), however, this prevents code below that statement from executing until several bars have passed. This means that the code starting with this line: if ( CurrentBar == 0 ) is never executed because 0 is the very first bar of data. This is likely not the issue you are facing but is a logic error.

    If you would like your strategy professionally created we can provide references to 3rd party programmers.

    Comment


      #3
      Hi PaulH, its curious cause i have two charts one with the indicator and the other one with the strategy, the one with the indicator works just fine, the one with the strategy doesn't show up and throws the error

      Comment


        #4
        Hello kabott,

        Thanks for your reply.

        Then you would want to use the print statements in the strategy to find out at which point it errors.

        Comment


          #5
          Thanks Paul, i scraped that indi and started a new one, now works fine, no clue what was going on there, probably some silly error I overlooked a hundred times ;P

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          649 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          370 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          109 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          574 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          576 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X