Thread: MQL4 Guide
View Single Post
  #3 (permalink)  
Old 05-27-2007, 06:01 PM
RickD's Avatar
RickD RickD is offline
Member
 
Join Date: Jan 2006
Location: Eastern Europe
Posts: 54
RickD is on a distinguished road
How to close the all market orders:
Code:
int Slippage = 3;
 
void CloseOrders() 
{
  int cnt = OrdersTotal();
  for (int i=cnt-1; i>=0; i--) {
    if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
 
    //if (OrderSymbol() != Symbol()) continue;
    //if (OrderMagicNumber() != Magic) continue;
 
    if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), Slippage);
    if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), Slippage);
  }
}
How to close all the orders of predefined type:
Code:
void CloseOrders(int type) 
{
  int cnt = OrdersTotal();
  for (int i=cnt-1; i>=0; i--) {
    if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
 
    //if (OrderSymbol() != Symbol()) continue;
    //if (OrderMagicNumber() != Magic) continue;
    
    if (OrderType() != type) continue;
    
    if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), Slippage);
    if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), Slippage);
  }
}
Reply With Quote