When position is closed, you will receive a message with type ORDER_CLOSE_OK in onMessage method of your strategy. Then you can determine if closed position was profitable and save this info to appropriate counter or any data structure of yours.
Look at onMessage implementation of "Detect close by Stop Loss" example:
https://www.dukascopy.com/wiki/#Set_Stop ... _Stop_LossAlso take a look at Order State diagram to find more about messages:
https://www.dukascopy.com/wiki/#Order_state