How to find new candle (new bar) use MQL programming?

Here are two ways to identify a new candlestick using MQL for MetaTrader.

static int BARS;
bool IsNewCandle()
  {
   if(BARS!=Bars(Symbol(),PERIOD_CURRENT))
     {
      BARS=Bars(Symbol(),PERIOD_CURRENT);
      return(true);
     }
   return(false);
  }
datetime NewCandleTime=TimeCurrent();
datetime NewCandleTime=TimeCurrent();
bool IsNewCandle(){
   if(NewCandleTime==iTime(Symbol(),0,0)) return false;
   else{
      NewCandleTime=iTime(Symbol(),0,0);
      return true;
   }
}
 

Share with your friends

bitcoin analysis

ETH

We suggest buying Atrium for a short period of time...

Shopping Cart
Scroll to Top