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

 
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.

 
William Roeder #:

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.

Not compiled, not tested, just typed.

Thanks for the code. Could you please provide an example to show how to use your mutex class to wait for a global variable "CurrencyPairCount" to be unlocked before attempting to write to it?

Basically what I want to do is to take a count of the currency pairs that are ready to open when a new bar is generated. So initially CurrencyPairCount will be 0. If chart1 and chart2 are ready to open trades, one of the charts will increment the CurrencyPairCount to 1 and then the other will increment it to 2. Problem is sometimes both these charts attempt to increment at the same time, so the value of CurrencyPairCount will end up at 1, even though there are 2 trades ready to open. I want to avoid this.

 
Tony A Antony #: Could you please provide an example to show how to use your mutex class to wait for a global variable "CurrencyPairCount" to be unlocked before attempting to write to it?
I did.
TYPE function(){
   Mutex m; // Unlocks on function exit.
   int CurrencyPairCount = …;
   GlobalVariableSet("CurrencyPairCount",CurrencyPairCount);
}
 
William Roeder #:

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.

Not compiled, not tested, just typed.

Hi William 

I would like to discuss about scanner which filters and help to trade only the currency pair which is going to have Trending and with big Pips.

reply so we can discuss.

 
I want to use it with single pair

When I load 3 charts of same pair and all 3 charts shows signal on same place EA open trade on all 3 charts

I want EA to open only 1 trade at that time not all 3 charts should open trade 
 
Millennium Management #:
I want to use it with single pair

When I load 3 charts of same pair and all 3 charts shows signal on same place EA open trade on all 3 charts

I want EA to open only 1 trade at that time not all 3 charts should open trade 

I have deleted your other topic as the forum is not the place to place ads for a coder. You can use Freelance to find a coder if you can't code it yourself.

You posted that topic in the general section, this post is in the MQL4 section. Please be clear what you are working with.

If you want help with coding post your attempt and I am sure that someone will help you.

Trading applications for MetaTrader 5 to order
Trading applications for MetaTrader 5 to order
  • 2022.12.05
  • www.mql5.com
The largest freelance service with MQL5 application developers
 
Keith Watford #:

I have deleted your other topic as the forum is not the place to place ads for a coder. You can use Freelance to find a coder if you can't code it yourself.

You posted that topic in the general section, this post is in the MQL4 section. Please be clear what you are working with.

If you want help with coding post your attempt and I am sure that someone will help you.

Which topic you are telling you have deleted.

You are a coder and asking in form to go for coders.


Please keep form clean 

 
Millennium Management #: Which topic you are telling you have deleted. You are a coder and asking in form to go for coders. Please keep form clean. 

A moderator is telling you that requesting coding services should be done in the Freelance section and not in the Forum.

The Freelance system uses a "double blind" system, so neither the coder nor the customer know who each are until the selection is finalised.

Reason: