last closed order profit

28 August 2017, 14:30
jatinpruthvi
0
20
// return last closed ticket (returns -1 if not found)
int LastClosedTicket()
{
   datetime last_closed = 0;           // close time of last closed order
   int last_ticket = -1;               // ticket number of last closed order  
   
   // loop on all orders in history pool and filter
   for (int i=0; i<OrdersHistoryTotal(); i++) {  
      if (!OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)) continue;
      //if (OrderMagicNumber() != MAGIC) continue;
      
      if (OrderType()<=1) {
         if (OrderCloseTime() > last_closed) {        // here we filter the last closed order
            last_closed = OrderCloseTime();           // save close time and ticket for next iteration
            last_ticket = OrderTicket();
         }
      }
   }
   
   return(last_ticket);
}

// return last closed profit (returns 0 if not found)
double LastClosedProfit()
{
   int last_ticket = LastClosedTicket();
   
   if (last_ticket > 0) {
      if (OrderSelect(last_ticket,SELECT_BY_TICKET,MODE_HISTORY))
         return(OrderProfit());
   }
   
   return(0.0);
}
Share it with friends: