Send info to another EA

 
Hi, I want to use information from one EA with another. One is processing information and want to get a signal or var from the processing eA to the execution EA.

Can I create a class which i can import or how to go about ?
 

On MetaTrader, there is no built-in interprocess communication mechanism that can be used between processes such as two EAs.

You have to use indirect methods to achieve that. Here are some example suggestions:

  • Graphical objects on charts
  • Global Terminal Variables
  • Files
  • SQLite database
There are probably other methods that can be used, but they don't come to mind at the moment.
 
The practical ways I used myself are Text File, Global Variable and Database.
 
A million ways. 
Depending on how tight the traffic is and if u need response or not. 

1. For status-data u use a file. Use Global vars to count the number of changes and check that in the timer in your client. Whenever serving EA changed sth, the numer increased and u know you have to read again.

2. For string messages one way use the WindowText of the chart. Its invisible, since its a child of the actual window with its border. Use functions from Winuser.dll, actually easy and also thread-safe. Here as well use a counter in the beginning of the windowtext, so the client knows when a new message is there (OnTimer). Windowtext can be up to 2048 bytes. 

3. String messages one way but sync - same as 2, but let the client reset the window-text so the server knows it was read. 

4. Two way, full duplex asynchronous, same as 2 and 3 but on both charts. 

5. Professional way: Use MMF and Mutex and create a IPC server/client/peer. Do not use Windows namedpipes. They will also work somehow, also with a server in MQL (which is officially not possible - well it is!), but you wont be able to keep them stable. MMF with a mutex is rocksteady and faster than namedpipes. 1000 sync messages need less that 10ms. We do it that way. 

Depending on your skills, you will be able to find an appropriate solution. WindowText might be „dirty“, but easy and really steady. Maybe best way to do it as least safe and slim with just few lines of code. Worth it. 

How to find eachother? Use ChartFirst/ChartNext, get the handle, read the windowtext. Put/keep sth to identify as client/server in the windowtext. Voila. 

PS: Under no circumstances use EventchartCustom with strings. Super unreliable and crashy. 
 
Gerhard Lombard:
Hi, I want to use information from one EA with another. One is processing information and want to get a signal or var from the processing eA to the execution EA.

Can I create a class which i can import or how to go about ?

Hello, 👋

I also use File Communication, and it works great especially when dealing with multiple variables or structured data.

However, for lighter use cases (like a simple buy/sell flag or a single signal value), the Global Variables of the Terminal option is definitely a very good choice.

👉 File Communication is perfect when you need to store more data or keep logs.
👉 Global Variables are perfect when you just need to share a simple value between two EAs quickly.

Best regards, 🌹
Hamid Marwi

 
Hamid Marwi #:

Hello, 👋

I also use File Communication, and it works great especially when dealing with multiple variables or structured data.

However, for lighter use cases (like a simple buy/sell flag or a single signal value), the Global Variables of the Terminal option is definitely a very good choice.

👉 File Communication is perfect when you need to store more data or keep logs.
👉 Global Variables are perfect when you just need to share a simple value between two EAs quickly.

Best regards, 🌹
Hamid Marwi

Like everything in MQL which happens in different threads, global vars need to be handled with care. You may see unexpected delays, same like with ChartGetInteger etc. 

Sonetimes „quick“, sonetimes lame, and when accessed too frequent: Freeze. For a little traffic here and there its ok, but I gave up on it long time ago. 

If u want, make a benchmark and track the time. Id be curious about the results. But when I see, that getting 10 values via ChartGetInteger etc that takes 20-30ms, Im speechless. I mention it cuz the principle is the same: Different thread and asynchronous. Last … for whatever unreasonable reason. 

I think that some of the code in MT is very old and noone dares to touch it.