Announcement

Collapse

Looking for a User App or Add-On built by the NinjaTrader community?

Visit NinjaTrader EcoSystem and our free User App Share!

Have a question for the NinjaScript developer community? Open a new thread in our NinjaScript File Sharing Discussion Forum!
See more
See less

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.
      BertrandNinjaTrader Customer Service

      Comment


        #4
        Thanks for the clarification.

        Comment

        Latest Posts

        Collapse

        Topics Statistics Last Post
        Started by cre8able, 02-11-2023, 05:43 PM
        3 responses
        235 views
        0 likes
        Last Post rhubear
        by rhubear
         
        Started by frslvr, 04-11-2024, 07:26 AM
        8 responses
        113 views
        1 like
        Last Post NinjaTrader_BrandonH  
        Started by stafe, 04-15-2024, 08:34 PM
        10 responses
        45 views
        0 likes
        Last Post stafe
        by stafe
         
        Started by rocketman7, Today, 09:41 AM
        3 responses
        11 views
        0 likes
        Last Post NinjaTrader_Jesse  
        Started by traderqz, Today, 09:44 AM
        2 responses
        10 views
        0 likes
        Last Post NinjaTrader_Gaby  
        Working...
        X