Referencing Closed Orders

 
Hello All,

I'm a newbie at MQL4 and like most if not all I'm hoping to create the perfect program that makes lots of money :-). That being said I'm having difficulty with something that I fear is probably relatively easy for most. I'm trying to analyze my last closed order and see if it made profit or not. I've been trying to use the OrderMagicNumber() of that particular order. However I cannot for the life of me figure out how to write it in the OrderSelect() since you must either use a ticket or index? So thats the question how do i look at my last closed order find its profit and store it as a variable? Example code would be greatly appreciated. Thankyou in advance for all you reply.

Sincerely,
Justin L. Halpin
justinhalpin@hotmail.com
 
int GetOrder(int Magic) {
 
  int cnt = OrdersTotal();
  for (int i=0; i < cnt; i++) {
    if (!OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) continue;
    if (OrderMagicNumber() == Magic) return (OrderTicket());
  }
 
  return (-1);
}