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

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 AaronKoRn, Yesterday, 09:49 PM
          0 responses
          11 views
          0 likes
          Last Post AaronKoRn  
          Started by carnitron, Yesterday, 08:42 PM
          0 responses
          10 views
          0 likes
          Last Post carnitron  
          Started by strategist007, Yesterday, 07:51 PM
          0 responses
          12 views
          0 likes
          Last Post strategist007  
          Started by StockTrader88, 03-06-2021, 08:58 AM
          44 responses
          3,982 views
          3 likes
          Last Post jhudas88  
          Started by rbeckmann05, Yesterday, 06:48 PM
          0 responses
          10 views
          0 likes
          Last Post rbeckmann05  
          Working...
          X