IsNewCandle not branching to true

 
Hi guys and complements. The following is a code is designed to show true if a new candle is seen for the given time frame (Not necessarily the current timeframe) . However it does not branch to the 'true' section, only to all the 'false' sections. What could be wrong with the code pls. Thanks in advance.
void OnTick()
  {
   if (IsNewBarOnTimeframe(PERIOD_M1)==true)Print("New bar Period M1 found");
   if (IsNewBarOnTimeframe(PERIOD_M5)==true)Print("New bar Period M5 found");
   if (IsNewBarOnTimeframe(PERIOD_M15)==true)Print("New bar Period M15 found");
   if (IsNewBarOnTimeframe(PERIOD_M30)==true)Print("New bar Period M30 found");
   if (IsNewBarOnTimeframe(PERIOD_H1)==true)Print("New bar Period H1 found");
   if (IsNewBarOnTimeframe(PERIOD_H4)==true)Print("New bar Period H4 found");
   if (IsNewBarOnTimeframe(PERIOD_D1)==true)Print("New bar Period D1 found");
   if (IsNewBarOnTimeframe(PERIOD_W1)==true)Print("New bar Period W1 found");
   if (IsNewBarOnTimeframe(PERIOD_MN1)==true)Print("New bar Period MN found");
  }



bool IsNewBarOnTimeframe(ENUM_TIMEFRAMES timeframe = PERIOD_CURRENT)
{
   static ENUM_TIMEFRAMES tf = PERIOD_CURRENT;
   static datetime last_bar = 0;
   if(timeframe != tf && timeframe != PERIOD_CURRENT)
   {
      tf = timeframe;
      last_bar = 0;
   }
   datetime curr_bar = (datetime)SeriesInfoInteger(_Symbol,tf,SERIES_LASTBAR_DATE);
   if(last_bar == 0)
   {
      last_bar = curr_bar;
      return false;
   }
   if(last_bar != curr_bar)
   {
      last_bar = curr_bar;
      return true;
   }
   return false;
}
 
   if (IsNewBarOnTimeframe(PERIOD_M1)==true)Print("New bar Period M1 found");
   if (IsNewBarOnTimeframe(PERIOD_M5)==true)Print("New bar Period M5 found");
   if (IsNewBarOnTimeframe(PERIOD_M15)==true)Print("New bar Period M15 found");
   if (IsNewBarOnTimeframe(PERIOD_M30)==true)Print("New bar Period M30 found");
   if (IsNewBarOnTimeframe(PERIOD_H1)==true)Print("New bar Period H1 found");
   if (IsNewBarOnTimeframe(PERIOD_H4)==true)Print("New bar Period H4 found");
   if (IsNewBarOnTimeframe(PERIOD_D1)==true)Print("New bar Period D1 found");
   if (IsNewBarOnTimeframe(PERIOD_W1)==true)Print("New bar Period W1 found");
   if (IsNewBarOnTimeframe(PERIOD_MN1)==true)Print("New bar Period MN found");

For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
          New candle - MQL4 programming forum #3 2014.04.04

I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
          Running EA once at the start of each bar - MQL4 programming forum 2011.05.06

Your code will never work.

 
William Roeder:

For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
          New candle - MQL4 programming forum #3 2014.04.04

I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
          Running EA once at the start of each bar - MQL4 programming forum 2011.05.06

Your code will never work.

All I see here is criticism. I need solutions please. Thanks
Even with global variable as a check don't you think it can work?
 
William Roeder:

For a new bar test, Bars is unreliable (a refresh/reconnect can change number of bars on chart), volume is unreliable (miss ticks), Price is unreliable (duplicate prices and The == operand. - MQL4 programming forum.) Always use time.
          New candle - MQL4 programming forum #3 2014.04.04

I disagree with making a new bar function, because it can only be called once per tick. A variable can be tested multiple times.
          Running EA once at the start of each bar - MQL4 programming forum 2011.05.06

Your code will never work.

Don't be an enemy of progress by using such pessimistic words. My code will work.

 
macpee:

Don't be an enemy of progress by using such pessimistic words. My code will work.

Your code will not work.

You even say so yourself.

macpee:
Hi guys and complements. The following is a code is designed to show true if a new candle is seen for the given time frame (Not necessarily the current timeframe) . However it does not branch to the 'true' section, only to all the 'false' sections. What could be wrong with the code pls. Thanks in advance.

Your code is so strange that I cannot work out what you are trying to do.

Maybe you should consider storing all the last bar times in an array.