To replicate this error.
1) import attached indicator.
2) add the indicator to a chart with 3 data series. press the apply button. the indicator automatically detects all 3 series and adds them to the barsarray.
3) remove the 3rd indicator name from parameters. press Apply/OK. in the initialize method, the 3rd instrumnt is no longer added to the bars array.
Result: The chart fails to plot. Is this by design? How can I update the number of instruments used by the indicator?
Thanks
Code:
protected override void Initialize()
{
int barValue;
DrawOnPricePanel = false; // TRUE - Draw objects paint on price panel; FALSE - indicator panel.
Overlay = false; // TRUE - Indicator plots drawn on top of price; FALSE - Indicator drawn separate panel
Add(new Plot(Color.Black, PlotStyle.Line, "MyClose"));
barValue = Math.Max(1,base.BarsPeriod.Value);
Add(symbol2, BarsPeriod.Id, barValue);
if (symbol3!="" && symbol3!=null)
Add(symbol3, BarsPeriod.Id, barValue);
}
protected override void OnBarUpdate()
{
MyClose.Set(Close[0]);
}
#region Properties
[Browsable(false)] // this line prevents the data series from being displayed in the indicator properties dialog, do not remove
[XmlIgnore] // this line ensures that the indicator can be saved/recovered as part of a chart template, do not remove
public DataSeries MyClose
{
get { return Values[0]; }
}
private string symbol1="";
[Description("")]
[GridCategory("\t\t\t\t\tInstrument 1 Parameters")]
[Gui.Design.DisplayName ("\t\t\t\tSymbol")]
public string Symbol1
{
get
{
if (((symbol1 == "") || (symbol1 == null)) && (ChartControl != null) && (Instruments != null))
{
symbol1=ChartControl.BarsArray[0].Instrument.FullName;
}
return symbol1;
}
set
{
if((symbol1 == "") || (symbol1 == null))
{
symbol1=value;
}
}
}
private string symbol2 = @"";
[Description("")]
[GridCategory("\t\t\t\tInstrument 2 Parameters")]
[Gui.Design.DisplayName ("\t\t\t\tSymbol")]
public string Symbol2
{
get
{ // symbol2 defaults to secondary chart data series
if (((symbol2 == "") || (symbol2 == null)) && (ChartControl != null) && (Instruments != null))
{
symbol2 = ChartControl.BarsArray[1].Instrument.FullName;
}
return symbol2;
}
set { symbol2 = value; }
}
private string symbol3 = @"";
[Description("")]
[GridCategory("\t\t\t\tInstrument 3 Parameters")]
[Gui.Design.DisplayName ("\t\t\t\tSymbol")]
public string Symbol3
{
get
{ // symbol3 defaults to secondary chart data series
if (((symbol3 == "") || (symbol3 == null)) && (ChartControl != null) && (Instruments != null))
{
symbol3 = ChartControl.BarsArray[2].Instrument.FullName;
}
return symbol3;
}
set
{
// check for update Symbol3Units default...
symbol3 = value;
}
}
#endregion
Comment