Multi-EA Orchestration - How to do it? - page 2

 

thanks all for your input.


Alain Verleyen #:

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.

kinda new to MT5/mql5 ....so you're saying the multi-sym EA can call other EAs/indicators to offload the main thread and those "helper" EAs/indicators would get assigned their own threads/cores ? how to do this? spill dem beans !


Stanislav Korotky #:
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.

seems rather complicated.


Fernando Carreiro #:

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.

yup...custom events was one of the early ideas ...though i am not sure how it will help to have multiple EAs calling the same event handler simultanously ....which is the main the issue.


Ryan L Johnson #:

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.

yup..read up on them...they're neat for sure ....and will come in handy ....but again...they don't address the fundamental challenge: if two or more EAs want to open a trade at once ...even a global terminal var locking mechanism won't help and might actually run into race conditions due to processing synchronicity

 
chuckdavis #: ...though i am not sure how it will help to have multiple EAs calling the same event handler simultanously ....which is the main the issue.

No, it is not the same event handler. Each program (EA or Indicator) has their own independent event handler.

 
chuckdavis #: ...they don't address the fundamental challenge: if two or more EAs want to open a trade at once ...even a global terminal var locking mechanism won't help and might actually run into race conditions due to processing synchronicity

You are using "jargon", but not really understanding the concepts. If it is using a locking mechanism, like a mutex for exemple, how can there be a race condition?

The whole point of using a locking mechanism is to prevent the race condition in the first place.

 
Fernando Carreiro #:

You are using "jargon", but not really understanding the concepts. If it is using a locking mechanism, like a mutex for exemple, how can there be a race condition?

The whole point of using a locking mechanism is to prevent the race condition in the first place.

yeah..well ...i don't do coding for a living so there is that.

in your previous post you mentioned that the EAs should access unique event handlers ....but how do you establish a "central controller" mechanism using a priority list by handling the EAs requests through independent/unique event handlers ?

don't you need ALL requests to go to the SAME event handler....the event handler would then refer to the priority list and issue trade authorization to the highest priority EA.


how can we do this using multiple event handlers....not sure how that would work ? how to implement this ?

 

You are overthinking, overcomplicating and mainly prematurely thinking about optimization.

Code your multi-symbols EA, calling your indicators, and you could be really surprised how fast is MQL5 (if well coded).

 
chuckdavis #:

yeah..well ...i don't do coding for a living so there is that.

in your previous post you mentioned that the EAs should access unique event handlers ....but how do you establish a "central controller" mechanism using a priority list by handling the EAs requests through independent/unique event handlers ?

don't you need ALL requests to go to the SAME event handler....the event handler would then refer to the priority list and issue trade authorization to the highest priority EA.

how can we do this using multiple event handlers....not sure how that would work ? how to implement this ?


Your questions give an ambiguous impression of your knowledge. On one hand you use the words/jargon as if you understand the concepts, but at the same time it also seems you don't understand them.

So without a common understanding of the words/jargon, how are we going to communicate and give you the correct advice?

I personally am of the opinion that you need to streamline your code, and make it efficient enough to have only a single EA to do everything. Strategies that are too complex and require too much processing are usually a sign of a losing strategy. Refining it will help reduce the points of possible failure in the strategy rules.

Regarding the use of Global Terminal Variables, @William Roeder has in the past shared his Mutex implementation. This is one way to synchronise the exchange of data between different programs.

Forum on trading, automated trading systems and testing trading strategies

MUTEX in MQL5. Is it possible?

William Roeder, 2018.04.30 15:45

  1. By definition system calls not not part of MQL5.
  2. Metaquotes gave you the necessary call.
Files:
mutex.mqh  4 kb
 
assuming all EAs are in the same MT5 terminal, utilizing Global Variabbles would be the simplest method.
You could "misuse" variable name as "message" as long as you follow the variable name constraint.
A timestamp / tickcounter as global variable content could help to synchronize.

Good luck
 
