How to run an ea on many symbols by attaching it to one chart ?

dr.elkurdi
47

Dear all,

I need help to code an ea that checks the same conditions to open and close trades on as many symbols as it can from the symbols that the broker is dealing in, without opening their charts.

  •   any help on a code that returns " Symbol" and adds it tho the Ordersend.it is a try to run the ea on many currencies by attaching it to one chart.

Here is my try but I do not know if it will work

// Function call:
string Sympol = CheckSympol( "EURUSD,USDJPY,GBPUSD,USDCHF,AUDUSD,USDCAD,NZDUSD,EURGBP,EURJPY,GBPJPY,CHFJPY" );
// Function:
string CheckSympol( string Sympol )
{
    string symbols[];
    string Sympol = "NONE";
    for( int i=0; i<11; i++) // 11 is the maximum number to loop the condition and it equals the number of symbols to check.
    {
           Sympol = symbols[i];    
    }
    return (Sympol);
}
Marco vd Heijden
Moderator
13595
  for(int i=0;i<SymbolsTotal(1);i++)
     {
      Print("SYMBOL: ",SymbolName(i,1)," Found At: ",i);
     }


//+------------------------------------------------------------------+
//| Symbols Total, by Marco van der Heijden                          |
//+------------------------------------------------------------------+
 for(int i=0;i<SymbolsTotal(1);i++)
  {  
   if(SymbolName(i,1)=="AUDCAD")
    {
     // do something for AUDCAD
    }     
   if(SymbolName(i,1)=="AUDCHF")
    {
     // do something for AUDCHF 
    }     
   if(SymbolName(i,1)=="AUDJPY")
    {
     // do something...
    }
   if(SymbolName(i,1)=="AUDNZD")
    {
      
    }
   if(SymbolName(i,1)=="AUDSGD")
    {
      
    }
   if(SymbolName(i,1)=="AUDUSD")
    {
      
    }
   if(SymbolName(i,1)=="AUS200")
    {
      
    }
   if(SymbolName(i,1)=="CADCHF")
    {
      
    }
   if(SymbolName(i,1)=="CADJPY")
    {
      
    }
   if(SymbolName(i,1)=="CHFJPY")
    {
      
    }
   if(SymbolName(i,1)=="CHFSGD")
    {
      
    }
   if(SymbolName(i,1)=="EURAUD")
    {
      
    }
   if(SymbolName(i,1)=="EURCAD")
    {
      
    }
   if(SymbolName(i,1)=="EURCHF")
    {
      
    } 
   if(SymbolName(i,1)=="EURCZK")
    {
      
    }
   if(SymbolName(i,1)=="EURGBP")
    {
      
    }
   if(SymbolName(i,1)=="EURJPY")
    {
      
    }
   if(SymbolName(i,1)=="EURNOK")
    {
      
    }
   if(SymbolName(i,1)=="EURNZD")
    {
      
    }
   if(SymbolName(i,1)=="EURPLN")
    {
      
    }
   if(SymbolName(i,1)=="EURSEK")
    {
      
    }
   if(SymbolName(i,1)=="EURSGD")
    {
      
    }
   if(SymbolName(i,1)=="EURTRY")
    {
      
    }
   if(SymbolName(i,1)=="EURUSD")
    {
      
    }
   if(SymbolName(i,1)=="EURZAR")
    {
      
    }
   if(SymbolName(i,1)=="EUSTX50")
    {
      
    }
   if(SymbolName(i,1)=="FRA40")
    {
      
    }
   if(SymbolName(i,1)=="GBPAUD")
    {
      
    }
   if(SymbolName(i,1)=="GBPCAD")
    {
      
    }
   if(SymbolName(i,1)=="GBPCHF")
    {
      
    }
   if(SymbolName(i,1)=="GBPJPY")
    {
      
    }
   if(SymbolName(i,1)=="GBPNOK")
    {
      
    }
   if(SymbolName(i,1)=="GBPNZD")
    {
      
    }
   if(SymbolName(i,1)=="GBPSEK")
    {
      
    }
   if(SymbolName(i,1)=="GBPSGD")
    {
      
    }
   if(SymbolName(i,1)=="GBPTRY")
    {
      
    }
   if(SymbolName(i,1)=="GBPUSD")
    {
      
    }
   if(SymbolName(i,1)=="GER30")
    {
      
    }
   if(SymbolName(i,1)=="HK50")
    {
      
    } 
   if(SymbolName(i,1)=="IT40")
    {
      
    }
   if(SymbolName(i,1)=="JPN225")
    {
      
    }
   if(SymbolName(i,1)=="NAS100")
    {
      
    }
   if(SymbolName(i,1)=="NOKJPY")
    {
      
    }
   if(SymbolName(i,1)=="NOKSEK")
    {
      
    }
   if(SymbolName(i,1)=="NZDCAD")
    {
      
    }
   if(SymbolName(i,1)=="NZDCHF")
    {
      
    }
   if(SymbolName(i,1)=="NZDJPY")
    {
      
    }     
   if(SymbolName(i,1)=="NZDUSD")
    {
      
    }
   if(SymbolName(i,1)=="SEKJPY")
    {
      
    }
   if(SymbolName(i,1)=="SGDJPY")
    {
      
    }
   if(SymbolName(i,1)=="SPA35")
    {
      
    }
   if(SymbolName(i,1)=="UK100")
    {
      
    }
   if(SymbolName(i,1)=="US2000")
    {
      
    }
   if(SymbolName(i,1)=="US30")
    {
      
    }
   if(SymbolName(i,1)=="US500")
    {
      
    } 
   if(SymbolName(i,1)=="USDCAD")
    {
      
    }
   if(SymbolName(i,1)=="USDCHF")
    {
      
    }
   if(SymbolName(i,1)=="USDCNH")
    {
      
    }
   if(SymbolName(i,1)=="USDCZK")
    {
      
    }     
   if(SymbolName(i,1)=="USDHKD")
    {
      
    }
   if(SymbolName(i,1)=="USDJPY")
    {
      
    }
   if(SymbolName(i,1)=="USDMXN")
    {
      
    }
   if(SymbolName(i,1)=="USDNOK")
    {
      
    }     
   if(SymbolName(i,1)=="USDPLN")
    {
      
    }
   if(SymbolName(i,1)=="USDRUB")
    {
      
    }
   if(SymbolName(i,1)=="USDSEK")
    {
      
    }
   if(SymbolName(i,1)=="USDSGD")
    {
      
    }     
   if(SymbolName(i,1)=="USDTHB")
    {
      
    }
   if(SymbolName(i,1)=="USDTRY")
    {
      
    }
   if(SymbolName(i,1)=="USDZAR")
    {
      
    }
   if(SymbolName(i,1)=="XAGEUR")
    {
      
    }     
   if(SymbolName(i,1)=="XAGUSD")
    {
      
    }
   if(SymbolName(i,1)=="XAUEUR")
    {
      
    }      
   if(SymbolName(i,1)=="XAUUSD")
    {
      
    }
   if(SymbolName(i,1)=="XBRUSD")
    {
      
    } 
   if(SymbolName(i,1)=="XNGUSD")
    {
       
    }
   if(SymbolName(i,1)=="XPDUSD")
    {
       
    } 
   if(SymbolName(i,1)=="XPTUSD")
    {
       
    }
   if(SymbolName(i,1)=="XTIUSD")
    {
       
    } 
   if(SymbolName(i,1)=="ZARJPY")
    {
        
    }
   if(SymbolName(i,1)==" ")
    {
     //maybe more? add here. 
    }                                                                                                                               
  }//END for(i=0;i<SymbolsTotal(1);i++)
