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

William Roeder  
Steve H #: Is there any way of doing this without requiring an external file?

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.