Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

index out of range - where?

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

    index out of range - where?

    In an earlier thread, I was testing & debugging multi-bar indicators.

    Well, I had to stop for a while because NT (64-bit v7) starting crashing.
    Went back to look again today, and now on the simplest test, I am getting an index out of bounds error -- I understand these, but cannot figure where this testcase is failing. It is the same test that was working before. The code is patterned off the code in WMA which explicitly handles CurrentBar == 0.

    Error on calling 'OnBarUpdate' method for indicator 'Test' on bar 0: 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.

    This is the entire code in Initialize & OnBarUpdate:

    Code:
    protected override void Initialize()
            {
                Add(BarsPeriod.Id, BarsPeriod.Value*_basePrime);  // guaranteed to be BarsInProgress == 1
                Add(new Plot(Color.Orange, Name));
                Overlay                = false;
            }
    
            /// <summary>
            /// Called on each bar update event (incoming tick)
            /// </summary>
            protected override void OnBarUpdate()
            {
                if (CurrentBars[0] < 0 || CurrentBars[1] < 0) return; // patch for NT design flaw
                if ( Bars[0] == null || Bars[1] == null) return; 
                if (CurrentBars[x] < _basePrime) return;    // Check 2nd data stream for sufficient bars
                if (BarsInProgress == 0)   // NT can only plot from BIP=0 !!!
                {
                    Value.Set( WMA( Inputs[x], 10 )[0] );
                }
            }
    Attached Files

    #2
    LostTrader, it works ok without your if ( Bars[0] == null || Bars[1] == null) return; check - I'm not exactly sure why you put this in.

    Thanks,

    Comment


      #3
      The reason for putting it in is buried somewhere in the forum. Yep, that fixed the error. Thanks.

      Can you explain the relationship between the two? The error message seems off...

      Comment


        #4
        You're welcome, your CurrentBars check was not high enough to cover Bars[1] access.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        607 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        353 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        105 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        560 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        561 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X