Threepwood:
[EDIT] I was thinking about working at seconds instead of tick time using the TimeCurrent() function that's obviously accurate, the algorithm would be as follows:
if the "seconds" value of TimeCurrent() has changed, do my job related on the N seconds elapsed...What do you think of that? Do you think this is a good way to get a sufficient accuracy (1 second)?
Second question: how can I get the "seconds" part of TimeCurrent() ?
- Think again. If there is no tick, nothing has changed. What are you going to do now that you didn't do on the previous tick? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific).
-
If you insist, use the timer.
-
int seconds = TimeCurrent() % 60;
- Think again. If there is no tick, nothing has changed. What are you going to do now that you didn't do on the previous tick? There can be minutes between ticks during the Asian session, think M1 chart. Larger charts, think weekend, market holiday (country and broker specific).
-
If you insist, use the timer.
That makes perfectly sense, agree with that; I know exactly what to do now.
In the meantime I have based my strategy on TimeCurrent() function, checking whether more than 1 minute had elapsed since the last tick and in that case deduce the market were closed/the servers or internet connection were broken. I did not expect more than 1 minute between ticks in some cases as you mentioned, so I need to adjust (rewrite one part of) my code. Thanks a lot for this information.
Do you agree with the following condition: if more than 1h has elapsed since the previous tick => deduce the market was closed/other malfunction from servers or internet connection. I believe there's no way to have more than 1h?
Note: the timer function does not work in Test mode ;-)
void OnTick() { static datetime lasttime=0; datetime ticktime=TimeCurrent(); int seconds=(int)(ticktime-lasttime); lasttime=ticktime; if(seconds>=3600) { return; // market was closed, or first tick on startup } Print("seconds elapsed since last tick: ",seconds); }Note that in MT5 you can also get the milliseconds part of the tick time, see MqlTick and SymbolInfoTick().

- www.mql5.com
Note that in MT5 you can also get the milliseconds part of the tick time, see MqlTick and SymbolInfoTick().
This is the kind of code I have implemented (actually yours does not work, and do not see how it could, but I get the big picture, which was the same as mine).
I understand you validate the fact that "if elpasted time > 1h: deduce the market was closed" :-)
Thanks a lot for your help!
This is the best you can get at with MT4 if you want 100% reproducible test conditions. If you want something that "works", in your terms, then move on to MT5. The "big" picture is that your strategy is not testable in MT4 if you need sub-second resolutions. Hope that's clear now.
This is perfectly clear, and it has already been clear from the beginning, I have never said the opposite.
(int) TimeCurrent()is brillant :-) It will help me a lot. Thanks!

- www.mql5.com

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hi everyone,
I had a MQL4 strategy based on the ticks but unfortunately I needed the duration between two ticks.
I thought that GetTickCount() did the job, but I have just understood the GetTickCount relies on the computer time, so at each run of the same test in the same interval of course I don't get the same times...
So all my strategy is to throw away...
Would you see or indicate to me a trick to get the time between two ticks in Test mode ?
Thanks a lot in advance !!!!
[EDIT] I was thinking about working at seconds instead of tick time using the TimeCurrent() function that's obviously accurate, the algorithm would be as follows:
at OnTick() event:
wait until a TimeCurrent() second changes as a start,
if the "seconds" value of TimeCurrent() has changed, do my job related on the N seconds elapsed...
What do you think of that? Do you think this is a good way to get a sufficient accuracy (1 second)?
Second question: how can I get the "seconds" part of TimeCurrent() ?
Thanks !