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?
Comment