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 CarlTrading, 03-31-2026, 09:41 PM
        1 response
        134 views
        1 like
        Last Post NinjaTrader_ChelseaB  
        Started by CarlTrading, 04-01-2026, 02:41 AM
        0 responses
        75 views
        1 like
        Last Post CarlTrading  
        Started by CaptainJack, 03-31-2026, 11:44 PM
        0 responses
        119 views
        2 likes
        Last Post CaptainJack  
        Started by CarlTrading, 03-30-2026, 11:51 AM
        0 responses
        114 views
        1 like
        Last Post CarlTrading  
        Started by CarlTrading, 03-30-2026, 11:48 AM
        0 responses
        92 views
        0 likes
        Last Post CarlTrading  
        Working...
        X