Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

TimeSeries issue has be struggling..

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

    TimeSeries issue has be struggling..

    I am still struggling a bit with "index" values for Series<>.

    I have this issue with both BETA7 & 8 as I just updated. I cannot figure out why it generates this error:

    Exception e=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.Data.BarsSeries.GetTime(Int32 index)
    at NinjaTrader.Data.BarsSeries.GetSessionEndTime(Int3 2 index)
    at NinjaTrader.Data.Bars.GetSessionEndTime(Int32 index)
    at NinjaTrader.NinjaScript.TimeSeries.get_Item(Int32 barsAgo)
    at NinjaTrader.NinjaScript.Strategies.CartesianGeneti cProgramming.CGPStrategy01LongShort.LoadLearnerDat a(List`1 Examples, CGPLearnerMultiIsland& learner)
    at NinjaTrader.NinjaScript.Strategies.CartesianGeneti cProgramming.CGPStrategy01LongShort.InitLearner()
    at NinjaTrader.NinjaScript.Strategies.CartesianGeneti cProgramming.CGPStrategy01LongShort.Execute(String command)
    at NinjaTrader.NinjaScript.Strategies.CartesianGeneti cProgramming.CGPStrategy01LongShort.TextBox_Previe wKeyDown(Object sender, KeyEventArgs e)
    What I am trying to access is "Time[1333]" where CurrentBar=1355 and Time.Length=1357. Clearly the bars back is well within the length of the TimeSeries. I don't understand the strange "GetSesssionEndTime()" as part of the error as I am not interested in the Session, just the value at 1333 bars back.

    This one has me stumped...

    #2
    From that stack, it appears you're using that code outside of a core event handler. We've just adding some info to the help guide regarding this. Try using GetTime() in your text box and that should allow you to get the values correctly by absolute index, as you can run into cases where the current bar is not in sync if not using a custom events.


    Note: In most cases, you will access the historical price series using a core event handler such as OnBarUpdate. For more advance developers, you may find situations where you wish to access historical price series outside of the core event methods, such as your own custom mouse click. In these advanced scenarios, you may run into situations where the barsAgo pointer is not in sync with the current bar, and may result in errors when trying to obtain this information. In those cases, please use the Bars.Get...() methods with the absolute bar index, e.g., Bars.GetTime(), etc.
    MatthewNinjaTrader Product Management

    Comment


      #3
      Thanks for the fast reply. Yes, I thought I had used the "TriggerCustomEvent()" handle, but that didn't get included.

      Once I added that into the code, things worked fine!

      Comment


        #4
        Originally posted by NJA_MC View Post
        Thanks for the fast reply. Yes, I thought I had used the "TriggerCustomEvent()" handle, but that didn't get included.

        Once I added that into the code, things worked fine!
        I will take your recommendation to use more of the "Get..." type functions and access more like you post here:

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by Geovanny Suaza, 02-11-2026, 06:32 PM
        0 responses
        670 views
        0 likes
        Last Post Geovanny Suaza  
        Started by Geovanny Suaza, 02-11-2026, 05:51 PM
        0 responses
        379 views
        1 like
        Last Post Geovanny Suaza  
        Started by Mindset, 02-09-2026, 11:44 AM
        0 responses
        111 views
        0 likes
        Last Post Mindset
        by Mindset
         
        Started by Geovanny Suaza, 02-02-2026, 12:30 PM
        0 responses
        575 views
        1 like
        Last Post Geovanny Suaza  
        Started by RFrosty, 01-28-2026, 06:49 PM
        0 responses
        582 views
        1 like
        Last Post RFrosty
        by RFrosty
         
        Working...
        X