Multi Directional For Loop , or something similar?

 

Hello, I am fairly new to Mql Programming , so please excuse me if question is somewhat out there.


I need some advice regarding a scenario:


i am checking if an indicator arrow is visible in for loop Like this :

   for(int i = 0; i <= 5000; i++)
     {
       
      if(iCustom(NULL, PERIOD_CURRENT, "ArrowInd", 34, 0, i) != EMPTY_VALUE )
        {
         Buffer1[i] = Low[i] - iATR(NULL, PERIOD_CURRENT, 1, i );  
        }
      else
        {
         Buffer1[i] = EMPTY_VALUE;
        }
 
     }

But i want to check if another Indicator is also visible within 10 candle range of the first indicator, I mean if there is an arrow on "i" then i need to check if there was an arrow from indicator 2 between a certain number of candles .

Example : 

Indicator 1 arrow is visible at candle 50 let say . 
once for loop reaches that candle index (i-e i = 50) now i want to check if indicator 2 arrow is also visible on any of the previous 10 candles (ie on any candle from candle 60 to candle 50) and/or next 10 candles  (i-e on any candle from candle 40 to candle 50)


any suggestions about how i can achieve this ?

Thanks 

 
      for(int i = 0; i <= 5000; i++)
        {
         if(iCustom(NULL, PERIOD_CURRENT, "ArrowInd", 34, 0, i) != EMPTY_VALUE)
           {
            Buffer1[i] = Low[i] - iATR(NULL, PERIOD_CURRENT, 1, i);
            for(int i_2=i-10;i_2<=i+10;i_2++)
              {
               //Do your check
              }
           }
        }

Topics concerning MT4 and MQL4 have their own section.

In future please post in the correct section.

I have moved your topic to the MQL4 and Metatrader 4 section.


 
Avoid array exceeded or looking at non-existant bars.
for(int i_2=i-10;i_2<=i+10;i_2++)
By checking chart limits
for(int i_2=MathMax(0,i-10);i_2<=MathMin(Bars-1,i+10);i_2++)
 
William Roeder:
Avoid array exceeded or looking at non-existant bars.
By checking chart limits

You missed out correcting

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