Thread: MQL4 Guide
View Single Post
  #4 (permalink)  
Old 05-27-2007, 06:02 PM
RickD's Avatar
RickD RickD is offline
Member
 
Join Date: Jan 2006
Location: Eastern Europe
Posts: 52
RickD is on a distinguished road
GetLastOpenTime function gets OpenTime of the last order with predefined type.
The function makes a search of open trades and the history.
-1 means there are no orders found.

Code:
datetime GetLastOpenTime(int type) 
{
 
  datetime tm = -1;
 
  int cnt = OrdersTotal();
  for (int i=0; i<cnt; i++) 
  {
    if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
    
    //Optional
    //if (OrderSymbol() != Symbol()) continue;
    //if (OrderMagicNumber() != Magic) continue;
    
    if (OrderType() != type) continue;
    
    tm = MathMax(tm, OrderOpenTime());
  }
 
  cnt = OrdersHistoryTotal();
  for (i=0; i<cnt; i++) 
  {
    if (!OrderSelect(i, SELECT_BY_POS, MODE_HISTORY)) continue;
 
    //Optional
    //if (OrderSymbol() != Symbol()) continue;
    //if (OrderMagicNumber() != Magic) continue;
    
    if (OrderType() != type) continue;
    
    tm = MathMax(tm, OrderOpenTime());
  }
 
  return (tm);
}
Reply With Quote