//+------------------------------------------------------------------+

Here's a template i made especially for you.

dr.elkurdi
47
dr.elkurdi  
Marco vd Heijden:


Here's a template i made especially for you.

Thank you very much.

I'll try it .

and what about this : Modified from szgy74

extern bool Trade_On_All_Market_Currencies=true;
string _Sympols;




// Function Call
if (Trade_On_All_Market_Currencies){
                                     _Sympols=Symbols();
                                   }
else _Sympols=Symbol();
//end of function call

//Function
string Symbols()
{
   int iCount=SymbolsTotal(false); // true, the function returns the number of symbols selected in MarketWatch. If the value is false, it returns the total number of all symbols.
Print("Symbols Count: ", iCount);
   int i;
   for(i=0; i<iCount; i++)
   {
      string sSymbol=SymbolName(i, false);// true, the symbol is taken from the list of symbols selected in MarketWatch. If the value is false, the symbol is taken from the general list.
     // string desc=SymbolInfoString(sSymbol, SYMBOL_DESCRIPTION);
   }
   return(sSymbol);
}
JD4
838
JD4  
Marco vd Heijden:


Here's a template i made especially for you.

Wouldn't a case/switch structure also work with this?
Marco vd Heijden
Moderator
13595
a switch can also work but its a little bit different with integer constants so the example above is a bit more easy as it shows the actual symbol name.
JD4
838
JD4  
Marco vd Heijden:
a switch can also work but its a little bit different with integer constants so the example above is a bit more easy as it shows the actual symbol name.
I know in Java you can use enumerated lists with case/switch code.  Doing it that way, you could create an enumerated lists with all the currency pair names.  Do you think that it would be possible with MQL5 Lite (MQL4) and MQL5?
Marco vd Heijden
Moderator
13595

