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 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.
    Paul H.NinjaTrader Customer Service

    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.
        Paul H.NinjaTrader Customer Service

        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 geddyisodin, Yesterday, 05:20 AM
          7 responses
          45 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Started by gbourque, Today, 06:39 AM
          2 responses
          5 views
          0 likes
          Last Post gbourque  
          Started by cre8able, Yesterday, 07:24 PM
          1 response
          13 views
          0 likes
          Last Post NinjaTrader_ChelseaB  
          Started by cocoescala, 10-12-2018, 11:02 PM
          6 responses
          939 views
          0 likes
          Last Post Jquiroz1975  
          Started by cmtjoancolmenero, Yesterday, 03:58 PM
          1 response
          17 views
          0 likes
          Last Post NinjaTrader_Gaby  
          Working...
          X