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

Possible reason for ERROR: Failed to call 'Add' method: Arg OOR, OnRender

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

    Possible reason for ERROR: Failed to call 'Add' method: Arg OOR, OnRender

    I was getting errors like

    2023-09-06 12:02:54:229 ERROR: Failed to call 'Add' method: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index at System.ThrowHelper.ThrowArgumentOutOfRangeExceptio n(ExceptionArgument argument, ExceptionResource resource) at NinjaTrader.Gui.Chart.MultiEquidistant.GetTimeBySl otIndex(Int32 slotIndex) at NinjaTrader.Gui.Chart.MultiEquidistant.GetFirstBar IndexToUpdateFromCurrentMapping(ChartBars chartBars, DateTime firstTimeToUpdate) at NinjaTrader.Gui.Chart.MultiEquidistant.UpdateBar2S lotMappings(BarsSeries barsSeries, Int32 minBarIndex, Int32 maxBarIndex) at NinjaTrader.Gui.Chart.ChartControl.OnBarsUpdate(Ob ject sender, BarsUpdateEventArgs e) at NinjaTrader.Data.BarsSeries.Add(Bars bars, Double open, Double high, Double low, Double close, DateTime time, Int64 volume, Double tickSize, Boolean isBar, Double bid, Double ask)
    2023-09-06 12:02:54:229 ERROR: Failed to call 'Add' method: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index at System.ThrowHelper.ThrowArgumentOutOfRangeExceptio n(ExceptionArgument argument, ExceptionResource resource) at NinjaTrader.Gui.Chart.MultiEquidistant.GetTimeBySl otIndex(Int32 slotIndex) at NinjaTrader.Gui.Chart.ChartBars.MultiEqSaveTimes(M ultiEquidistant equidistantMulti, DateTime fromTime) at NinjaTrader.Gui.Chart.MultiEquidistant.UpdateBar2S lotMappings(BarsSeries barsSeries, Int32 minBarIndex, Int32 maxBarIndex) at NinjaTrader.Gui.Chart.ChartControl.OnBarsUpdate(Ob ject sender, BarsUpdateEventArgs e) at NinjaTrader.Data.BarsSeries.Add(Bars bars, Double open, Double high, Double low, Double close, DateTime time, Int64 volume, Double tickSize, Boolean isBar, Double bid, Double ask)
    2023-09-06 12:02:55:194 Gui.Chart.ChartPanel.OnRender: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
    at System.ThrowHelper.ThrowArgumentOutOfRangeExceptio n(ExceptionArgument argument, ExceptionResource resource)
    at NinjaTrader.Gui.Chart.MultiEquidistant.GetTimeBySl otIndex(Int32 slotIndex)
    at NinjaTrader.Gui.Chart.MultiEquidistant.UpdateX2Tim eMapping(Int32 firstSlotPainted, Int32 lastSlotPainted)
    at NinjaTrader.Gui.Chart.Direct2DForm.RenderInit()
    2023-09-06 12:02:55:194 ERROR: Chart rendering failed. There is likely a problem with a chart object's OnRender method. D2D error = 'Index was out of range. Must be non-negative and less than the size of the collection. Parameter name: index'
    2023-09-06 12:02:56:192 Gui.Chart.ChartPanel.OnRender: System.ArgumentOutOfRangeException: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
    at System.ThrowHelper.ThrowArgumentOutOfRangeExceptio n(ExceptionArgument argument, ExceptionResource resource)
    at NinjaTrader.Gui.Chart.MultiEquidistant.GetTimeBySl otIndex(Int32 slotIndex)
    at NinjaTrader.Gui.Chart.MultiEquidistant.UpdateX2Tim eMapping(Int32 firstSlotPainted, Int32 lastSlotPainted)
    at NinjaTrader.Gui.Chart.Direct2DForm.RenderInit()



    I had 2 different BarsTypes on the chart (2 data Series, same instrument).

    The log error doesn't explicitly say "AddBar()", just Add() method...

    I might still be hungover from Labor Day, but I came up with an illusion that this might be happening because the BarsType which was trying to add a new bar, was trying to use an Index value which did not exist yet in the overall BarArray index. And tha caused the Bar OnRender method (happening behind the scenes, not in my BarsType script), to toss the error.

    I avoided this error, when I made the barstype with the higher resolution as the first barstype, i.e. BarsArray 0, i.e. moving that BarsType to the top of the Data Series list in the Config Box, then this error did not happen again.

    I post this with the intention of helping others track down this error and ​possible solutions.

    Click image for larger version

Name:	NT8_Forum.png
Views:	130
Size:	88.6 KB
ID:	1267781
    Last edited by balltrader; 09-06-2023, 11:46 AM.

    #2
    Hello balltrader,

    The error is not specifically helpful to know what the problem is. If you are using some code or steps that produce that error you could share a sample of how to recreate that problem so we can test it. I otherwise wouldn't be able to tell what may have happened based on the given information.

    JesseNinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by lightsun47, Today, 03:51 PM
    0 responses
    5 views
    0 likes
    Last Post lightsun47  
    Started by 00nevest, Today, 02:27 PM
    1 response
    11 views
    0 likes
    Last Post 00nevest  
    Started by futtrader, 04-21-2024, 01:50 AM
    4 responses
    46 views
    0 likes
    Last Post futtrader  
    Started by Option Whisperer, Today, 09:55 AM
    1 response
    14 views
    0 likes
    Last Post bltdavid  
    Started by port119, Today, 02:43 PM
    0 responses
    10 views
    0 likes
    Last Post port119
    by port119
     
    Working...
    X