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 sjsj2732, Yesterday, 04:31 AM
      0 responses
      28 views
      0 likes
      Last Post sjsj2732  
      Started by NullPointStrategies, 03-13-2026, 05:17 AM
      0 responses
      284 views
      0 likes
      Last Post NullPointStrategies  
      Started by argusthome, 03-08-2026, 10:06 AM
      0 responses
      281 views
      0 likes
      Last Post argusthome  
      Started by NabilKhattabi, 03-06-2026, 11:18 AM
      0 responses
      132 views
      1 like
      Last Post NabilKhattabi  
      Started by Deep42, 03-06-2026, 12:28 AM
      0 responses
      90 views
      0 likes
      Last Post Deep42
      by Deep42
       
      Working...
      X