Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Why out-of-range error doesn't trigger with Series<T> variables?

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

    Why out-of-range error doesn't trigger with Series<T> variables?

    For example, test this:

    Code:
    #region Using declarations
    using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.ComponentModel.DataAnnotations;
    using System.Linq;
    using System.Text;
    using System.Threading.Tasks;
    using System.Windows;
    using System.Windows.Input;
    using System.Windows.Media;
    using System.Xml.Serialization;
    using NinjaTrader.Cbi;
    using NinjaTrader.Gui;
    using NinjaTrader.Gui.Chart;
    using NinjaTrader.Gui.SuperDom;
    using NinjaTrader.Gui.Tools;
    using NinjaTrader.Data;
    using NinjaTrader.NinjaScript;
    using NinjaTrader.Core.FloatingPoint;
    using NinjaTrader.NinjaScript.DrawingTools;
    #endregion
    
    namespace NinjaTrader.NinjaScript.Indicators
    {
        public class a1 : Indicator
        {         
            Series<int> my;
    
            protected override void OnStateChange()
            {
                if (State == State.SetDefaults)
                {
                    Description                                    = @".";
                    Name                                        = "a1";
                    Calculate                                    = Calculate.OnBarClose;
                    IsSuspendedWhileInactive                    = true;
                }
                else if (State == State.Configure)
                {
                }
                else if (State == State.DataLoaded)
                {
                    my= new Series<int>(this);
                }
            }
    
            protected override void OnBarUpdate()
            {
                if (CurrentBar<=1) Print(my[249]);
            }
    
        }
    }
    this doesn't fire error. However, if you change the number 249 to 250 it starts firing the:
    "You are accessing an index with a value that is invalid since it is out-of-range. ..."

    My Question, how even `my` Serie can be called for the index that doesn't exist at all? for example, even calling my[1] on the first Bar should trigger the error , but it doesn't.
    If we call i.e. High[1], then it does.

    so I am interested in the backgrounds of the series - are they (unless given "Infinite" bars lookback) somehow "rotating 250 slots" (with pre-filled zero-values below 0 CurrentBar) ?




    #2
    Hello ttodua,

    Thank you for your note.

    In my testing this does indeed give an error when the index is set to 249:

    Click image for larger version

Name:	2020-07-23_12-03-52.png
Views:	440
Size:	277.8 KB
ID:	1110982

    I would expect the error to be thrown no matter what the number there is changed to if it's anything other than 0.

    Please let us know if we may be of further assistance to you.

    Comment


      #3
      Hi,

      we can see in this post that the 256 bars data series does not properly limit a user to using data from less or equal to 256 bars ago.

      https://ninjatrader.com/support/foru...es-out-of-sync

      Click image for larger version  Name:	fetch?photoid=1109955.png Views:	0 Size:	53.6 KB ID:	1110987
      The data at the start of the chart is a copy of the one at the end because the user looped through the data series.
      I'd guess the concept of the limited data series is somewhat similar to this code(without push/pop but synchronization with CurrentBar instead).
      https://stackoverflow.com/questions/...80032#21380032

      This also explains why datasSeries[0] values have to be initialized and return random values if the code does not take care of it. Basically it will return the value that was previously written to the array.
      Last edited by MojoJojo; 07-23-2020, 12:57 PM.

      Comment


        #4
        what could be the reason i dont get the same result? see the video: https://app.box.com/s/tktprjcv3dyvef4zynmp9fncq20qpcw6

        --- Mojo @ thanks for posting your thoughts... interesting about zigzag case.

        Comment


          #5
          Hello ttodua,

          Thank you for your reply.

          The video you provided doesn't seem to be publicly accessible. Could you try hosting it somewhere it's publicly accessible so I can view it?

          Thanks in advance; I look forward to assisting you further.

          Comment


            #6
            Kate, it is publicly available. the site is just confusing, mentioning the words "your account is now allowed.." however that says for "preview". actually there appears the "download" button under that message and download that video (just 1 minute video)

            Comment


              #7
              Hello ttodua,

              Thank you for your reply.

              I was able to reproduce this after seeing your video and changing to a daily series. I do note it does not seem to be reproducible when the MaximumBarsLookback is set to Infinite, and only seems to occur when set to 256.

              I'm going to send this over to our QA team for them to take a look at and see if the developers need to take a look. I'll let you know what I hear from them as soon as I get news.

              Thanks in advance; I look forward to assisting you further.

              Comment


                #8
                yes, the strange thing there is that it even doesnt reach to 256, but rather errors after 250 th index. so, what relations does the numbers (250 and 256) have to each other?

                Comment


                  #9
                  I'm sure I've seen this behavior in the past with NT7 also.
                  eDanny
                  NinjaTrader Ecosystem Vendor - Integrity Traders

                  Comment


                    #10
                    Hello ttodua,

                    Thank you for your patience.

                    After running this by our QA Team, it appears this would be expected behavior.

                    We are seeing consistent behavior on latest build of the platform - you get an error with MaximumBarsLookback.Infinite, and MaximumBarsLookback.TwoHundredFiftySix shows 0’s.

                    This would make sense since TwoHundredFiftySix uses a ring buffer. We can think of this as a sort of middle man, and we wouldn’t get an error because the there are 256 elements in this buffer, and those values are initialized with 0.

                    Tip: A MaximumBarsLookBack.TwoHundredFiftySix series works as a circular ring buffer, which will "loop" when the series reaches full capacity. Specifically, once there are 256 entries in the series, new data added to the series overwrite the oldest data.

                    HelpGuide: https://ninjatrader.com/support/help...rslookback.htm

                    Please let us know if we may be of further assistance to you.

                    Comment


                      #11
                      thanks kate. now it's clear.

                      Comment

                      Latest Posts

                      Collapse

                      Topics Statistics Last Post
                      Started by Geovanny Suaza, 02-11-2026, 06:32 PM
                      0 responses
                      601 views
                      0 likes
                      Last Post Geovanny Suaza  
                      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
                      0 responses
                      347 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by Mindset, 02-09-2026, 11:44 AM
                      0 responses
                      103 views
                      0 likes
                      Last Post Mindset
                      by Mindset
                       
                      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
                      0 responses
                      559 views
                      1 like
                      Last Post Geovanny Suaza  
                      Started by RFrosty, 01-28-2026, 06:49 PM
                      0 responses
                      558 views
                      1 like
                      Last Post RFrosty
                      by RFrosty
                       
                      Working...
                      X