EA detects other EAs

 

Hi everybody,

Is it possible than an EA detect if other EAs are running on the same terminal?

If so, could you show me the routine?


Thanks in advance 

 
Only if it finds orders without its magic number.
 

Hi, what do you want to do?

If EA 1 running, EA 2 have to sleep?

 
Kane59:

Hi, what do you want to do?

If EA 1 running, EA 2 have to sleep?

Cannot be done. Possible solutions would be outside the scope of mql4. 
 
ubzen:
Cannot be done. Possible solutions would be outside the scope of mql4. 

Yes it's possible:

applying a magicnumber to the first, exemple 300.

Orderstotal()
 
  for(....)
  Orderselect(....)

    if(OrderMagicNumber() ==300)  // Looking for orders with Magic 300

          { EA1= 1 }// It means that there is an order by the first EA.

If (EA1 != 1)
{
   Allowed to trade with the second EA.
}
else 
{
   Print("The first EA is running")
}
 

The only way that I can think of with out looking for is through global variables.

#include "shared_file.mq4";
int number = 12345;
void init()
{
StartEA(number);
}
void deinit()
{
StopEA(number);
}
void start()
{
if(OtherEA(number))return;
// rest of code
}

 

 shared_file.mq4:

void StartEA(int number){
if(GlobalVariableCheck("EAcheck_"+number))GlobalVariableSet("EAcheck_"+number,WindowHandle(Symbol(),Period()));
}

void StopEA(int number){
if(GlobalVariableCheck("EAcheck_"+number))GlobalVariableDel("EAcheck_"+number);
}

bool OtherEA(int number)
{
for(int i=GlobalVariablesTotal()-1;i>=0;i--)
{
if(StringFind(GlobalVariableName(i),"EAcheck")>-1){if(GlobalVariableName(i)=="EAcheck_"+number)continue;return(true);}
}
return(false);
}

The have the code on all the EA which your likely to run at the same time. You could also modify it to check against a set list ie. 1 EA is good to trade while another isn't. 

 
Kane59:

Yes it's possible:

applying a magicnumber to the first, exemple 300.

Finding magic# 300 does not mean the other expert is still running. If you already have both experts codes, magic# etc. Then why ask a question you already know the answer to?
 
It's not me who ask the question ^^ but wanted to know what he wanted to do with?
 

Thanks everybody for your comments and ideas.

The idea is having a group of users doing a trading contest where the EAs are not allowed.

I think by reading the Magic Number would it possible to know it.

Regards 

 

An EA not necessarily sets a magic number. If omitted, it is 0 like for manual trades.

 
kronin:

An EA not necessarily sets a magic number. If omitted, it is 0 like for manual trades.

Any EA should not have magic number equal to zero, just in case the trader wants to interfere the trade by manual trade, that way both EA and the trader won't be a interfering and become a problem to each other.
Reason: