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

Index out of range Exception when setting plot Values on 'Load data based on: Bars'

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

    Index out of range Exception when setting plot Values on 'Load data based on: Bars'

    Hello Support Team,

    When I configure my chart data series to 'Load data based on' Bars vs Days, my indicator(s) using AddDataSeries throw exceptions in when setting plot Values or ISeries.
    The AddDataSeries has to use a larger BarsPeriod.Value than the primary series. When primary series is configured to 'Load data based on' Days, everything seems to work normally with no exceptions.

    EXCEPTION [MultiSeriesTest]: OnBarUpdate; BIP: 1; CB1: 0, 1/26/2024 2:45:00 AM; CB2: 0, 1/26/2024 2:45:00 AM; Ct1: 50; Ct2: 50; ADS: True Msg: Index was out of range. Must be non-negative and less than the size of the collection.
    Parameter name: index
    Trace: at System.ThrowHelper.ThrowArgumentOutOfRangeExceptio n(ExceptionArgument argument, ExceptionResource resource)
    at NinjaTrader.NinjaScript.Series`1.set_Item(Int32 barsAgo, T value)
    at NinjaTrader.NinjaScript.Indicators.MultiSeriesTest .OnBarUpdate() in c:\Users\becht\Documents\NinjaTrader 8\bin\Custom\Indicators\CDX\Indicators\MultiSeries Test.cs:line 117


    Please see the attached MultiSeriesTest.cs script as an example, setting the Alternate Data Series to something larger than the primary.

    This appears to be a synchronization bug between the two data series when using Load data based on Bars. Am I missing something?

    Thanks in advance.
    Attached Files
    Last edited by CDXTrader; 01-28-2024, 01:33 PM.

    #2
    Hello CDXTrader,

    Thanks for your post.

    I see you are dynamically calling AddDataSeries() in your script which is not supported and goes outside the support we could provide you with. All arguments supplied to the AddDataSeries() method must be hard coded in the script.

    From the help guide:

    "Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input). Attempting to add a data series dynamically is NOT guaranteed and therefore should be avoided."

    AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm

    If the script works when using 'Load Data Based On Days' but not when using 'Bars', you would need to ensure that you are loading enough bars on the chart for your script to process.

    Further, you should make sure that you have a CurrentBars check for the primary series and added secondary series in the script.

    CurrentBars: https://ninjatrader.com/support/help...urrentbars.htm
    Brandon H.NinjaTrader Customer Service

    Comment


      #3
      Hi Brandon,

      I appreciate the response. I should have clarified that I am aware of the stated guidance in the help guide. I was more or less confused about what seemed like incongruity between the two types of bar loading, Bar quantity and Days. However, after further review, it appears that the data requestor does load an equal number of bars for both series.

      Because the two series are aligned by the present end time, this behavior does make some sense. If one of those series is of larger interval, its time span would obviously go back much further than the smaller interval and therefore the smaller series would not be available until the iteration reaches its beginning later in the series.

      | | | | | | | | | | | | | | | | | | | | | | | | ​ Large Series
      . . . . . . . . . . . . . |||||||||||||||||||||​ Small Series

      May I ask why this configuration is considered "dynamic" and unsupported? The data is not being changed in the middle of indicator processing logic. It's only being set during initialization when the properties are being set. I don't see how this is any different than say changing the native "Input series" property. I'm guessing it has something to do with the original platform design team painting themselves into a corner or something.

      Anyway, thank you again for entertaining my little confusion and curiosity.

      Cheers

      Comment


        #4
        Hello CDXTrader,

        Thanks for your notes.

        The values being supplied to AddDataSeries() are not hardcoded into the method as seen in the help guide. Each individual argument would need to be supplied to the AddDataSeries() method as seen in the sample code on the help guide for it to not be considered dynamic.

        Further, calling AddDataSeries() within a condition would also be considered calling the method dynamically since the AddDataSeries() call would be dependent on a variable/condition.

        Arguments supplied to AddDataSeries() should be hardcoded and NOT dependent on run-time variables which cannot be reliably obtained during State.Configure (e.g., Instrument, Bars, or user input).

        For example, the below code from the help guide would be supported:


        if (State == State.Configure)
        {
        // Add a 5 minute Bars object - BarsInProgress index = 1
        AddDataSeries(BarsPeriodType.Minute, 5);

        // Add a 100 tick Bars object for the ES 09-16 contract - BarsInProgress index = 2
        AddDataSeries("ES 09-16", BarsPeriodType.Tick, 100);
        }


        If each of the arguments are not directly coded (hardcoded) into the AddDataSeries() method or the AddDataSeries() method is placed inside a condition, this would be considered calling AddDataSeries() dynamically which is not supported.

        AddDataSeries(): https://ninjatrader.com/support/help...dataseries.htm
        Brandon H.NinjaTrader Customer Service

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Segwin, 05-07-2018, 02:15 PM
        14 responses
        1,789 views
        0 likes
        Last Post aligator  
        Started by Jimmyk, 01-26-2018, 05:19 AM
        6 responses
        837 views
        0 likes
        Last Post emuns
        by emuns
         
        Started by jxs_xrj, 01-12-2020, 09:49 AM
        6 responses
        3,293 views
        1 like
        Last Post jgualdronc  
        Started by Touch-Ups, Today, 10:36 AM
        0 responses
        13 views
        0 likes
        Last Post Touch-Ups  
        Started by geddyisodin, 04-25-2024, 05:20 AM
        11 responses
        63 views
        0 likes
        Last Post halgo_boulder  
        Working...
        X