Download MetaTrader 5
To add comments, please log in or register
Post web links to other trader's signals and make profit
lugevho1
21
lugevho1 2016.02.07 07:53 

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!

Keith Watford
Moderator
9448
Keith Watford 2016.02.07 08:44  
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 

/
To add comments, please log in or register