Function returning the number of active symbol on the account.

Back to topics list To post a new topic, please log in or register
avatar
11
lugevho 2016.02.07 08: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!

avatar
Moderator
3418
GumRai 2016.02.07 09: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 

Back to topics list  

To add comments, please log in or register