Difference between Void OnInit and Void Ontick

William Roeder  
Fujin: But for OnInit i tought it detect every new candle on the chart?

OnInit is called once when the EA is first loaded, and when things like timeframe changes. Nothing to do with a new bar.

Fujin  
William Roeder #:

OnInit is called once when the EA is first loaded, and when things like timeframe changes. Nothing to do with a new bar.

 Oh i understand more now,

Is there a function already created that the ea detect each new bar?

Willbur  
Fujin #:

 Oh i understand more now,

Is there a function already created that the ea detect each new bar?

No. OnTicks is called on every change (deal or ask/bit) at the exchange.
You have to find out for yourself whether  a new tick starts a new bar.
There are some discussions and examples about this here in the forum.
William Roeder  
Fujin #: Is there a function already created that the ea detect each new bar?

If you had used this, you would have found many.

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. A variable can be tested multiple times.
          Running EA once at the start of each bar - MQL4 programming forum (2011)

Reason: