How to get EAs on Different Computers to Talk to Each Other

 

Hi All.  I'm trying to setup a backup redundancy for when my EA stops functioning on my PC.  I want to do this by having a second PC in a different location with an EA running and monitoring the primary EA in the first location.  The secondary EA will then kick-in when the primary EA stops transmitting a signal.  To do this I need the client terminals on both PCs to be able to transmit data between them so the EAs know which EA is in command and the current status of the trade strategy.  I have done some research and read through the forums but have not been able to find a solution to this.  Note, I have tried VPS solutions but also found these to be unreliable. Your help is much appreciated.

 
I would find a free REST api (like twitter or something) and then set a timer in the primary to POST the timestamp (heartbeat) every minute or so.  Then, on the backup EA I'd GET the most recent timestamp and if the delta is greater than the allowable downtime then it assume the primary role and send an email alerting you of the potential outage. 
 
nicholi shen:
I would find a free REST api (like twitter or something) and then set a timer in the primary to POST the timestamp (heartbeat) every minute or so.  Then, on the backup EA I'd GET the most recent timestamp and if the delta is greater than the allowable downtime then it assume the primary role and send an email alerting you of the potential outage. 

Nicholi, thanks for your response.  I taught myself MQL4 to develop the EA and run within the MT4 terminal but my coding knowledge outside of that is limited. I have been doing some reading but am still unclear on how it works.

1) Would you mind elaborating more on how to use a REST API with the MT4 terminal or send me a link to learn more about it. 

2) Do I need to use WebRequest() function? 

3) Is it also possible to send/receive information such as up to approx. 30 variables to enable the second EA to start from the same position as the first EA? 

4) Also, can the data transfer be achieved on every tick so the second EA starts with the most accurate data?

 
LifeHack:

1) Would you mind elaborating more on how to use a REST API with the MT4 terminal or send me a link to learn more about it. 

2) Do I need to use WebRequest() function? 

3) Is it also possible to send/receive information such as up to approx. 30 variables to enable the second EA to start from the same position as the first EA? 

Yes, you would need to serialize your message to JSON before posting/after getting over WebRequest. 

4) Also, can the data transfer be achieved on every tick so the second EA starts with the most accurate data? 

This is a tough one since almost all REST api have strict limits on number of calls for minute. You could create a simple micro-service (with python for example) and deploy it as an AWS lambda function and pair it with the aws api gateway. ...OR... you'd need to figure out how to directly connect the terminals via encrypted websockets ...OR... create a VPN between endpoints and use regular sockets. 

 
nicholi shen:

Yes, you would need to serialize your message to JSON before posting/after getting over WebRequest. 

This is a tough one since almost all REST api have strict limits on number of calls for minute. You could create a simple micro-service (with python for example) and deploy it as an AWS lambda function and pair it with the aws api gateway. ...OR... you'd need to figure out how to directly connect the terminals via encrypted websockets ...OR... create a VPN between endpoints and use regular sockets. 

I've been doing some reading and I may start learning GraphQL to be able to achieve the communication link through developer.github.com, do you think this is a good path to be on?
 
Totally inapplicable to your needs. Look at something like telegram. You just need an api to post/get the heartbeat. (timestamp)
 
If you only know mql4 language you can do it with csv files, if the ea stops, you place this information inside the csv file, and open this csv file on the other computer every second, and monitor it. If it's a local network you just need a program to send this csv file to the other computer every second, on windows you have dsyncronize, a great program, on linux you can use rsync with watch command line, for every second to transfer the folder
 

Yes so you can make a file and write the time to it, like every second or so called heartbeat.

Then you server this file over a small webserver for example HFS.

The receiving Terminal reads the file and compares the time.

When there is a problem with the Master transmitting Terminal the file with the time won't get updated.

This will be noticed by the receiver and you can set it to any time out length.

For example ten seconds, if the difference in receiver time and file time is larger then ten seconds, raise an alert or take over trading.

This mechanism is called watchdog timer.

 

If OP doesn't want to go the simple API route then I'd suggest instead of complicating matters with files and servers and fun networking hacks to simply use the platform itself as a watchdog timer. EA#1 sets/modifies a limit order with a unique magic id, at a designated interval, at minimum volume, and so far off market prices it will never get filled. EA#2 checks the order conditions against its set of rules. 

 

It's not complicated.

Drag & Drop

 
Marco vd Heijden:

It's not complicated.

Drag & Drop

Are you suggesting that OP should expose a port on his private network to run this unencrypted file-server? No offence, but it seems both complicated and wildly insecure, but what do I know...