I'm trying to loop through a reasonable lookback (in this case 20) to print out the consecutive number of bars that have closed either up or down, but the values that are printing are incorrect.
What am I doing wrong?
for(int i = 2; i <= lookback; i++)
{
double nBarsUpValue = NBarsUp(i, true, false, false)[0];
double nBarsDownValue = NBarsDown(i, true, false, false)[0];
if(nBarsUpValue == 1)
{
consecutiveUpBars = i;
}
if(nBarsDownValue == 1)
{
consecutiveDownBars = i;
}
}
It looks like the values that I'm printing may be correct and that the issue is in getting it to plot correctly so I'm attaching the whole code.

Comment