Announcement

Collapse
No announcement yet.

Partner 728x90

Collapse

Multiple instrument out of range

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

    Multiple instrument out of range

    Suppose I make an indicator where I simply plot the close of a second instrument as an indicator. This is of course easy to do with:

    Add( <instrument>, PeriodType.Day, 1 );

    and

    protected override void OnBarUpdate()
    {
    plot0.Set(Closes[1][0]);
    }

    This works fine until I select a range on my chart where the primary instrument doesn't have any data. For example, if I have data for MSFT from 1/1/1990 and IBM from 1/1/1980. I use MSFT as my primary instrument and I plot IBM as an indicator using the method above. As long as I don't choose an earlier startdate than 1/1/1990 for my chart there is no problem. However if I choose for example 1/1/1989 as startdate I get an error message: "You are accessing an index with a value that is invalid since its out of range".

    If I have only the primary instrument on my chart without the indicator then there is no problem. Even if I select the chart to start on 1/1/1989, it will simply start from 1/1/1990 because it has no earlier data. However when using the indicator based on a second instrument it gives an error. It apparently gets an invalid index.

    How can I prevent this from happening in my code? I want to make it robust, so maybe I need to somehow check if the primary series exists before doing plot0.Set(Closes[1][0])? How can I do that?

    #2
    FireFly, please try including a CurrentBars check for all involved series - for example :

    if (CurrentBars[0] <= BarsRequired || CurrentBars[1] <= BarsRequired)
    return;

    Comment


      #3
      @NinjaTrader_Bertrand: that doesn't solve the problem.

      BUT it seems I have already solved the problem by simply using

      if (BarsInProgress == 0)
      {

      }

      How stupid that I didn't think about that earlier!

      Comment

      Latest Posts

      Collapse

      Topics Statistics Last Post
      Started by Hwop38, 05-04-2026, 07:02 PM
      0 responses
      164 views
      0 likes
      Last Post Hwop38
      by Hwop38
       
      Started by CaptainJack, 04-24-2026, 11:07 PM
      0 responses
      319 views
      0 likes
      Last Post CaptainJack  
      Started by Mindset, 04-21-2026, 06:46 AM
      0 responses
      246 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by M4ndoo, 04-20-2026, 05:21 PM
      0 responses
      350 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Started by M4ndoo, 04-19-2026, 05:54 PM
      0 responses
      179 views
      0 likes
      Last Post M4ndoo
      by M4ndoo
       
      Working...
      X