How often is OnTick function called?

To add comments, please log in or register
Samanmalee
33
Samanmalee  
Hi Im new to MQL4. As I understood from what I read online, OnTick() is called when a new tick comes. I understood as a change in the chart graph, i.e. price change. But when I attached my tester EA with counter to increase everytime the OnTick is called, it keeps on increasing every second. Id OnTick called every second even though there may not be any price changes in the chart Symbol? Any response appreciated. Thanks.
Marco vd Heijden
Moderator
12670
Marco vd Heijden  

Hello incoming ticks vary with market activity you can see tick volumes by using iVolume() function.

https://www.mql5.com/en/docs/series/ivolume

Documentation on MQL5: Timeseries and Indicators Access / iVolume
Documentation on MQL5: Timeseries and Indicators Access / iVolume
  • www.mql5.com
The tick volume of the bar (indicated by the 'shift' parameter) on the corresponding chart or 0 in case of an error. For error details, call the GetLastError() function. The function always returns actual data. For this purpose it performs a request to the timeseries for the specified symbol/period during each call. This means that if there is...
Samanmalee
33
Samanmalee  
Marco vd Heijden:

Hello incoming ticks vary with market activity you can see tick volumes by using iVolume() function.

https://www.mql5.com/en/docs/series/ivolume

Thanks for the quick response Marco. I do not see any variation at all. It just keeps on ticking every second. And it shows the updated values at the tick. I expected it to not tick constantly but to tick only when the chart graph makes a change. Do you think there is some paraeter that I should perhaps set to obtain this behaviour? A tick every second with or without a market move creates an unneccessary load of data to my application. More importantly, it does not update my interface within a second, so movements within a second is lost..
Marco vd Heijden
Moderator
12670
Marco vd Heijden  

There can be thousand of ticks a minute so its normal for it to tick fast.

If you need something slower you can use a timer.

William Roeder
20207
William Roeder  

There can be tens to thousands of ticks per minute, depends on the broker's filtering. The three broker's I used averaged 50, 150, and 300 ticks per minute consistently during the London/NY session.

There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific.) requires knowledge of when your broker stops and starts (not necessary the same as the market.)

If you want once a second or slower use the timer.

Samanmalee
33
Samanmalee  
William Roeder:

There can be tens to thousands of ticks per minute, depends on the broker's filtering. The three broker's I used averaged 50, 150, and 300 ticks per minute consistently during the London/NY session.

There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific.) requires knowledge of when your broker stops and starts (not necessary the same as the market.)

If you want once a second or slower use the timer.

Thanks William, and thanks Marco again,

I believe my question is not very clear. I certainly do not want to slow it down. I would like to receive all ticks as they receive. But what my test code shows is that its just a regular interval tick like a heartbeat, which triggers only every one second. I want it to trigger as and when market changes. Receiving tens or thousand ticks is not a problem. Receiving one only each second is the problem. Following is my code:

void OnTick()
  {
     Comment("Tick: "+Ask+", counter: "+counter++);
  }

counter is a variable defined. What I expected is to not see counter increases when there are no market movements. Today is Saturday, and I ran the EA, and the counter keeps on increasing every second. So definitely this does not reflect market movements. And Marco, no it doesn't tick fast. It just ticks once every second with or without any market event.


Thanks in advance for your support.

Marco vd Heijden
Moderator
12670
Marco vd Heijden  

Which instrument was that ?

Only Crypto's are active in weekends, a forex chart should not receive any ticks because markets are closed.

What code did you use to monitor it ?

Samanmalee
33
Samanmalee  
Marco vd Heijden:

Which instrument was that ?

Only Crypto's are active in weekends, a forex chart should not receive any ticks because markets are closed.

What code did you use to monitor it ?

Screenshot from Saturday.

I used a regular EA that I use for testing. Its saved as an MQ4 and compiled into an EX4.

And the chart is GBPUSD, H1. The code is exactly as I have mentioned above:

void OnTick()
  {
//  Alert("On Tick called");
Comment("Tick: "+Ask+", counter: "+counter++);
  }


This is exactly what I am saying. My OnTick() is called every second with or without any market events. Its not triggered by any market events. Its just a heartbeat every second.
lippmaje
1037
lippmaje  
Samanmalee:

This is exactly what I am saying. My OnTick() is called every second with or without any market events. Its not triggered by any market events. Its just a heartbeat every second.

Wow... this is the creepiest thing I've come across here so far. Maybe there's a timer in the EA that makes a call to OnTick.

Samanmalee
33
Samanmalee  
lippmaje:

Wow... this is the creepiest thing I've come across here so far. Maybe there's a timer in the EA that makes a call to OnTick.

There isn't. I do not call it. Thanks for all your input. Now I know this is an unusual behaviour. I will investigate further. I wanted to know from you all if this is normal or not. Im running on Mac OS on PlayOnMac. The broker is Oanda. If any of these will help you diagnose something.
lippmaje
1037
lippmaje  

A closed market means there's no ticks. Not one single tick. Maybe your broker sees this different but there's no point at all in doing this.

Check the specifications of the symbol, what are the session times for quoting and trading.

12
To add comments, please log in or register