Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Need to Pre-load DataSeries?

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

    Need to Pre-load DataSeries?

    I have been thinking about DataSeries as arrays. One thing I am not sure of, is what they contain... 0 or Null, or what... if we have not loaded anything into them yet..

    Here is a snippet of code from NinjaTrader_Ray...

    protected override void OnBarUpdate()
    {
    if(CurrentBar < 6)
    return;

    diff.Set(Median[0] - Median[6]);

    double mid = diff[3];
    double wtd = 0.75 * (diff[0] - diff[6]) + 0.25 * (diff[2] - diff[4]);

    diff is a DataSeries, and on the seven bar, he loads (sets) a value into diff[0].... but a few lines later he accesses diff[6], diff[4], diff[2] and does some math with their values.

    What do diff[2], diff[4] and diff[6] contain on the first pass through this code, on the close of the 7th bar?

    I have been pre-loading something in mine to make sure something is there.... maybe I don't have to?

    #2
    I believe that is what NT calls the unstable part of the indicator?

    One thing will be to dump out the values using Print() statements and see what they contain. I would venture to say they are probably zero, as it would appear that diff is not defined before bar 6, so that diff[6] on bar 6 cannot be defined either as that would be diff on bar 0. It is probably not double.MinValue.

    Comment


      #3
      Crassius, they would hold 0 values - we generally advise to not attempt to access a dataseries value for a bar where you would not have called the Set() method for as you could run into exceptions - in the example case it's fine as you would not access those bars used to initialize the code.

      Comment


        #4
        Thanks for the clarification.

        Comment

        Latest Posts

        Collapse

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