Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Strange Problem with bars lookback

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

    Strange Problem with bars lookback

    Hey all,
    I'm wondering if anybody else can spot the problem with my code here, I've been pulling my hair out for hours trying to figure out what the hell is wrong....


    The error I get is
    "You are accessing an index with a value that is invalid since its out of range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart."


    In my "initialise" I have the below to check if there is enough data:

    if (CurrentBar < barsCheck)
    {
    return;
    }

    And I have narrowed the problem down to this section of code:

    private void MergeLastXBars()
    {
    myHigh = 0;
    myLow = 10;
    myOpen = (double)opens[(barsCheck - 1)];
    myClose = (double)closes[0];

    for (int i = (barsCheck -1); i > 0; i--)
    {
    if ((double)highs[i] > myHigh)
    {
    myHigh = (double)highs[i];

    }
    Print ("Checking bar " + i);


    }
    for (int j = (barsCheck -1); j > 0; j--)
    {
    if ((double)lows[j] < myLow)
    {
    myLow = (double)lows[j];
    }


    }

    }

    I can't for the life of me figure out what's doing it...
    Any help would be much appreciated.
    Thanks!
    Bill
    Last edited by bilster; 04-16-2016, 06:30 AM.

    #2
    Hmmm it seems my "CurrentBar" starts at 20..... I wonder why that is!!!


    EDITED:
    My bad Had to set this code in "initialise":

    BarsRequired = 0;
    Last edited by bilster; 04-16-2016, 06:31 AM.

    Comment


      #3
      Hello blister,

      Thank you for writing in.

      You would want the CurrentBar check to occur within OnBarUpdate() and not Initialize().

      Please take a look at this tip on our support forum to check that you have enough bars in the data series you are accessing: http://ninjatrader.com/support/forum...ead.php?t=3170

      Please, let us know if we may be of further assistance.
      Zachary G.NinjaTrader Customer Service

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      558 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      324 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      101 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      545 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      547 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X