MQL4 -> MQL5 strange problem

 

Hello everyone,

I programming MQL4 since some years so I can make indicators and EA without problems…

Now I’m studying MQL5 but I have some problems.

For example it’s so simple in MQL4 to count orders by type (open e pending)..

In MQL5, if I understood, I have to choose if I would to count pending or open orders… I can’t make a function that do all things like in MQL4…

In MQL4 I simply do something like this:

int TradesCount(int type) 
 {
  int result = 0;
  int total = OrdersTotal();
  for(int i = 0; i < total; i++)
    {
     if(OrderSelect(i, SELECT_BY_POS, MODE_TRADES) == false) continue;
     if(OrderMagicNumber() != MagicNumber || OrderSymbol() != Symbol() || OrderType() != type) continue;
     result++;
    }
  return(result);
 }

In MQL5 I can’t… I should create 2 functions, one to count pending orders and one to count open orders… It’s a ugly scenario for me…

 int TradesOpenCount(int type) 
 {
  int result = 0;
  int total = PositionsTotal();

  for(int i = total - 1; i >=0; i--)
    {
      if(PositionGetSymbol(i)!=Symbol()) continue;
      if(PositionGetInteger(POSITION_MAGIC) != MagicNumber || PositionGetInteger(POSITION_TYPE) != type) continue;
      result++;
    }
  return(result);
 }


 int TradesPendingCount(int type) 
 {
  int result = 0;
  int total = OrdersTotal();

  for(int i = total - 1; i >=0; i--)
    {
      OrderGetTicket(i);
      if(type == ORDER_TYPE_SELL_STOP || ORDER_TYPE_BUY_STOP) if(OrderGetString(ORDER_SYMBOL)!=Symbol()) continue;
      if(OrderGetInteger(ORDER_MAGIC) != MagicNumber || OrderGetInteger(ORDER_TYPE) != type) continue;
      result++;
    }

  return(result);
 }

Same thing for open an order (at market or pending): in MQL4 I created a function that open a trade (at market or pending) passing some data (type, price, sl, etc...)... In MQL5 I can't do something similar...

Where I'm wrong? There is a way to count orders by type or open an order link in MQL4 (without using MQL4 library).

Thanks