Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

IsValidDataPoint with Multi-Data Series

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

    IsValidDataPoint with Multi-Data Series

    I am attempting to load a number of data series. For some strange reason, one data series fails to load (problem for another day). What I want to do, is just catch this error and then ignore this data series for this moment.

    To check whether the data series is valid, I use the call IsValidDataPoint. This works for the correct data series, but it also returns true for the one data series that failed to load.

    It looks for me (naively), like IsValidDataPoint is returning true when it should not.

    (I have searched this forum and also read the sentences about MaximumBarsLookBack.TwoHundredFiftySix, but dont think this is valid, as it works for the other data series.)

    Here is the sample code. First I load three extra data series. The last series ^RUI fails to load, but that is exactly what I want to test.

    Code:
    if (State == State.Configure)
    {
      AddDataSeries("^NDX", Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);
      AddDataSeries("^OEX", Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);
      AddDataSeries("^RUI", Data.BarsPeriodType.Day, 1, Data.MarketDataType.Last);
    }
    Now, because I know that Closes[3][0] will blow up, I use IsValidDataPoint first to ensure that the data point is valid. Here the code:

    Code:
    protected override void OnBarUpdate()
    {			
        if (CurrentBar <= 20 || BarsInProgress != 0)
            return;
        for(int idx=0; idx<Closes.Length; idx++)
            if (Closes[idx].IsValidDataPoint(0))
                Print(Closes[idx][0]);
    }
    What gets printed:

    Code:
    1304.27
    1581.95
    602.82
    Indicator 'TEST_IsValidDataPoint': Error on calling 'OnBarUpdate' method on bar 21: You are accessing an index with a value that is invalid since it is out-of-range. I.E. accessing a series [barsAgo] with a value of 5 when there are only 4 bars on the chart.
    This means that Closes[3].IsDataPointValid(0) returned TRUE and then the Closes[3][0] blew up. (Checked in debugger.)

    Am I overseeing anything obvious?

    Thanks, Brian

    #2
    Hello zr6bcm,

    Thank you for writing in.

    The reason why IsValidDataPoint() returned true is because a Bars object exists for Closes[idx].

    I would suggest this check instead:
    Code:
    if (Closes[idx].Count > 0)
         Print(Closes[idx][0]);
    
    // alternative
    if (CurrentBars[idx] > -1)
         Print(Closes[idx][0]);


    This would prevent the print from occurring if no bars exist for the series you are trying to access.

    Please, let us know if we may be of further assistance.
    Zachary G.NinjaTrader Customer Service

    Comment

    Latest Posts

    Collapse

    Topics Statistics Last Post
    Started by geddyisodin, 04-25-2024, 05:20 AM
    8 responses
    60 views
    0 likes
    Last Post NinjaTrader_Gaby  
    Started by jxs_xrj, 01-12-2020, 09:49 AM
    4 responses
    3,287 views
    1 like
    Last Post jgualdronc  
    Started by Option Whisperer, Today, 09:55 AM
    0 responses
    5 views
    0 likes
    Last Post Option Whisperer  
    Started by halgo_boulder, 04-20-2024, 08:44 AM
    2 responses
    22 views
    0 likes
    Last Post halgo_boulder  
    Started by mishhh, 05-25-2010, 08:54 AM
    19 responses
    6,189 views
    0 likes
    Last Post rene69851  
    Working...
    X