//+------------------------------------------------------------------+ //| GetTicketOfTrade.mq4 | //| Copyright © 2005, MetaQuotes Software Corp. | //| http://www.metaquotes.net/ | //+------------------------------------------------------------------+ #define LOWEST 0 #define HIGHEST 1 extern int MagicNumber = 20050610; int ticket; //+------------------------------------------------------------------+ //| Get the ticket of the a trade based on inputs //| //| cmd = OP_BUY //| which = 0 returns ticket of lowest open buy //| which = 1 returnds ticket of highest open buy //| cmd = OP_SELL //| which = 0 returns ticket of lowest open sell //| which = 1 returns ticket of highest open sell //+------------------------------------------------------------------+ int TicketOfTrade(int cmd, int which) { int ticket; int LowestBuy,HighestBuy, LowestSell, HighestSell; //---- LowestBuy = 9999; HighestBuy = 0; LowestSell = 9999; HighestSell = 0; for(int i=0;i HighestBuy) { HighestBuy = OrderOpenPrice(); ticket = OrderTicket(); } } } if(OrderType()==OP_SELL && cmd == OP_SELL) { if (which == 0) { if (OrderOpenPrice() < LowestSell) { LowestSell = OrderOpenPrice(); ticket = OrderTicket(); } } else { if (OrderOpenPrice() > HighestSell) { HighestSell = OrderOpenPrice(); ticket = OrderTicket(); } } } } } //---- return order ticket return(ticket); } //+------------------------------------------------------------------+ //| Start function | //+------------------------------------------------------------------+ void start() { ticket = TicketOfTrade(OP_SELL, LOWEST); if (ticket > 0) { if (OrderSelect(ticket, SELECT_BY_TICKET) == true) { // Add code to process order } } } //+------------------------------------------------------------------+