Fernando Carreiro #:


Your questions give an ambiguous impression of your knowledge. On one hand you use the words/jargon as if you understand the concepts, but at the same time it also seems you don't understand them.

So without a common understanding of the words/jargon, how are we going to communicate and give you the correct advice?

I personally am of the opinion that you need to streamline your code, and make it efficient enough to have only a single EA to do everything. Strategies that are too complex and require too much processing are usually a sign of a losing strategy. Refining it will help reduce the points of possible failure in the strategy rules.

Regarding the use of Global Terminal Variables, @William Roeder has in the past shared his Mutex implementation. This is one way to synchronise the exchange of data between different programs.

is this supposed to compile in mt5 without the basic_types.mqh include file? where to get that? 

 
chuckdavis #:is this supposed to compile in mt5 without the basic_types.mqh include file? where to get that? 

It is supposed to serve as an example for you to study and develop your own version, not to be used without regard for understanding it first.

Forum on trading, automated trading systems and testing trading strategies

Prevent EA from opening trades at the same time across 2 or more pairs?

William Roeder, 2022.09.21 17:17

That was an outline, not a working file, showing how to make one. Here is a simplified, standalone version that should work.

Not compiled, not tested, just typed.

//+------------------------------------------------------------------+
//| 10:47 AM 9/21/2022                                    mutex1.mqh |
//|                              Copyright © 2022, William H. Roeder |
//|                                        mailto:WHRoeder@yahoo_com |
//+------------------------------------------------------------------+
/** @file
 * @brief Mutex locks on creation.                                            */
//+------------------------------------------------------------------+
/// Mutex lock on creation.
class Mutex{
 public:
   void     Mutex(bool lockIt=true, string name="Mutex") :              //[Ctor]
      mLocked(false), mName(name){              // Create GV if it doesn't exist
      if(!GlobalVariableCheck(mName) ) GlobalVariableTemp(mName);
      if(lockIt)  lock();
   }
   virtual ~Mutex(){                               release();  }        // Dtor
 public:                                                          // Methods
   bool     is_locked(void)                  const{return mLocked;             }
   void     lock(void){
      int   st = 0;
      while(!mLocked){
         if(GlobalVariableSetOnCondition(mName, 0, 1) )  mLocked = true;
         else                                            Sleep(st+=1000);
      }
      if(st != 0)    RefreshRates();                              // I slept.
   }  // lock
   void     release(void){
      if(mLocked){   GlobalVariableSet(mName, 0);  mLocked  = false; }
   }
 private:                                                         // Data
   string   mName;
   bool     mLocked;
};
//+- Mutex ----------------------------------------------------------+

/////////////////////////////////////////////////////////////
// TYPE function(){
//    Mutex m; // Unlocks on function exit.

Not compiled, not tested, just typed.

Forum on trading, automated trading systems and testing trading strategies

Prevent EA from opening trades at the same time across 2 or more pairs?

William Roeder, 2022.11.30 13:54

I did.
TYPE function(){
   Mutex m; // Unlocks on function exit.
   int CurrencyPairCount = …;
   GlobalVariableSet("CurrencyPairCount",CurrencyPairCount);
}

 
chuckdavis #:
[T]hey don't address the fundamental challenge: if two or more EAs want to open a trade at once ...even a global terminal var locking mechanism won't help and might actually run into race conditions due to processing synchronicity

I assume that your code would also be limiting the number of trades with something like PositionsTotal() or deal status. If EA1 opened a trade, the trade count would equal 1 and the master GV would equal say, 2.0, representing "in-the-market." As EA2 would be conditional on the trade count being zero and EA1 being "out-of-the-market," EA2 wouldn't trade... and so on regarding EA3.

When I need values "set in stone" and accessible to multiple indicators and/or multiple EA's, I frequently use GV's. In this way, I've never experienced race conditions. The GV values simply update in sequence.

My pc has a 2019 Intel Core i7 processor. Nothing special. I have no idea what you're running, of course.