int OrdersHistoryTotal( )
Returns the number of closed orders in the account history loaded into the terminal. The history list size depends on the current settings of the "Account history" tab of the terminal.
// retrieving info from trade history
//---- check selection result
Print("Access to history failed with error (",GetLastError(),")");
// some work with order
The most recent closed is probably index 0, but not sure, from there use other order key words open price and close price etc to compute the p/l.