How to change the total buy and sell order code for different pairs

 
int cntBuy = 0;
int cntSell = 0;

void OnTick(){

   Comment("\n\n\n\n\n"+
           "Buy Count : ", cntBuy, "\n",
           "Sell Count : ", cntSell, "\n");

   cntBuy = 0;   cntSell = 0;                   // initialize counts

   for(int i = PositionsTotal() - 1 ; i >= 0 ; i--){
     PositionGetTicket(i);                                    
         if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_BUY){
            cntBuy++;
         }
         if(PositionGetInteger(POSITION_TYPE) == POSITION_TYPE_SELL){
            cntSell++;
         }

     } // for loop end
  }

I use this code to count the total number of buy and sell orders for all my pairs but how can I change the code to make it count only individual pairs attached to each chart?

 
Your topic has been moved to the section: Expert Advisors and Automated Trading
Please consider which section is most appropriate — https://www.mql5.com/en/forum/172166/page6#comment_49114893
 
psychekiro: I use this code to count the total number of buy and sell orders for all my pairs but how can I change the code to make it count only individual pairs attached to each chart?

Positions are not associated with charts. They are, however, associated with symbols. So, check if the symbol matches the chart symbol.

PositionGetString

Returns the requested property of an open position (string)

ENUM_POSITION_PROPERTY_STRING

POSITION_SYMBOL

Symbol of the position

string

Or, instead of using "PositionGetTicket", you can use "PositionGetSymbol" to select and get the symbol, instead of the ticket number if you don't need it.

EDIT: Also, consider using a Magic Number to prevent the EA from clashing with other running EAs if it is only counting its own positions.