Interprocess Communications

 

I am trying to build an IPC through named pipes between another application with a RT data feed and MT4. I have considered using reading/writing files on the disk but would like to achieve the memory option if I can. I am using various combinations of C/C++ dlls and importing the kernel32.dll library to try to get this to work.

If MT4 is the server and creates the named pipe, it has to wait until the client connects and sends its data. During this time, MT4 is unusable for the trader; any mouse click or attempt to interact with MT4 results in it crashing or indefinitely hanging. If the other application is the server and creates the named pipe, like when MT4 is the pipe server, it hangs whilst waiting for the client to connect making unavailable for the user to continue to use normally. I am going to guess the same delays/waiting will happen if I use windows sockets, so it is not a viable alternate solution? Can I spawn a new thread for the IPC and have it exchange information with the parent process in MT4?

There needs to be some modicum of synchronisation to ensure the signals received in MT4 are timely (I am currently using a timestamp on the data to achieve this, with MT4 rejecting anything older than x-seconds)

Can anyone suggest a method to pipe data from another application to MT4 that will allow both applications to continue working whilst the IPC is happening? (BTW: the information flow is one-way, to MT4). Samples are always helpful.

TIA

 
wabbit:

If MT4 is the server and creates the named pipe, it has to wait until the client connects and sends its data. During this time, MT4 is unusable for the trader; any mouse click or attempt to interact with MT4 results in it crashing or indefinitely hanging. If the other application is the server and creates the named pipe, like when MT4 is the pipe server, it hangs whilst waiting for the client to connect making unavailable for the user to continue to use normally. I am going to guess the same delays/waiting will happen if I use windows sockets, so it is not a viable alternate solution? Can I spawn a new thread for the IPC and have it exchange information with the parent process in MT4?

I would definitely go down the route of spawning a new thread. Basically, I'd use a DLL at the client (MT4) end, and have the DLL monitoring the message feed in a separate thread and putting incoming messages into a queue. On each tick - i.e. each call to start() - the EA would then ask the DLL for all messages currently in the queue.


Two further things about this. Firstly, you can run into terrible trouble with MT4 calling FreeLibrary() on a DLL which contains the thread proc for a thread which is still running. You can theoretically get round this if you are very careful about terminating the worker thread before your EA is unloaded, but it's safer in practice simply to increase the DLL's refcount - i.e. by doing an extra LoadLibrary() call on it - so that it remains in memory until the whole MT4 application closes.


Secondly, when an incoming message is received by the DLL, it can simulate a market tick and force the EA to call it even if no real market tick has been received. In other words, you can force the EA to act on incoming messages even if there are no market ticks and it would normally be hibernating between calls to start(). The DLL needs to be given the chart's window handle, and can then simulate a tick using the following: PostMessage(hwnd, RegisterWindowMessageA("MetaTrader4_Internal_Message"), 2, 0);

 

I have a central server running MT4 that generates signals that I want to send out to various MT4 running in other PCs across a network, can anyone help?