I have the code below but **PostionsTotal()** is always returning zero even when there is open trades.

I am trying to return the total number of currently open trades.

I am using MT5 downloaded from Metaquotes.

Any help highly appreciated. Thanks.

```
int _Currently_Open_Trades_Of_Type(ENUM_ORDER_TYPE tradeType)
{
int totalPositions=0;
int total = PositionsTotal();
int oType;
if(total<=0)
{
return(0);
}
else
{
for(int i=total-1;i>=0;i--)
{
if (!PositionSelectByTicket(i)) continue;
oType = (int)PositionGetInteger(POSITION_TYPE);
if( oType==tradeType)
{
totalPositions++;
}
}
}
return(totalPositions);
}
```