looping through candlesticks and incrementing problem

 

So, I want to loop through candlesticks and see if they meet my conditions and if they do then I want to draw a line but my problem is with the looping. 


For example,


int counter = 10;
for (int i = 0; i<counter; i++){
// some other condiitons for example

if(High[0] > High[i] ) {

//draw line


}
else{

counter++;
}
}

my problem is when the condition is not met, it goes to increment the counter so I can get access to more candlesticks but it never stops. It goes increments to 100 or more. I want it to increment one by one and check until it gets to the closest one that meets the condition that I want it to meet

 
   int counter = Bars-2;
   for (int i = 0; i<counter; i++)
     {
      // some other condiitons for example
      if(High[i] > High[i+1] )
        {
         //draw line
         break;
        }
     }

.

 
Keith Watford:

.

Thank you Keith. The break helped a lil bit. I am trying to always look for the latest candlesticks and it does not meet the conditions then increment by one to look one more further back but it does not seem to behave that way. That is why I did High[0] > High[1] . I understand with the use of i and i + 1 but I want it to look if the current candlestick is bigger than the one before it then it gives me alert. and when I set it to High[0] > High[1] it keeps on incrementing
 

First of all your code did not have

if(High[0] > High[1] ) 

it had

if(High[0] > High[i] ) 

If  High[0] > High[1]  is not true with the first loop, it won't be true the 2nd, 3rd or nth pass.

It makes no sense to increment i and then not use it in the calculations in some way.

Reason: