Go backwards if condition is not met. (Code Help )

 

I am having a problem with traversing bars backwards. 

I have a condition and if it is not met then I want it to change the bars it is focusing on and look backwards and stop when it meets the condition.


I have this for loop


int counter = 250;

for(int i = 0; i< counter; i++){
        if(High[i] < High[0]){

        // draw a line for example
}else{
        i++;

}


}

when I do this, it keeps on incrementing and it does not stop. I want it as soon as it finds the i that is less than current high of candlestick it stops and draws a line for example, but it goes to thousands. Is there a way to go back one by one and check until the condition is met?



I want it to go from 0 to whatever number of candlesticks until it finds it. I know the first if should work and do not stop until it finds it but it does not seem to work that way. I am not sure why

Documentation on MQL5: Common Functions / GetTickCount64
Documentation on MQL5: Common Functions / GetTickCount64
  • www.mql5.com
GetTickCount64 - Common Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 

Your code won't go to 1000's, the value of counter will stop it at 249.

I find your formatting very confusing.

This should do as you want.

   int counter = 250;
   for(int i = 1; i< counter; i++)
     {
      if(High[i] < High[0])
        {
         // draw a line for example
         break;
        }
     }
 
Keith Watford:

Your code won't go to 1000's, the value of counter will stop it at 249.

I find your formatting very confusing.

This should do as you want.

I actually figured out the problem with my code not to be this one. As soon as I typed the question and typed the code ( did not copy it from the editor) I realized what my mistake was which is a really small mistake that was causing the bug I was having. I really appreciate your help though. Thank you so much. 

 
aalrehn:

I actually figured out the problem with my code not to be this one. As soon as I typed the question and typed the code ( did not copy it from the editor) I realized what my mistake was which is a really small mistake that was causing the bug I was having. I really appreciate your help though. Thank you so much. 

Then why didn't you delete your post??

Reason: