OnTick() or OnTimer()?

 

Hello folks, 

 I'm building an EA that must place a trade at the beginning of a new bar. Regarding to less time delay from the opening time of the new bar, which one is more recommended to use: OnTick() or OnTimer()?

 
A new bar requires a new tick, so just use OnTick() and check for a new bar
 
GumRai:
A new bar requires a new tick, so just use OnTick() and check for a new bar
Thanks.
 
GumRai:
A new bar requires a new tick, so just use OnTick() and check for a new bar
Aren't there multiple ticks on each bar?  Like when the price changes at all, doesn't that generate a new tick?  Not very familiar with MQL, sorry if this is obvious to everybody else.
 
JD4:
Aren't there multiple ticks on each bar?  Like when the price changes at all, doesn't that generate a new tick?  Not very familiar with MQL, sorry if this is obvious to everybody else.

Yes, usually. However, each bar can only have 1 first tick

The open time of a bar is stored in a static/globalscope variable.

At each tick the open time of the current bar is compared to the value. If it is not the same, then it must be the first tick of a new bar (received by the Expert)

The variable is reassigned the value of the current bar's open time in order to check for the next new bar.

 
GumRai:

Yes, usually. However, each bar can only have 1 first tick

The open time of a bar is stored in a static/globalscope variable.

At each tick the open time of the current bar is compared to the value. If it is not the same, then it must be the first tick of a new bar (received by the Expert)

The variable is reassigned the value of the current bar's open time in order to check for the next new bar.

Makes sense.  TY for the answer.
 
JD4: Aren't there multiple ticks on each bar? 
  1. not necessarily, "Free-of-Holes" Charts - MQL4 Articles
  2. Ticks per bar vary wildly (100x) from broker to broker.
 
GumRai:

Yes, usually. However, each bar can only have 1 first tick

The open time of a bar is stored in a static/globalscope variable.

At each tick the open time of the current bar is compared to the value. If it is not the same, then it must be the first tick of a new bar (received by the Expert)

The variable is reassigned the value of the current bar's open time in order to check for the next new bar.

Just thought of something again on this.  When using OnTick(), which will work because of the bar needing that first tick anyway, how is it to differentiate between that (infamous) first tick, and any following ticks related to that same bar?
 
JD4:
Just thought of something again on this.  When using OnTick(), which will work because of the bar needing that first tick anyway, how is it to differentiate between that (infamous) first tick, and any following ticks related to that same bar?

Strange that you quote my post which has already answered your question

GumRai:

Yes, usually. However, each bar can only have 1 first tick

The open time of a bar is stored in a static/globalscope variable.

At each tick the open time of the current bar is compared to the value. If it is not the same, then it must be the first tick of a new bar (received by the Expert)

The variable is reassigned the value of the current bar's open time in order to check for the next new bar.

 If it is not the same, then it must be the first tick of a new bar (received by the Expert)

It follows that if it IS the same, it must be a subsequent tick 

 
GumRai:

Strange that you quote my post which has already answered your question

 If it is not the same, then it must be the first tick of a new bar (received by the Expert)

It follows that if it IS the same, it must be a subsequent tick 

Sorry, must have been half asleep when I was reading it, because I did not see that until now, going back and re-reading it after you re-pointed it out to me.