Thursday, September 17, 2015

How to check if a new candle has been opened from an MT4 Expert Advisor

When programming an MT4 robot, you often need to perform certain actions only at the beginning of a new candle. This can be either for execution speed reasons or because of the logic flow of your trading system.

Here is a boolean (true/false) MQL4 function that returns true whenever a new candle has closed/opened on the given timeframe:


bool IsNewCandle(int tf=0)
  {
   static datetime timeLastCandle=0;
   if(iTime(Symbol(),tf,0)==timeLastCandle)
      return (false);
   timeLastCandle=iTime(Symbol(),tf,0);
   return(true);
  }

Let me know if you would have done it differently.

1 comment:

  1. As reported by Stanford Medical, It's in fact the ONLY reason women in this country get to live 10 years longer and weigh 19 KG lighter than we do.

    (And by the way, it has absoloutely NOTHING to do with genetics or some secret diet and really, EVERYTHING to around "how" they are eating.)

    P.S, What I said is "HOW", and not "what"...

    Click this link to find out if this quick test can help you discover your true weight loss possibility

    ReplyDelete