How to write a ea that's about to start when the newest tick generated?

 

Hi Guys,

I want to write a ea but when I put it in the chart,

it will wait until the current candle close,

(for example :

 double Close[];

  ArraySetAsSeries(Close,true);

  Copyclose(_Symbol,_Period,0,10,Close);  ),

which is when the tick of Close[0] close, then it became Close[1],

then it just start(I mean before my code start running, I need to write the code that wait until the current candle close, but I don't know how to write)

sorry for my broken english,

if u don't understand any part of it,

please ask me,

I will try my best to explain it.

 
ziyang2048: I want to write a ea but when I put it in the chart, it will wait until the current candle close, ... I need to write the code that wait until the current candle close, but I don't know how to write)

Code Base

Detecting the start of a new bar or candle

Fernando Carreiro, 2022.04.24 00:38

Detecting the start of a new bar or candle, in the OnTick() event handler of an expert advisor.
 

You can't know when a candle closes. Only when a new tick arrives that starts a new bar is the old bar closed.

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.
          MT4: New candle - MQL4 programming forum #3 (2014)
          MT5: Accessing variables - MQL4 programming forum #3 (2022)

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

 
Fernando Carreiro #:
William Roeder #:

You can't know when a candle closes. Only when a new tick arrives that starts a new bar is the old bar closed.

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.
          MT4: New candle - MQL4 programming forum #3 (2014)
          MT5: Accessing variables - MQL4 programming forum #3 (2022)

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

thanks for answering