yes of course.

enum symbols
{
AUDCAD=0,
AUDCHF=1,
...
};
the problem with this is that the positions can vary between brokers where in the first examples, it will always only use what is offered, when int i comes across it at the right position this way you can be sure the same symbol is always at the same int i position in the code, and there can be no mix up of string comparison.
Jose Miguel Soriano
4575
dr.elkurdi:

Dear all,

I need help to code an ea that checks the same conditions to open and close trades on as many symbols as it can from the symbols that the broker is dealing in, without opening their charts.

  •   any help on a code that returns " Symbol" and adds it tho the Ordersend.it is a try to run the ea on many currencies by attaching it to one chart.

Here is my try but I do not know if it will work

You can study the use of OnChartEvent ()

https://www.mql5.com/en/articles/1052 

Optimization. A Few Simple Ideas
Optimization. A Few Simple Ideas
  • 2015.03.05
  • Jose Miguel Soriano
  • www.mql5.com
The optimization process can require significant resources of your computer or even of the MQL5 Cloud Network test agents. This article comprises some simple ideas that I use for work facilitation and improvement of the MetaTrader 5 Strategy Tester. I got these ideas from the documentation, forum and articles.
JD4
838
JD4  

I went back and looked through the posts from other threads, but am having problems with the search function working properly.  There was a thread, I do not remember if it was on MQL4 or 5 right now, but someone was trying to run multiple instances of the trading platform.  One of the topics covered there was EAs, and the platform only allows a maximum of one EA per chart.  I am not sure if this applies here, or if you can trade other pairs without having a chart open for them or not.

Edit: I found the other thread I was talking about.  It is here at https://www.mql5.com/en/forum/59293.

Alain Verleyen
42595
JD4:

I went back and looked through the posts from other threads, but am having problems with the search function working properly.  There was a thread, I do not remember if it was on MQL4 or 5 right now, but someone was trying to run multiple instances of the trading platform.  One of the topics covered there was EAs, and the platform only allows a maximum of one EA per chart.  I am not sure if this applies here, or if you can trade other pairs without having a chart open for them or not.

Edit: I found the other thread I was talking about.  It is here at https://www.mql5.com/en/forum/59293.

That has nothing to do with the current topic.
JD4
838
JD4  
Alain Verleyen:
That has nothing to do with the current topic.
One specific comment does, the one about how many EAs are allowed on one chart.  I would link that specific spot if I knew how.