[MQL4 Coding Advise] Which is best for filtering order with symbol and Magic Number?

shanmugapradeep

Active Trader
Dec 18, 2020
118
5
34
38
Hello,

Which will be more effective, reliable and faster?

Code 1 :

MQL4:
void CloseOpenAndPendingTrades(int trade_close_magic)
  {
   for(int pos_0 = OrdersTotal() - 1; pos_0 >= 0; pos_0--)
     {
      OrderSelect(pos_0, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol() != Symbol() || OrderMagicNumber() != trade_close_magic)
         continue;
 
      if(OrderType() > OP_SELL)
         OrderDelete(OrderTicket());
      else
        {
         if(OrderType() == OP_BUY)
            OrderClose(OrderTicket(), OrderLots(), Bid, 3, CLR_NONE);
         else
            OrderClose(OrderTicket(), OrderLots(), Ask, 3, CLR_NONE);
        }
     }
  }


Code 2 :

MQL4:
void CloseOpenAndPendingTrades(int trade_close_magic)
  {
   for(int pos_0 = OrdersTotal() - 1; pos_0 >= 0; pos_0--)
     {
      OrderSelect(pos_0, SELECT_BY_POS, MODE_TRADES);
      if(OrderSymbol() == Symbol() && OrderMagicNumber() == trade_close_magic)
         {
 
      if(OrderType() > OP_SELL)
         OrderDelete(OrderTicket());
      else
        {
         if(OrderType() == OP_BUY)
            OrderClose(OrderTicket(), OrderLots(), Bid, 3, CLR_NONE);
         else
            OrderClose(OrderTicket(), OrderLots(), Ask, 3, CLR_NONE);
        }
     }
  }
}




Using not Equal to (or) using Equal to?
 

shanmugapradeep

Active Trader
Dec 18, 2020
118
5
34
38
I myself prefer the first variant because it offers better readability due to fewer curly brackets.
Thanks for suggestion.

Should i use BID/ASK :

MQL4:
if(OrderType() > OP_SELL)
         OrderDelete(OrderTicket());
      else
        {
         if(OrderType() == OP_BUY)
            OrderClose(OrderTicket(), OrderLots(), Bid, 3, CLR_NONE);
         else
            OrderClose(OrderTicket(), OrderLots(), Ask, 3, CLR_NONE);
        }

(OR) OrderClosePrice() :

MQL4:
if(OrderType() > OP_SELL)
         OrderDelete(OrderTicket());
      else
            OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 3, CLR_NONE);