
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
True. Thanks. I didn't remember that. Actually it doesn't solve the problem completely since I need orders to be executed almost immediately (and I think with this method I can only check it every second, but at least not every tick), but indeed I can easily build a temporary solution using it.
Though the OnTimer has the fastest rate aligned with the system clock, i.e. every 15 ms, I would prefer looping in 1ms intervals (using the Sleep(1) in the loop).
Though the OnTimer has the fastest rate aligned with the system clock, i.e. every 15 ms, I would prefer looping in 1ms intervals (using the Sleep(1) in the loop).
Wouldn't that be a problem? I mean, there are not internal processes in MT4 that may need OnTick() to be executed to avoid some kind of internal buffers to end up overflowed or oversized after weeks of being running (the EA) without stopping and just looping?
I'm asking it from the ignorance, I have no idea whether it could be a problem, just assuming MT4 was not devised to do it.
So you think(/have tried) it will not be a problem? (If so, those are great news).
BTW: How do you get OnTimer() to be executed below 1 sec interval? :?
I used to run EAs in a loop started in init() some years ago, for similar reason - reading external data with minimum delay. It used to run weeks without any side effect. The Sleep(1) is satisfactory to make the computing power impact very light.
The timer settings accepts millis.
I used to run EAs in a loop started in init() some years ago, for similar reason - reading external data with minimum delay. It used to run weeks without any side effect. The Sleep(1) is satisfactory to make the computing power impact very light.
The timer settings accepts millis.
BTW: How do you get OnTimer() to be executed below 1 sec interval? :?
EventSetMillisecondTimer
The function indicates to the client terminal that timer events should be generated at intervals less than one second for this Expert Advisor or indicator.
bool EventSetMillisecondTimer(
int milliseconds // number of milliseconds
);
Parameters
milliseconds
[in] Number of milliseconds defining the frequency of timer events.
Returned value
In case of successful execution, returns true, otherwise - false. To receive an error code, GetLastError() function should be called.
Note
This feature is designed for the cases when high-resolution timer is required. In other words, timer events should be received more frequently than once per second. If a conventional timer with the period of several seconds is enough for you, use EventSetTimer().
Usually, this function should be called from OnInit() function or in class constructor. To handle events coming from the timer, an Expert Advisor or an indicator should have OnTimer() function.
Each Expert Advisor and each indicator work with its own timer receiving events solely from this timer. During mql4 application shutdown, the timer is forcibly destroyed in case it has been created but has not been disabled by EventKillTimer() function.
Only one timer can be launched for each program. Each mql4 application and chart have their own queue of events where all newly arrived events are placed. If the queue already contains Timer event or this event is in the processing stage, then the new Timer event is not added to mql4 application queue.
EventSetMillisecondTimer
The function indicates to the clientterminal that timer eventsshould be generated at intervals less than one second for this Expert Advisor orindicator.
bool EventSetMillisecondTimer(
int milliseconds // number of milliseconds
);
Parameters
milliseconds
[in] Numberof milliseconds defining the frequency of timer events.
Returned value
In case of successfulexecution, returns true, otherwise - false. To receive an error code, GetLastError() function should be called.
Note
This feature is designedfor the cases when high-resolution timer isrequired. In other words, timer eventsshould be received more frequently than once per second. If a conventional timerwith the period of several seconds is enough for you, use EventSetTimer().
Usually, this functionshould be called from OnInit()function or in class constructor. To handle events coming from thetimer, an Expert Advisor or an indicator should have OnTimer() function.
Each Expert Advisor andeach indicator work with its own timer receiving events solely from this timer.During mql4 application shutdown, the timer is forcibly destroyed in case it hasbeen created but has not been disabled by EventKillTimer() function.
Only one timer can belaunched for each program. Each mql4 application and chart have their own queueof events where all newly arrived events are placed. If the queue alreadycontains Timer event or thisevent is in the processing stage, then the new Timer event is not added to mql4application queue.
Thanks for the detailed explanation; my fault; I read it too quickly online. (Links have interchanged docs.mql4.com domain with forum.mql4.com. Just in case anyone else check this thread...)
EDIT: I'm going to take advantage of a moderator being around: Do you know whether it exists any difference between executing OnTimer() every N millisecs and doing the same looping every N millisec as described on previous posts?
I don't see why all the fuss with "ms" timing. Unless this is some sort of "High Frequency News Scalper" on a very low latency broker connection, one second intervals on OnTimer() should be more than enough as a response time.
If you add all the delays and latency of the JAVA app execution, IPC (LAN & WAN) communication, Order management execution and Broker server latency, there is no real advantage in using "ms" timing for normal strategies.
If however, it is some sort of "High Frequency News Scalper", to be used on a VPS with a low latency connection to the broker, then you should NOT be messing about with JAVA and IPC at all, and should be coding the strategy directly in very compact MQL to get the lowest latency possible.
EDIT:
EDIT: I'm going to take advantage of a moderator being around: Do you know whether it exists any difference between executing OnTimer() every N millisecs and doing the same looping every N millisec as described on previous posts?
Just because I am a moderator, it doesn't mean that I am more knowledgable than others. In fact, the other posters in this thread obviously have more knowledge than I on the subject matter. I know nothing about Java.
I don't understand the point of using Sleep() in a timer event as it puts the EA on hold and this could mean missing a lot of OnTick() events. Of course, depending on the EA, OnTick events may be unimportant.
I used to run EAs in a loop started in init() some years ago, for similar reason - reading external data with minimum delay. It used to run weeks without any side effect. The Sleep(1) is satisfactory to make the computing power impact very light.
For a bit of fun... the following script accepts multiple concurrent TCP/IP connections, and writes incoming CR-delimited messages to the Experts log. For example, once the script is running you can connect via Telnet (to port 51234 by default), and each line of text which you type in will be printed.
For a bit of fun... the following script accepts multiple concurrent TCP/IP connections, and writes incoming CR-delimited messages to the Experts log.
... stating the obvious, if you wanted to do the above in an EA rather than a script, then you'd simply change it as follows: