Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error on calling 'OnBarUpdate' method for indicator on bar n: index out of bounds

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

    Error on calling 'OnBarUpdate' method for indicator on bar n: index out of bounds

    Hi,
    I'm developing an Indicator within call other indicators. When I use some kind of indicator as the Vitalij's Volume Indicator I receive the error message:

    Error on calling 'OnBarUpdate' method for indicator on bar n: index out of matrix's bounds

    In the attachment there is my custom indicator (simplified for debugging) and the Vitalij's Volume Indicator.
    To solve the problem I tried to put some ifs in the OnBarUpdate() method like

    Code:
    if(CurrentBar > vitVolume.BarsRequired){...}
    or
    Code:
    if(CurrentBar < 0){...}
    as suggested in other posts. Nevertheless, it doesn't work.

    Please, can you help me to resolve the problem?
    Best
    Stefano

    P.s. I'm using the indicator with MarketReplay.
    Attached Files

    #2
    Hello stefanodp,

    Thank you for your note.

    I'm unable to test the script as I'm missing methods needed in VitVolume indicator. It looks like you are creating an indicator instance vitVolume, never setting it, then trying to print its values.

    Below would be an example of the correct format in NT7 for referencing another indicator via an indicator.

    Under OnBarUpdate,

    Code:
    if(CurrentBar<30) return;
    Print("MACD"+MACD(5, 10, 20).Avg[0].ToString());
    In order to access the values in the VitVolume, VitVolume should set plots and its these plots which are accessible. You could see the MACD indicator or SMA for how this is done.

    If VItVolume does not set plots you could see the following reference example,


    If you use this format, does this resolve the issue?

    I look forward to your reply.
    Alan P.NinjaTrader Customer Service

    Comment


      #3
      Thank you for reply.

      The VitVolume sets the Plots, as follow

      Code:
      Add(new Plot(new Pen(Color.FromArgb(64, 64, 64), 2), PlotStyle.Bar, "UnknownAsk"));
      Add(new Plot(new Pen(Color.FromArgb(64, 64, 64), 2), PlotStyle.Bar, "UnknownBid"));
      Add(new Plot(new Pen(Color.Green, 2), PlotStyle.Bar, "AtAsk"));
      ...
      in a similar way to MACD.
      The indicator itself works fine. Why am I unable to get the values stored in Values[0], Values[1] and so on? That's weird.

      Comment


        #4
        Hello stefanodp,

        Have you attempted to print the indicator values using something similar to the following?

        Code:
        Print("VitVolume "+VitVolume().UnknownAsk[0].ToString());
        I look forward to your reply.
        Alan P.NinjaTrader Customer Service

        Comment


          #5
          Thank you.

          The problem was that it didn't recognize it as Indicator, only as Type. I created a new Indicator with the wizard and copied/pasted the code. Now it works.

          Comment

          Latest Posts

          Collapse

          Topics Statistics Last Post
          Started by Geovanny Suaza, 02-11-2026, 06:32 PM
          0 responses
          597 views
          0 likes
          Last Post Geovanny Suaza  
          Started by Geovanny Suaza, 02-11-2026, 05:51 PM
          0 responses
          343 views
          1 like
          Last Post Geovanny Suaza  
          Started by Mindset, 02-09-2026, 11:44 AM
          0 responses
          103 views
          0 likes
          Last Post Mindset
          by Mindset
           
          Started by Geovanny Suaza, 02-02-2026, 12:30 PM
          0 responses
          556 views
          1 like
          Last Post Geovanny Suaza  
          Started by RFrosty, 01-28-2026, 06:49 PM
          0 responses
          555 views
          1 like
          Last Post RFrosty
          by RFrosty
           
          Working...
          X