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 Austiner87, Yesterday, 11:24 AM
        2 responses
        12 views
        0 likes
        Last Post brucerobinson  
        Started by Rogers101, 05-05-2024, 11:30 AM
        3 responses
        21 views
        0 likes
        Last Post Rogers101  
        Started by nightstalker, 05-04-2024, 02:05 PM
        5 responses
        54 views
        1 like
        Last Post nightstalker  
        Started by MSerag, Yesterday, 11:52 PM
        0 responses
        11 views
        0 likes
        Last Post MSerag
        by MSerag
         
        Started by DynamicTest, Yesterday, 11:18 PM
        0 responses
        3 views
        0 likes
        Last Post DynamicTest  
        Working...
        X