OnTick() or OnTimer()?

Back to topics list To post a new topic, please log in or register
avatar
4
marcosdnm 2015.05.28 02:24
 

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()?

avatar
Moderator
3407
GumRai 2015.05.28 03:13 #
 
A new bar requires a new tick, so just use OnTick() and check for a new bar
avatar
4
marcosdnm 2015.06.01 14:42 #
 
GumRai:
A new bar requires a new tick, so just use OnTick() and check for a new bar
Thanks.
avatar
313
JD4 2015.06.25 02:16 #
 
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.
avatar
Moderator
3407
GumRai 2015.06.25 03:45 #
 
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.

avatar
313
JD4 2015.06.25 03:50 #
 
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.
avatar
12985
WHRoeder 2015.06.25 13:59 #
 
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.

avatar
313
JD4 2015.06.27 07:25 #
 
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?
avatar
Moderator
3407
GumRai 2015.06.27 08:20 #
 
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 

avatar
313
JD4 2015.06.27 19:50 #
 
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. 
Back to topics list  

To add comments, please log in or register