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 Irukandji, Today, 09:34 AM
          0 responses
          3 views
          0 likes
          Last Post Irukandji  
          Started by TraderBCL, Today, 04:38 AM
          3 responses
          25 views
          0 likes
          Last Post NinjaTrader_Jesse  
          Started by WeyldFalcon, 08-07-2020, 06:13 AM
          11 responses
          1,423 views
          0 likes
          Last Post jculp
          by jculp
           
          Started by RubenCazorla, Today, 09:07 AM
          0 responses
          4 views
          0 likes
          Last Post RubenCazorla  
          Started by BarzTrading, Today, 07:25 AM
          2 responses
          29 views
          1 like
          Last Post BarzTrading  
          Working...
          X