What am I missing?
Your script probably resets the `i` variable every time back to zero when the code runs. For instance, if your code comes from the `CalcBar()` method, it looks like:
Code: Select all
protected override void CalcBar()
{
int i = 0;
if(Bars.Close[0] < Bars.Close[1]){i=i+1;}
else{i=0;}
plot1.Set(0, i);
}
With that you reset the `i` variable each time to 0 (first line of code in the method).
To fix that, you'll need to move the declaration and initial assignment of the variable outside of the `CalcBar()` method like so:
Code: Select all
int i = 0;
protected override void CalcBar()
{
if (Bars.Close[0] < Bars.Close[1])
i = i + 1;
else
i = 0;
plot1.Set(i);
}