Facing problem with and in if

 

I have following code that is giving different result with two different for loops

1. for (i=0, i<10,i++);

2. for (i=10,i>0,i--);

sample code is

if(counted_bars<0) return(-1);

if(counted_bars>0) counted_bars--;

limit=Bars-counted_bars;

for(int i=0; i<limit; i++)

{

...

....

....

if((a1>0) && (d1==45678))

{

..

..

}

else if((a1<0) && ( d2==45678))

{

..

..

}

some having some idea......


 
amitgvarun:

I have following code that is giving different result with two different for loops

1. for (i=0, i<10,i++);

2. for (i=10,i>0,i--);


  1. Play video
    Please edit your post.
    For large amounts of code, attach it.

  2. You didn't show any real code and there are no mind readers here.
  3. But since you get different results, you are using left over values in your variables from one iteration to the next.
    limit=Bars-counted_bars;
    for(int i=0; i<limit; i++){
      :
      if((a1>0) && (d1==45678))
    Limit will normally be 1 so a1 and d1 MUST be calculated either inside the loop or before the loop starts using only OHLC or your buffer[limit]
  4. Always count down.
Reason: