Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Error on calling OnBarUpdate, Index was outside the bounds of the array

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

    Error on calling OnBarUpdate, Index was outside the bounds of the array

    I have a custom indicator where I have two properties. I only want to plot one of them - the default Series at index 0, but I want a second Series (at index 1) that would be available to a Strategy that uses this indicator.

    My properties are defined like this:

    Code:
    #region Properties
    
    [Browsable(false)]
    [XmlIgnore()]
    public Series<double> PendingCount
    {
        get { return Values[1]; }
    }
    
    [Browsable(false)]
    [XmlIgnore]
    public Series<double> TrendMode
    {
        get { return Values[0]; }
    }
    #endregion
    When I add my indicator to a chart, it has no problem setting the default data series TrendMode at current bar: TrendMode[0] = 0 for example
    But when I try to set PendingCount[0] I get an error message in runtime: Error on calling OnBarUpdate, Index was outside the bounds of the array

    Note that in OnStateChange if State == State.SetDefaults I call only one AddPlot function:

    AddPlot(Brushes.DarkCyan, "TrendMode");

    since I only want to see TrendMode plotted, not PendingCount. But for some reason, PendingCount doesn't seem to get allocated.

    How do I fix this?

    #2
    Hello westofpluto,

    Thank you for your post.

    The PendingCount property is calling get { return Values[1]; } and Values[ ] holds an array of Series<double> objects associated with plots. Since PendingCount is not being plotted and you are trying to access objects associated with plots, you are seeing an error when calling PendingCount. In order to expose indicator values that are not plots, you could create a Series<double> variable that stores information followed by accessing and expose that variable in the PendingCount property.

    Please review the SampleBoolSeries indicator example that demonstrates how to expose indicator values that are not plots - https://ninjatrader.com/support/help...alues_that.htm

    Also, here are help guide links for more information about Values [ ] and AddPlot.

    Values[ ] - https://ninjatrader.com/de/support/h...t8/?values.htm

    AddPlot - https://ninjatrader.com/support/help...8/?addplot.htm

    Let us know if we may assist further.
    <span class="name">Brandon H.</span><span class="title">NinjaTrader Customer Service</span><iframe name="sig" id="sigFrame" src="/support/forum/core/clientscript/Signature/signature.php" frameborder="0" border="0" cellspacing="0" style="border-style: none;width: 100%; height: 120px;"></iframe>

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by Geovanny Suaza, 02-11-2026, 06:32 PM
    0 responses
    650 views
    0 likes
    Last Post Geovanny Suaza  
    Started by Geovanny Suaza, 02-11-2026, 05:51 PM
    0 responses
    370 views
    1 like
    Last Post Geovanny Suaza  
    Started by Mindset, 02-09-2026, 11:44 AM
    0 responses
    109 views
    0 likes
    Last Post Mindset
    by Mindset
     
    Started by Geovanny Suaza, 02-02-2026, 12:30 PM
    0 responses
    574 views
    1 like
    Last Post Geovanny Suaza  
    Started by RFrosty, 01-28-2026, 06:49 PM
    0 responses
    577 views
    1 like
    Last Post RFrosty
    by RFrosty
     
    Working...
    X