# Incorrect (empty body) 'for' loop

I am trying to use a bar by bar analysis inside a loop. Having problem with the returned values
Below is the code snippet and the debugger results

X[i] is used on a bar by bar basis and return values are seemingly random.
Y is used as an array and the values are normal 1 or 0

``````for (i=1; i < BarCount-1; i++);
{

X[i]		= CCI1[i] < 0 AND CCI1_slope[i] > 0;
Y		= CCI1    < 0 AND CCI1_slope    > 0;
etc
`````` Did you initialize X before the loop? Also your for loop has incorrect upper limit (should be BarCount)

``````X = 0; // init
for( i = 0; i < BarCount; i++ )
{
....
}
``````

X was not initialized before the loop.

After initializing, the random values are no longer, but all values for X are zero Also, if I change the upper limit for the loop, line starting with X[i] produces error "Array subscript out of range".
If I comment out the X[i] line, The line starting with "Y = " works fine. As always: post ENTIRE formula. Really. We can’t help you unless we can copy-paste the code on OUR end and check what is wrong with the ENTIRE formula. Your problem is apparently OUTSIDE the small snippets that you post.

Tomasz, Entire AFL is attached

If I change the upper bound of the loop to barcount -1, I do not get the error, but all values of X are 0 (zero)   The mistake you are making is semicolon right after for() statement.
You’ve got this:

``````for( i = 1; i < BarCount; i++ ) ;  // THIS semicolon is the entire body of for loop

// subsequent block is executed AFTER for loop
// so 'i' variable is equal BarCount (one too much)
{
...
}

``````

You should have for loop written the way I WROTE in original reply.

``````X = 0; // init
for( i = 0; i < BarCount; i++ )
{
....
}
``````

NOTE there is NO SEMICOLON after for.