Opening one position per currency pair in mt5 - page 4

 
Vladimir Karputov:

An example for you: No more than N positions for each symbol Simple

I salute you Sir. You really are an asset to the MQL5 community. Thank you for your help and guidance. 

 
Vladimir Karputov #:

I showed the solution - how to get the number of BUY positions and the number of SELL positions at once for all symbols in one function:

//+------------------------------------------------------------------+
//| Calculate all positions Buy and Sell                             |
//+------------------------------------------------------------------+
void CalculateAllPositions(STRUCT_CALCULATE_POSITIONS &SCalculatePositions[])
  {
   ArrayFree(SCalculatePositions);
   for(int i=PositionsTotal()-1; i>=0; i--)
      if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
        {
         string pos_symbol=m_position.Symbol();
         int size=ArraySize(SCalculatePositions);
         int find=false;
         for(int j=0; j<size; j++)
           {
            if(SCalculatePositions[j].symbol==pos_symbol)
              {
               if(m_position.PositionType()==POSITION_TYPE_BUY)
                  SCalculatePositions[j].count_buys=SCalculatePositions[j].count_buys+1;
               if(m_position.PositionType()==POSITION_TYPE_SELL)
                  SCalculatePositions[j].count_sells=SCalculatePositions[j].count_sells+1;
               find=true;
               break;
              }
           }
         if(!find)
           {
            ArrayResize(SCalculatePositions,size+1);
            SCalculatePositions[size].symbol=pos_symbol;
            if(m_position.PositionType()==POSITION_TYPE_BUY)
               SCalculatePositions[size].count_buys=SCalculatePositions[size].count_buys+1;
            if(m_position.PositionType()==POSITION_TYPE_SELL)
               SCalculatePositions[size].count_sells=SCalculatePositions[size].count_sells+1;
           }
        }
//---
   return;
  }
In the j-loop you compare the symbols in the SCalculatePositions[] - Array with the position symbol and only if they are equal you check for Position-Type and start counting . However, what is the value of variable size before you run into the j-loop?  Where does SCalculatePositions[] get its values (symbols) from that size becomes > 0? Thanks in advance.
Reason: