How often is OnTimer function called?

Hi guys. I wanted to test the timer (OnTimer) and I did a very simple script.

int tempo;

int OnInit()
   Print("0: GetTickCount: " + GetTickCount() + " GetMicrosecondCount: " + GetMicrosecondCount());

void OnDeinit(const int reason)

void OnTimer()
   if(tempo == 1) Print("1: GetTickCount: " + GetTickCount() + " GetMicrosecondCount: " + GetMicrosecondCount());
   if(tempo == 10) Print("10: GetTickCount: " + GetTickCount() + " GetMicrosecondCount: " + GetMicrosecondCount());
   if(tempo == 100) Print("100: GetTickCount: " + GetTickCount() + " GetMicrosecondCount: " + GetMicrosecondCount());
   if(tempo == 1000) Print("1000: GetTickCount: " + GetTickCount() + " GetMicrosecondCount: " + GetMicrosecondCount())

But I get a strange result. As you can see from the MT4 log a lot more than 1, 10, 100 and 1000 ms have passed.

2019.04.11 22:37:15.819 TestTimer EURUSDq,H1: 1000: GetTickCount: 10043531 GetMicrosecondCount: 15614678
2019.04.11 22:37:01.757 TestTimer EURUSDq,H1: 100: GetTickCount: 10029468 GetMicrosecondCount: 1552525
2019.04.11 22:37:00.358 TestTimer EURUSDq,H1: 10: GetTickCount: 10028062 GetMicrosecondCount: 153794
2019.04.11 22:37:00.211 TestTimer EURUSDq,H1: 1: GetTickCount: 10027921 GetMicrosecondCount: 6875
2019.04.11 22:37:00.204 TestTimer EURUSDq,H1: initialized
2019.04.11 22:37:00.204 TestTimer EURUSDq,H1: 0: GetTickCount: 10027906 GetMicrosecondCount: 274
2019.04.11 22:37:00.191 Expert TestTimer EURUSDq,H1: loaded successfully
I have tried on 4 different versions of MT4 and I always get the same result.

Am I doing something wrong??

Thank for Help

Yes you are.

Why do you use 1 ?

I need to go fast to the market.

Furthermore, MT4 is not connected to any server. Receive prices from Fix Api trader (FixAPI Bridge) so I can’t use OnTick ()

The minimum interval of 1000 milliseconds is used in the strategy tester

In general, when the timer period is reduced, the testing time is increased, as the handler of timer events is called more often.

When working in real-time mode, timer events are generated no more than 1 time in 10-16 milliseconds due to hardware limitations.

OK thanks.

I don’t use strategy tester. As I wrote MT4 gets the prices from the fix bridge. However I have seen that the loops using an infinite loop are much faster (a few microseconds).

To lower the time I will use this technique. I know it is strongly discouraged but I need to go fast :slight_smile:

16 ms of delay between the orders sent from MT4 to the fix bridge are too many for me.

ps. I don’t need microseconds. I’m satisfied with 1ms :slight_smile:

The lowest i use is 250.

I do not think that you are going to succeed if you continue on this track.

You can also consider moving to MT5 as it is a lot faster and a lot closer to what i assume you want.

But when it comes to hardware limitations, there is very little you can do.

I did a couple of tests. With an infinite cycle and a sleep of 1 I can have a clock just over 1 ms.

But I agree with you. Overcoming the hardware limitations is really impossible.

I check if the FixApi trade bridge also works with MT5.

Thank you very much for your suggestion.