Multi-EA Orchestration - How to do it?

 

Boys...this is a big one !


suppose i have multiple EAs running on separate charts and currency pairs (for e.g EA1 : USDJPY, EA2: EURUSD, EA3: AUDCAD) ..... in the event that two (or more) EAs want to open a new position, only one EA should be allowed to open a position based on a pre-defined "priority list".

for e.g : say EA1 and EA3 signal readiness to open a trade at the same instant.....my "priority list" says that USDJPY is higher priority than AUDCAD....so the USDJPY trade is allowed to execute ...while the AUDCAD is denied !

I thought about using a "central" controller EA that would get all trading requests from the trading EAs, prioritizes them and sends " approve/deny" responses back to the EAs....but i am not sure how to implement this or whether it would work in real time (runtime collisions/synchronization issues).

this "architecure" is one possible solution to this multi-EA orchestration problem...I would appreciate clear on whether this is the best way to do it and how to actually implement this in mql5


note: in case anyone's wondering " why multi EAs instead of a single multi-symbol EA? " ...well....each EA runs on a dedicated thread that is barely enough to handle the load of a single EA+indicators. ...heavy proccessing being performed by each EA.


thanks

chuck

 
chuckdavis: Boys...this is a big one !

😅Don't discriminate! There are "girls" here too, some of which are very knowledgeable and more competent than the "boys".

 
chuckdavis: note: in case anyone's wondering " why multi EAs instead of a single multi-symbol EA? " ...well....each EA runs on a dedicated thread that is barely enough to handle the load of a single EA+indicators. ...heavy proccessing being performed by each EA.

Somehow, I think that you are presenting us with a X/Y problem, where you want a solution for "X", when the real issue is "Y".

Whatever the case, if you really want a solution for "X", why don't you first start by listing out all the possible ways for which the independent EAs can coordinate with each other. Then you can think of the pros and cons of each.

Here are a few that come to mind ...

  • Global Terminal Variables
  • Hidden graphical objects on the charts
  • Files
  • RAM-only SQLite database
  • Windows API DLL calls
There are probably others of which did not come to mind.
 
chuckdavis: barely enough to handle the load of a single EA+indicators. ...heavy proccessing being performed by each EA.

You should also consider streamlining that. If it has so much processing, then maybe you should rethink its design.

 

thanks 

i thought about most of the above . global terminal vars, writing to files, custom events...etc ...will definitely come in handy in the implementation . but they don't address the main archtecture issue:

suppose multiple trading EAs request "permission" from the "controller EA to open a trade at the same time .... how will MT5 deal with several calls to the same event handler (in the controller EA) happening at the same time ?


if the processing ends up being sequential ...then the controller EA won't work as intended.


girls....by all means...please pitch in and educate us !

 
chuckdavis #: suppose multiple trading EAs request "permission" from the "controller EA to open a trade at the same time .... how will MT5 deal with several calls to the same event handler (in the controller EA) happening at the same time ?
It is not MT5 that has to deal with that. There is no inherent IPC method built into MetaTrader. It is your own code logic that needs to deal with that.
 
One thing I can suggest is to [try to] use fxsaber's Virtual library in all separate EA's, then just implement a way to transfer/scan/report periodically these virtual environments into the single master EA, which will decide which parts of the virtual trades to copy into the real world.
 
Fernando Carreiro #:
It is not MT5 that has to deal with that. There is no inherent IPC method built into MetaTrader. It is your own code logic that needs to deal with that.

ok.

but perhaps there is an accepted or published method/recommendation how to handle this in the code logic? surely MT5 devs must have seen this one coming !

 
chuckdavis #: ok. but perhaps there is an accepted or published method/recommendation how to handle this in the code logic? surely MT5 devs must have seen this one coming !

There are none by MetaQuotes (with a caveat, see below). MetaTrader has never had a proper IPC and I doubt there will be any in the foreseeable future. It is simply not part of the platform's architecture.

The only method (the caveat) that comes close to a type of IPC implementation described by MetaQuotes is the Custom Chart Events but it's limited, rudimentary and suffers from all the same issues that chart events suffer from, and only Indicators and EAs can process the events. Scripts and Services cannot.

There have been a few articles by normal users, describing their own personal solutions for IPC, but there is no consensus among them.

Documentation on MQL5: Working with Events / EventChartCustom
Documentation on MQL5: Working with Events / EventChartCustom
  • www.mql5.com
The function generates a custom event for the specified chart. Parameters chart_id [in] Chart identifier. 0 means the current chart...
 
chuckdavis:

Boys...this is a big one !


suppose i have multiple EAs running on separate charts and currency pairs (for e.g EA1 : USDJPY, EA2: EURUSD, EA3: AUDCAD) ..... in the event that two (or more) EAs want to open a new position, only one EA should be allowed to open a position based on a pre-defined "priority list".

for e.g : say EA1 and EA3 signal readiness to open a trade at the same instant.....my "priority list" says that USDJPY is higher priority than AUDCAD....so the USDJPY trade is allowed to execute ...while the AUDCAD is denied !

I thought about using a "central" controller EA that would get all trading requests from the trading EAs, prioritizes them and sends " approve/deny" responses back to the EAs....but i am not sure how to implement this or whether it would work in real time (runtime collisions/synchronization issues).

this "architecure" is one possible solution to this multi-EA orchestration problem...I would appreciate clear on whether this is the best way to do it and how to actually implement this in mql5


note: in case anyone's wondering " why multi EAs instead of a single multi-symbol EA? " ...well....each EA runs on a dedicated thread that is barely enough to handle the load of a single EA+indicators. ...heavy proccessing being performed by each EA.


thanks

chuck

What is an "heavy processing" for you ? Did you decide it's heavy subjectively or do you come to this conclusion in practice ?

The best approach remains one multi-symbols EA. And they, if needed (but I am curious to "see" if it is really) you can delegate subtask/processing using indicators, EAs or even services.

 
chuckdavis:
I would appreciate clear on whether this is the best way to do it and how to actually implement this in mql5

I would go with Fernando's first listed idea in his Post #2... GV's (terminal-wide) GlobalVariable's. They're basically double type variables with custom string type names. I would encapsulate each EA's trade entry conditions within a parent condition that detects via GV whether a preempting (prioritized) EA is already in a trade. The master EA would update its master GV following its entry and exit of a trade. EA2 would check the master GV value in a condition that encapsulates EA2's trade entry logic (and update EA2's own GV value following order execution), and EA3 would check both the master GV and EA1's GV values (and update).

If you choose to go this route and you haven't worked with GV's before, they are rather unique. They stay in MT5's memory until you manually or programmatically delete them, even after you shutdown MT5. You can inspect and alter them in the Tools ==> Global Variables window.