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 Geovanny Suaza, 02-11-2026, 06:32 PM
      0 responses
      585 views
      0 likes
      Last Post Geovanny Suaza  
      Started by Geovanny Suaza, 02-11-2026, 05:51 PM
      0 responses
      340 views
      1 like
      Last Post Geovanny Suaza  
      Started by Mindset, 02-09-2026, 11:44 AM
      0 responses
      103 views
      0 likes
      Last Post Mindset
      by Mindset
       
      Started by Geovanny Suaza, 02-02-2026, 12:30 PM
      0 responses
      554 views
      1 like
      Last Post Geovanny Suaza  
      Started by RFrosty, 01-28-2026, 06:49 PM
      0 responses
      552 views
      1 like
      Last Post RFrosty
      by RFrosty
       
      Working...
      X