My indicator is simply supposed to draw a green line when up, and red when down. Here's the logic:
#region Variables
private DataSeries vol;
#endregion
protected override void Initialize()
{
Add(new Plot(new Pen(Color.Orange, 2), PlotStyle.Line, "Plot0"));
Add(new Plot(new Pen(Color.Indigo, 2), PlotStyle.Line, "Plot1"));
Add(new Plot(new Pen(Color.LimeGreen, 2), PlotStyle.Line, "Up"));
Add(new Plot(new Pen(Color.DarkRed, 2), PlotStyle.Line, "Down"));
Add(new Plot(new Pen(Color.Yellow, 2), PlotStyle.Line, "Neutral"));
vol = new DataSeries(this);
}
protected override void OnBarUpdate()
{
double newSlope = 0;
double study = 0;
double primary = 0;
if (CurrentBar == 0)
{
return;
}
else
{
newSlope = (Volume[0] - Volume[1]) / (ToTime(Time[0]) - ToTime(Time[1]));
vol.Set(newSlope);
study = SMA(vol, 6)[0];
primary = vol[1]+vol[0];
//
//Plot0.Set(primary);
Plot1.Set(study);
if (vol[0] > vol[1])
{
Up.Set(primary);
}
else if (vol[0] < vol[1])
{
Down.Set(primary);
}
else
{
Neutral.Set(primary);
}
//DrawHorizontalLine("L", Low[1], Color.Yellow);
}
}
If I comment out the if/elseif/else condition, the study works(without colors of course). AND if I print out "hey" in the second condition (vol[0] < vol[1]) "hey" prints to the output window. There's something funky in the vol[n] ...why is this giving me the "Index out of bounds of array" error?
Comment