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]);
    https://ninjatrader.com/support/help...urrentbars.htm

    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 schmidtbc16, Today, 03:36 PM
    1 response
    9 views
    0 likes
    Last Post NinjaTrader_ChelseaB  
    Started by RT001, Today, 03:25 PM
    2 responses
    15 views
    0 likes
    Last Post RT001
    by RT001
     
    Started by mbrandau, Today, 01:58 PM
    5 responses
    37 views
    0 likes
    Last Post mbrandau  
    Started by remcovdmeulen, Today, 02:15 PM
    1 response
    13 views
    0 likes
    Last Post NinjaTrader_Jim  
    Started by gbrad, Today, 09:57 AM
    7 responses
    17 views
    0 likes
    Last Post NinjaTrader_Jesse  
    Working...
    X