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 AaronKoRn, Today, 09:49 PM
    0 responses
    11 views
    0 likes
    Last Post AaronKoRn  
    Started by carnitron, Today, 08:42 PM
    0 responses
    10 views
    0 likes
    Last Post carnitron  
    Started by strategist007, Today, 07:51 PM
    0 responses
    11 views
    0 likes
    Last Post strategist007  
    Started by StockTrader88, 03-06-2021, 08:58 AM
    44 responses
    3,980 views
    3 likes
    Last Post jhudas88  
    Started by rbeckmann05, Today, 06:48 PM
    0 responses
    9 views
    0 likes
    Last Post rbeckmann05  
    Working...
    X