Difference between Void OnInit and Void Ontick

 

I tought at the begining Void OnTick was used for detect new change of price per exemple when the begening's price was at 1.00 and then go at 1.01 you have a new detection bc its a new Tick

But for OnInit i tought it detect every new candle on the chart?


Can somebody clear me out?

 
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.

 
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?

 
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.
 
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)