How can I get Close [0]? - page 3

 
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)

Honestly I don’t understand because too little knowledge of MQL...

Does it mean that by entering the code below, Tick will come and decide if it's the beginning of a new bar?

And what I'm curious about is that the OnTick function returns the Bid price every time a Tick comes, I want to do the same thing with the OnTick function with the Void function.

datetime time0; int init(){ time0 = Time[0];  // No mid bar allowed.
   :
}
int start(){
   bool isNewBar = time0 != Time[0]; time0 = Time[0];
 
Kosei S #: Honestly I don’t understand because too little knowledge of MQL... Does it mean that by entering the code below, Tick will come and decide if it's the beginning of a new bar? And what I'm curious about is that the OnTick function returns the Bid price every time a Tick comes, I want to do the same thing with the OnTick function with the Void function.

It does not matter if it is OnTick or any other function, void or otherwise. You can detect a new bar anywhere in your code.

If you want your function to read Close[0] for later ticks and not just the first tick, then remove the following from your code ...

if(Volume[0]>1) return;

Also read the following:

Code Base

Detecting the start of a new bar or candle

Fernando Carreiro, 2022.04.24 00:46

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

It does not matter if it is OnTick or any other function, void or otherwise. You can detect a new bar anywhere in your code.

If you want your function to read Close[0] for later ticks and not just the first tick, then remove the following from your code ...

Also read the following:

OMG! I did it, Thank you appreciate everyone 

And sorry for the late understanding