Thread: MQL4 Guide
View Single Post
 
Old 05-27-2007, 06:00 PM
RickD's Avatar
RickD RickD is offline
Member
 
Join Date: Jan 2006
Location: Eastern Europe
Posts: 52
RickD is on a distinguished road
OrdersCount function allows to get the orders count of predefined type.
Code:
int OrdersCount(int type)
{
  int orders = 0;
 
  int cnt = OrdersTotal();
  for (int i=0; i<cnt; i++) {
    if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
 
    //if (OrderSymbol() != Symbol()) continue;
    //if (OrderMagicNumber() != Magic) continue;
 
    if (OrderType() == type) orders++;
  }
 
  return (orders);
}
Example:
Code:
int start() 
{
  int BuyCnt = OrdersCount(OP_BUY);
  if (BuyCnt > 0) return (0);
  ...