How to set number of open positions at same time, please help!

 
I have wrote a EA in mql5 void onTick part, I used Ctrade library for opening positions, the EA recognize the condition correctly but it opens alot of positions at same time on one bar!
How can I set the max positions to be opened at a same time? I want it ti open like 5 open positions

Please help me with that! 
Tnx in advance
 
Fafar.forex:
I have wrote a EA in mql5 void onTick part, I used Ctrade library for opening positions, the EA recognize the condition correctly but it opens alot of positions at same time on one bar!
How can I set the max positions to be opened at a same time? I want it ti open like 5 open positions

Please help me with that! 
Tnx in advance


You can check how many items are open:

//+------------------------------------------------------------------+
//| Calculate Positions                                              |
//+------------------------------------------------------------------+
void CalculatePositions()
  {
   int total=0.0;

   for(int i=PositionsTotal()-1;i>=0;i--)
      if(m_position.SelectByIndex(i)) // selects the position by index for further access to its properties
         if(m_position.Symbol()==m_symbol.Name() && m_position.Magic()==m_magic)
           total++;
//---
   return(total);
  }