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

Bar index needs to be greater/equal 0

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

    Bar index needs to be greater/equal 0

    This is very odd.

    I have a multi-instrument indicator, and at some point in the code I have a call that occurs when BarsInProgress==0

    This code tries to look at the series of other instruments and is looking for a matching timestamp. Skipping some code, here's the context of the problem:

    //...
    ITimeSeries time = Times[instrumentIndex];
    //...
    for (int i = 0; i < time.Count; i++)
    {
    //...
    Print("i=" + i+", time.Count = "+time.Count); // debugging
    DateTime t = time[i];
    Print(" time = " + t); // debugging
    // do stuff with t....
    }

    This works for some bars, but at some point it throws an exception. The output window shows the following:
    ...
    i=390, time.Count = 1556
    time = 6/6/2012 6:32:00 AM
    i=391, time.Count = 1556
    time = 6/6/2012 6:31:00 AM
    i=392, time.Count = 1556
    Exception in MyGroupWatchListVsIndex.OnBarUpdate(): System.ArgumentException: Bar index needs to be greater/equal 0
    at NinjaTrader.Data.Bars.GetTime(Int32 barIndex)
    at NinjaTrader.Data.Bars.GetTimeEnd(Int32 barIndex)
    at NinjaTrader.Indicator.TimeSeriesHelper.get_Item(In t32 barsAgo)
    at NinjaTrader.Indicator.MyGroupWatchListVsIndex.Find OffsetByTimestamp(DateTime syncTimeStamp, Int32 instrumentIndex, Boolean roundToDate, Boolean useExactMatch, Int32 guess) in c:\Users\Admin\Documents\NinjaTrader 7\bin\Custom\Indicator\MyGroupWatchListVsIndex.cs: line 327
    ...
    So it's trying to access Times[instrumentIndex][392] when the series has 1556 items. As i understand this, this should not blow up... Plus the index is clearly positive.

    What gives?

    #2
    arnonmoscona,

    Do you perhaps have a toy sample I could use for testing that exhibits this same behavior?
    Adam P.NinjaTrader Customer Service

    Comment


      #3
      Not really... It'll take some work probably.
      Have you seen before this situation where a positive index causes this exception?

      Comment


        #4
        arnon,

        I have not. I am wondering if the error is from somewhere else here and so I wanted to take a look through the code.

        A try/catch can be used to identify the exact line this is coming from in your Tools > Output window.

        Adam P.NinjaTrader Customer Service

        Comment


          #5
          I did. Debug was turned on and the line number in the exception stack trace matched exactly where you see time[i]. No question about that part...

          Comment


            #6
            arnon,

            Without code here I wouldn't really be able to investigate further. I am not aware of any reason this would occur just with that code sample. I will discuss with our tech lead.

            If you want, you can submit the code to support at ninjatrader dot com with a reference to this thread. That way your code won't be public as we keep all that confidential.
            Adam P.NinjaTrader Customer Service

            Comment


              #7
              MaximumBarsLookBack Set?

              Do you have the data series?

              Finally:

              ITimeSeries time = Times[instrumentIndex];

              Do you have this synced to the correct series in MTF with this sample?

              Note: In NinjaTrader 8 It is no longer needed to use an indicator to sync a secondary series. This can be done directly from the Series&lt;T&gt; (https://ninjatrader.com/support/helpGuides/nt8/NT%20HelpGuide%20English.html?seriest.htm) constructor. This post is left for historical purposes. Series objects are useful for



              Thanks.

              Comment

              Latest Posts

              Collapse

              Topics Statistics Last Post
              Started by judysamnt7, 03-13-2023, 09:11 AM
              4 responses
              59 views
              0 likes
              Last Post DynamicTest  
              Started by ScottWalsh, Today, 06:52 PM
              4 responses
              36 views
              0 likes
              Last Post ScottWalsh  
              Started by olisav57, Today, 07:39 PM
              0 responses
              7 views
              0 likes
              Last Post olisav57  
              Started by trilliantrader, Today, 03:01 PM
              2 responses
              21 views
              0 likes
              Last Post helpwanted  
              Started by cre8able, Today, 07:24 PM
              0 responses
              10 views
              0 likes
              Last Post cre8able  
              Working...
              X