Download MetaTrader 5
To add comments, please log in or register
Trade like successful traders - subscribe to their signals!
Marcos Maia
159
Marcos Maia 2015.05.28 00: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()?

Keith Watford
Moderator
7887
Keith Watford 2015.05.28 01:13  
A new bar requires a new tick, so just use OnTick() and check for a new bar
Marcos Maia
159
Marcos Maia 2015.06.01 12:42  
GumRai:
A new bar requires a new tick, so just use OnTick() and check for a new bar
Thanks.
JD4
1101
JD4 2015.06.25 00: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.
Keith Watford
Moderator
7887
Keith Watford 2015.06.25 01: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.

JD4
1101
JD4 2015.06.25 01: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.
whroeder1
13596
whroeder1 2015.06.25 11: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.
JD4
1101
JD4 2015.06.27 05: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?
Keith Watford
Moderator
7887
Keith Watford 2015.06.27 06: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 

JD4
1101
JD4 2015.06.27 17: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. 
/
To add comments, please log in or register