Function returning the number of active symbol on the account.

 

Hello,

I am looking for a script that would return the number of active symbol on the account (number of symbols that have active orders). Il would use this value in an EA to limit the number of active symbols.

Thank you!

 
string OrderSymbolArray[];  //Globally Declared
//+------------------------------------------------------------------+
int CountOrderSymbols()
 {
 int as=0;
 ArrayResize(OrderSymbolArray,0);
 for(int x=OrdersTotal()-1;x>=0;x--)
    {
    bool found=false;
    if(OrderSelect(x,SELECT_BY_POS) && (OrderType()==OP_BUY || OrderType()==OP_SELL))  //Check excluding Pending Orders
    //if(OrderSelect(x,SELECT_BY_POS))                                                 //Check Active & Pending Orders
       {
       for(int y=as-1;y>=0;y--)
          {
          if(OrderSymbol()==SymbolArray[y])
             {
             found=true;
             break;
             }
          }
       if(!found)
          {
          as++;
          ArrayResize(OrderSymbolArray,as);
          OrderSymbolArray[as-1]=OrderSymbol();
          }
       }
    }
    return(as);
 }
 

This will count the symbols and also put the symbol names in an array.

It's old code of mine, but I thinjk that it should work ok 

Reason: