How to get 2 EAs to 'talk' to each other on separate MT4 instances

 

Hi,

I am new to MetaTrader and MQ4, so please excuse any obvious questions. However, I have failed to find the answer online. Here is my question:

I wish to develop my own 'EA' running on 2 different MT4 instances connected to 2 different brokers. Under certain circumstances, I would like one EA (running on one MT4 instance) to send a 'close' signal to the other EA (running on the other MT4 instance). Is this possible?

One suggestion is to write a DLL. The first EA would call the DLL to force it to write something to a file which the second 'EA' would read and interpret this as a sell signal. Would this work?

Is there any better way to do it?


Thanks,

Bernard

 

I dont know if you can point MT4 to the same directory in order to access the file. Also, if you could would there be read/write issues on a file opened by another program, and perhaps still open ? no idea, but I will be interested in the answer.

 
MickGlancy:

I dont know if you can point MT4 to the same directory in order to access the file. Also, if you could would there be read/write issues on a file opened by another program, and perhaps still open ? no idea, but I will be interested in the answer.


Hi Mick.

I will keep you posted. I was thinking the DLL would simply create a file in the 'tmp' directory. The 2nd EA would read it. I dont think this would cause a problem because the 2nd EA would not be writing to the same file.

Anyway, do you know of a better way/approach? My suggestion appears/feels quite primitive.

 
 
The other question I forgot to ask was....is there any known issues/problems running multiple MT4 instances on the same Windows machine?
 
bgaughran:
The other question I forgot to ask was....is there any known issues/problems running multiple MT4 instances on the same Windows machine?


also easy to use : windows registry

one EA write there, other read and delete/archive

 
zzuegg:
use named pipes. https://www.mql5.com/en/forum/127032

Hi zzuegg,

I very much appreciate the reply. I will test the code in the link you sent. It appears (on paper) it will solve my problem.

Do you know if you can run a server AND a client with each EA? Market movements will decide which EA is the client and which is the server.

Are there any restrictions using named pipes on XP/Windows 7/etc?

 
EADeveloper:


also easy to use : windows registry

one EA write there, other read and delete/archive


Thanks EADeveloper,

how would an EA write to the 'windows registry'? And why is the registry better to use than the file system?

 
bgaughran:


Thanks EADeveloper,

how would an EA write to the 'windows registry'? And why is the registry better to use than the file system?


>>One suggestion is to write a DLL

Most of the languages you use for write the dll can easy access the registry.

Better then filesystem is in my opinion because in the registry you can read/write within a structured key. Filesystem is more complicated if you use more parameters/charts/EA's.

Delphi Example for read integer from registry:

function GetRegistryInteger(MID,KeyName: PChar): integer;    StdCall;
var Regi: TRegistry;
begin
  Regi := TRegistry.Create;
  try
    Regi.RootKey := HKEY_LOCAL_MACHINE;
    Regi.OpenKey('Software\EaRegistry\'+MID, False);
    Result := Regi.ReadInteger(KeyName);
  finally
    Regi.Free;
  end;
end;
 
EADeveloper:


>>One suggestion is to write a DLL

Most of the languages you use for write the dll can easy access the registry.

Better then filesystem is in my opinion because in the registry you can read/write within a structured key. Filesystem is more complicated if you use more parameters/charts/EA's.

Delphi Example for read integer from registry:


EADeveloper,

would you see this a better solution over 'named pipes'?

 
bgaughran:


EADeveloper,

would you see this a better solution over 'named pipes'?


better i dont know, this depends also on the developer i guess, in my opinion more easy, but i am use do develop in delphi also :-)

But this from the pipes:

if (SendPipeMessage(ServerName, Message, RetryForSeconds)) {
Print("Message succeeded (but may not have been processed by the server yet)");
} else {
Print("Message failed!");
}

normaly with the registry can not happen, because when client B is not availibel for the moment he can read later the value from registry and decide to use or not (i use for example in the registry a timestamp when i was writen, the pair, the timeframe and the command) so if the timestamp is to old, i delete the entry from the registry and do not fullfil the command.