
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
... stating the obvious, if you wanted to do the above in an EA rather than a script [...]
Revised version which can be used to create an EA rather than a script simply by un-commenting the #define COMPILE_AS_EA. The code then has OnTimer (and OnTick) instead of OnStart.
The only other change is that the code now puts the sockets into non-blocking mode. It still polls for the availability of new socket events using select(), but it now avoids the danger of entering into a blocking state if select() is somehow erroneous.
Revised version which [...]
I'm sure everyone's eager for an update on this...
In the context of an EA - which is now the default in the code - it turns out to be possible to use WSAAsyncSelect() to do event-driven handling of the socket activity. This can often push latency between message-send and message-receipt below the millisecond level. The exact speed varies depending on what else MT4 is doing, but it's on average a lot faster, and never worse, than just using the timer.
It's not possible to get WSAAsyncSelect() to trigger OnTimer() or OnTick() in the EA. For example, WSAAsyncSelect() can be told to fire WM_TIMER messages, but MT4 ignores these because the wparam timer ID from WSAAsyncSelect() doesn't match the timer ID which it is expecting from EventSetMillisecondTimer().
However, telling WSAAsyncSelect() to send WM_KEYDOWN does successfully fire OnChartEvent() in the EA. See the comments in the code for full details of how this addition works.
For a bit of fun...
Lol. Amazing. Congrats. I didn't though it could be possible to code these functionalities on MQL.
Lol. Amazing. Congrats. I didn't though it could be possible to code these functionalities on MQL.
My instinct is always to do server sockets using multi-threading, but I can't actually think of a reason why this code wouldn't be viable and safe for real-life usage.
There's one thing in the most recent version, above, which isn't ideal. Rather than posting yet another large block of code, I'll describe it instead:
It's a small change to the code, but I don't want to post yet another big block into this forum when only you are interested.
Rather than posting yet another large block of code [...]
On second thoughts...
Yet another version, with the following changes:
Instead of posting such long SRC contributions, consider just attaching the file itself instead. I would suggest you EDIT your longer posts, deleting the SRC sections and just attaching the source file.
Instead of posting such long SRC contributions, consider just attaching the file itself instead. I would suggest you EDIT your longer posts, deleting the SRC sections and just attaching the source file instead.
Thank you very much for your contribution.
But, among the many reasons why I'm not going to do this is the fact that the code above works on both MT4 and MT5. If I uploaded it as an attachment, it would misleadingly have to be flagged as either .mq4 or .mq5 whereas in fact it works as both.
But, among the many reasons [...]
Another of the key reasons is the following scenario, which could have applied to the OP:
As far as I am aware, neither search engines nor the search on this site can look inside attachments. So, posting the code as an attachment would make it invisible to a search such as "mql4 bind listen htons".
You regularly tell people that they should have done a search or consulted the documentation; I am trying to help with exactly that.
(As it happens, "mql4 bind listen htons" doesn't find this topic because Google hasn't crawled the page since September 14th. But it should start appearing on Google soon.)
Thank you very much for your contribution.
But, among the many reasons why I'm not going to do this is the fact that the code above works on both MT4 and MT5. If I uploaded it as an attachment, it would misleadingly have to be flagged as either .mq4 or .mq5 whereas in fact it works as both.
On second thoughts...
Yet another version, with the following changes:
THANKS again jjc,
Right now I'm in a hurry and don't have time to test it, but I'll do it next week and tell you about. I think I won't have any problem running it, but maybe I'll ask you some doubts. BTW: Please don't edit any post; they all are perfect as they are (I feel like in StackOverflow =)).