How can I tell my EA that a new candle has arrived?

 
How can I program my EA to do something when a new candle has appeared? What is the command for a new candle appearing? Anything like:
OnNewBar()
I need to do something when a new candle arrives, e.g. to reinitialize the content of a variable.
E.g.: 

if (A New Bar Arrives) {MyVariable = '' '';}
 
macpee:
How can I program my EA to do something when a new candle has appeared? What is the command for a new candle appearing? Anything like:
OnNewBar()
I need to do something when a new candle arrives, e.g. to reinitialize the content of a variable.
E.g.: 

if (A New Bar Arrives) {MyVariable = '' '';}
OK thanks
I saw this somewhere

bool NewBar()
{
static datetime lastbar;
datetime curbar = Time[0];
if(lastbar!=curbar)
{
lastbar=curbar;
return (true);
}
else
{
return(false);
}
}
 
 
 
macpee: How can I program my EA to do something when a new candle has appeared?

If you had used this you would have found many results for new candle or new bar.
    How can I search for indicators and other elements in this forum? - MQL5 programming forum 2017.05.28
    How To Ask Questions The Smart Way. 2004
      How To Interpret Answers.
          RTFM and STFW: How To Tell You've Seriously Screwed Up.

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

 
William Roeder:

If you had used this you would have found many results for new candle or new bar.
    How can I search for indicators and other elements in this forum? - MQL5 programming forum 2017.05.28
    How To Ask Questions The Smart Way. 2004
      How To Interpret Answers.
          RTFM and STFW: How To Tell You've Seriously Screwed Up.

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


Lols. You sure got some askers on that. Thanks anyways.

What if I use the if statement

if (TimeCurrent() == Time[0]) {bla bla bla;}

I think it would produce the required result.

 
macpee:
How can I program my EA to do something when a new candle has appeared? What is the command for a new candle appearing? Anything like:
OnNewBar()
I need to do something when a new candle arrives, e.g. to reinitialize the content of a variable.
E.g.: 

if (A New Bar Arrives) {MyVariable = '' '';}


datetime lastbar;

bool NewBar()
{
if(lastbar!=Time[1])
{
lastbar=Time[1];
return (true);
}
else
{
return(false);
}
}

there is big difference between Time[0] and Time[1] in that context!
 
macpee:

Please edit your post and

use the code button (Alt+S) when pasting code

 
Issam Kadhi:

Please edit your post and

use the code button (Alt+S) when pasting code

 
macpee: What if I use the if statement

if (TimeCurrent() == Time[0]) {bla bla bla;}

I think it would produce the required result.

Think again, then test it (live). Will not work if you miss a tick. See #2

Reason: