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 CarlTrading, 03-31-2026, 09:41 PM
      1 response
      133 views
      1 like
      Last Post NinjaTrader_ChelseaB  
      Started by CarlTrading, 04-01-2026, 02:41 AM
      0 responses
      75 views
      1 like
      Last Post CarlTrading  
      Started by CaptainJack, 03-31-2026, 11:44 PM
      0 responses
      117 views
      2 likes
      Last Post CaptainJack  
      Started by CarlTrading, 03-30-2026, 11:51 AM
      0 responses
      113 views
      1 like
      Last Post CarlTrading  
      Started by CarlTrading, 03-30-2026, 11:48 AM
      0 responses
      90 views
      0 likes
      Last Post CarlTrading  
      Working...
      X