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 inanazsocial, Today, 01:15 AM
    1 response
    5 views
    0 likes
    Last Post NinjaTrader_Jason  
    Started by rocketman7, Today, 02:12 AM
    0 responses
    6 views
    0 likes
    Last Post rocketman7  
    Started by dustydbayer, Today, 01:59 AM
    0 responses
    1 view
    0 likes
    Last Post dustydbayer  
    Started by trilliantrader, 04-18-2024, 08:16 AM
    5 responses
    23 views
    0 likes
    Last Post trilliantrader  
    Started by Davidtowleii, Today, 12:15 AM
    0 responses
    3 views
    0 likes
    Last Post Davidtowleii  
    Working...
    X