title: How do I detect new bars multiple times?
body: <p>This EA is supposed to detect new bars and Alert some info, but it only detects the first new bar (not the next ones). Any idea why? Also, The MaxPercent function doesn't run nicely and the 'Alert' inside it doesn't show. Please helpppppppppppppppppppppppppppp.
  My code:</p>
  <pre><code>    static double barOpen1 = Open[0]; 
      static double barOpen2 = Open[5];   
      
      int IsNewCandle()
      {
      
           if(barOpen1 != Open[0] || barOpen2 != Open[5]) //If any of the statements pass, a new candle must have opened changing the index number.
           {        
              barOpen1 = Open[0]; // Update variables with current prices
              barOpen2 = Open[5];
              Alert(&quot;New bar. The time is: &quot;,TimeToStr(TimeCurrent(),TIME_SECONDS));
              return(1);
           }
           else
            {
            return(0);
            }
      
      }
      //--------MaxPercent-------      
      double MaxPercent(string Pair, int First, int Last)
      {
         double Highest = 0;
      
         for (int p = First; p &lt;= Last; p++)
         {
         if(iHigh(&quot;Pair&quot;,PERIOD_H1,p)&gt; Highest)
            {
            Highest = iHigh(&quot;Pair&quot;,PERIOD_H4,p);
            Alert(&quot;Inside MaxPercent(), Highest= &quot;,DoubleToStr(Highest));   
            }
            
         };
         return((Highest/(iOpen(&quot;Pair&quot;,PERIOD_H1,Last)))-1);
      }
      //--------MinPercent-------
      double MinPercent(string Pair, int First, int Last)
      {
         double Lowest = 0;
         for (int p = First; p &lt;= Last; p++)
         {
         if(iLow(&quot;Pair&quot;,PERIOD_H1,p) &lt; Lowest )
            {
            Lowest = iLow(&quot;Pair&quot;,PERIOD_H1,p);
            }
         };
         return((Lowest/(iOpen(&quot;Pair&quot;,PERIOD_H1,Last)))-1);
      } 
      //-----ClosePercent--------------
      double ClosePercent(string Pair, int First, int Last)
      {
         return(((iClose(&quot;Pair&quot;,PERIOD_H1,First))/(iClose(&quot;Pair&quot;,PERIOD_H1,Last)))-1);
      } 
      void PrintDataEURUSD()
      {
      double MaxPercentD1EURUSD = MaxPercent(&quot;EURUSD&quot;, 1, 3);
      Alert(&quot;MaxPercentD1EURUSD is: &quot;, MaxPercentD1EURUSD );
      
      } 
      void OnTick()
         {
         if(IsNewCandle()==1)
            {  
            PrintDataEURUSD(); 
            }
         }
  </code></pre>
  <p>Thanks</p>