How to turn an EA into Universal EA?

 

Dear Community,


I would like to know what makes an Expert Advisor to be universal (to attach on one chart and trade all symbols)?


for the following code:

#property copyright "Copyright © 2011, Krzysztof Sosnierz"
#property link      ""

// Current counters
int market   = 0;

// Previous counters
int pmarket  = 0;


//+------------------------------------------------------------------+
//| script init  function                                            |
//+------------------------------------------------------------------+
int init()
{
  
    
    // Initialize counters
    countOrders();
    
    pmarket  = market;

}
//+------------------------------------------------------------------+
void countOrders()
{

    market  = 0;

    
    for(int i = 0; i < OrdersTotal(); i++)
    {
        if(OrderSelect(i, SELECT_BY_POS))
        {
            switch(OrderType())
            {
            case OP_BUY:
            case OP_SELL:
                market++;
                break;
            }                
        }   
    }          
}
//+------------------------------------------------------------------+
//| script deinit function                                           |
//+------------------------------------------------------------------+
int deinit()
{
 
}
//+------------------------------------------------------------------+
string makeSubject(string text)
{
    return (StringConcatenate("#", OrderTicket(), " ", OrderSymbol(), " ", text));
}
//+------------------------------------------------------------------+
void email(string subject, string body)
{
    Print(subject);
    Print(body);
        
    SendMail(subject, body);
}

//+------------------------------------------------------------------+
//| script CheckOrders function                                    |
//+------------------------------------------------------------------+
int checkOrders()
{
    // Get current counters
    countOrders();
    
    double tp, sl, cl, op;
    string subject;
   
    if(market > pmarket)
    {
        // Select new market order
        for(int j = OrdersTotal() - 1; j >= 0; j--)
        {
            if(OrderSelect(j, SELECT_BY_POS) == false)
            {
                Print("OrderSelect returned the error of ", GetLastError());
                continue;
            }
            
            if(OrderSymbol() != Symbol())
            {
                continue;
            }            
            
            tp = OrderTakeProfit();
            sl = OrderStopLoss();
            op = OrderOpenPrice();            
            
            switch(OrderType())
            {
            case OP_BUY:
                subject = makeSubject("buy order opened");
                break;  
                          
            case OP_SELL:
                subject = makeSubject("sell order opened");
                break;
                
            default:
                continue;
            }
            
            email(subject, StringConcatenate("open: ", op, ", sl: ", sl, ", tp: ", tp));
            break;
        }
    }
    
 
    // Save current counters
    pmarket  = market;

}
//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
{
   // Main loop
   while(!IsStopped())
   {
      // Refresh buffers
      RefreshRates();
      // Get and process new events
      checkOrders();
      // Pass control to the terminal for a while
      Sleep(100);
   }
   
   return(0);
}
//+------------------------------------------------------------------+
 
Cristian Baciu:

Dear Community,


I would like to know what makes an Expert Advisor to be universal (to attach on one chart and trade all symbols)?


for the following code:


I do receive emails only from the currency I attached the EA.


Thank you for any advise :)

Add the SymbolsTotal() loop so it runs through all symbols.
 
Marco vd Heijden:
Add the SymbolsTotal() loop so it runs through all symbols.
Thank you! It is working!
 

Comment out the lines:

// if(OrderSymbol() != Symbol())
// {
//   continue;
// }
Reason: