How to accurately get total positions

 

Hello everyone , I have encountered a problem and hope to receive everyone's help , thank you !

My question is very simple, just is to get the total positions 

My code :

#include <Trade\Trade.mqh>
CTrade    m_trade;
int OnInit()
   {
   return(INIT_SUCCEEDED);
   }
void OnDeinit(const int reason)
   {
   }
void OnTick()
   {
   string symbol  = Symbol();
   double ask     = SymbolInfoDouble(symbol,SYMBOL_ASK);
   for(int i=0;i<5;i++) //open 5 positions
      {
      m_trade.PositionOpen(symbol,ORDER_TYPE_BUY,0.01,ask,0,0);
      }
   int total = PositionsTotal();
   Print("Total pos = ",total);
   }

I also understand that the OrderSent() function returning TRUE does not necessarily mean that the trade success .

I know this is no the right way to get total positions , it just shows what i want through a easy way .

So the question is :

( Assuming that external conditions are both healthy and normal , such as the market starting normally , no issues with broker , liquidity , balance , web , and  so on )

If i trade 5 times in one tick , how do i accurately  get the right total positions . 

The premise is that I have already seen the transaction form in the Trade box on MT5 , but the Print() is incorrect .



I found a situation that if i put 

int total = PositionsTotal();
   Print("Total pos = ",total);

on the first line in OnTick() funtion , it will get me right print every times . why different ?