Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

IsValidDataPoint with Multi-Data Series

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

  • NinjaTrader_ZacharyG
    replied
    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.

    Leave a comment:


  • zr6bcm
    started a topic IsValidDataPoint with Multi-Data Series

    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

Latest Posts

Collapse

Topics Statistics Last Post
Started by lorem, Today, 09:18 AM
0 responses
2 views
0 likes
Last Post lorem
by lorem
 
Started by hazylizard, Today, 08:38 AM
4 responses
11 views
0 likes
Last Post hazylizard  
Started by geddyisodin, Today, 05:20 AM
2 responses
18 views
0 likes
Last Post geddyisodin  
Started by Max238, Today, 01:28 AM
5 responses
47 views
0 likes
Last Post Max238
by Max238
 
Started by giulyko00, Yesterday, 12:03 PM
3 responses
13 views
0 likes
Last Post NinjaTrader_BrandonH  
Working...
X