Data exchange using DLLs vs. DLL-free solutions vs. Memory-mapped files vs. Named pipes vs. Socket communication
Hey,
I did lots of benchmarks with most of the types for data exchange that you mentioned. But its not only about about performance, safety is also very important, because you have to make sure, that there are not two or more processes which try to access and write a file at the same time. This is what you should definetly have in mind.
Let me give you some hints.
* MQL file access is not working with shared files, the functions are buggy, don´t use that at all (there is sample code in this forum which I created months ago to demonstrate that)
* Memory mapped files are cool and quick so far, but you have to handle the locking by yourself entirely
* DDE ... no experience in combination with MQL
* Named pipes ... you need a host to setup on, for your purpose probably a little too much overhead
What you didn´t mention was plain memory blocks, which could be the best for your purpose, cause locking/unlocking is also implemented by Windows and it´s 3-4 times faster than memory mapped files. To deal with such buffers, take a look at the manuals of Microsoft. https://docs.microsoft.com/en-us/windows/win32/api/winbase/nf-winbase-globalalloc. You can deal with this functions without the need of any additional DLLs, it can be done entirely in MQL. I use this too in such special environments and its just simple and faster than anything else.
- 2018.12.05
- lastnameholiu
- docs.microsoft.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 all,
I'm trying to get my EAs to talk to each other, as simple as it gets, and I would appreciate some help.
Since the majority of brokers in my country offer only netting accounts, I'm currently trading with 5 different brokers. For each of them I use an EA, which runs the same script, but using slightly different input parameters in order to trade the same symbol. Thus these 5 EAs complement each other, because when one of them has a big drawndown, the others compensate for the loss.
Currently I'm using 5 different MetaQuotes VPS, but I'm planning to move them to the same VM, probably hosted on Amazon (AWS). In this new VM I want to install 5 different instances of MT5, one for each broker, and each of them trading with its own EA.
Each EA has a function that defines its current status, and stores this information on an int variable that varies from 1 to 5. When the EA is initialized and starts trading, its status is "1". If during a trade its profit gets negative and increases, the status goes to "2", then to "3" and so on until it's "5". It works just like the DEFCON scale: the bigger the number, the worse the situation is.
I need the 5 EAs to talk to each other so they can share this information about their current statuses. I thought of a very simple file, containing an integer with 5 digits, something like "00000", or an array. Each EA would have a fixed position on this file, and it would update its respective digit as soon as its status changes.
The main objective of this script is to create a security trigger: whenever one EA reaches level "3", it automatically puts on hold the next 2 EAs with the major levels. If the EA reaches status "4", then the remaining 2 EAs will also pause and wait for a sign so they can resume trading.
It would work like this: let's say that the 5 EAs, named A, B, C, D and E, are inicialized, so their statuses would be "11111". At some point during the day they are trading normally, with this statuses: "12112". Then suddenly EA "A" (first one on the list) has a big drowndown and goes to level 3: "32112". Whenever this happens, EA "A" will also change the statuses of the other EAs with major levels using a different number, let's say "9", so they could know that they should stop trading immediately: "39119". Right after this EAs "B" and "E" will read this update and then cancel all pending orders, close all open positions and then enter stand by mode. If the drawndown gets bigger and EA "A" goes to level "4", the remainig 2 EAs should also be paused: "49999". On the other hand, if the trade reverses and the profit gets positive, EA "A" goes back to level "1" and put the other EAs on reset mode so they could restart: "10000".
Maybe the tricky part is that all 5 EAs should be able to read and write this data on the same spot, at the same time. I've read articles, codes and posts in this forum searching for a script like this, but unfortunately the similar ones often suggest a very complex solution to setup this communication. I think that my case is simpler because all I need is to share a 5 digits number, just 1 byte of information.
Among the solutions that I have found, there is the usage of a single data file stored in the Common Folder, using DLL files for data exchange, DLL-free solutions for data exchange, file-mapping and memory-mapped files, named pipes, socket communication, trade copier, client-server solutions with VB, Python, C and so on. I'm pretty sure all of them are great, but I'm just looking for a straightfoward one.
I would really appreciate if you could share your thoughts about this topic and indicate the best solution in this cenario.