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 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,
    BertrandNinjaTrader Customer Service

    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.
        BertrandNinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by funk10101, Today, 12:02 AM
        1 response
        10 views
        0 likes
        Last Post NinjaTrader_LuisH  
        Started by GLFX005, Today, 03:23 AM
        1 response
        6 views
        0 likes
        Last Post NinjaTrader_Erick  
        Started by nandhumca, Yesterday, 03:41 PM
        1 response
        12 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by The_Sec, Yesterday, 03:37 PM
        1 response
        11 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Started by vecnopus, Today, 06:15 AM
        0 responses
        1 view
        0 likes
        Last Post vecnopus  
        Working...
        X