How To Check Result Of Last Closed Trade

I want to build a simple martingale strategy to practice with, but i am confused as to how i can check the result of the last trade, whether it hit t.p or s.l. I'd really appreciate it if anyone can help me with the code to use. Thanks in advance :)
double deal_profitY()

   ulong ticket;
   datetime closeTime=0;
   bool found=false;
    double deal_profit=0;
    //ulong order_magic;
     string   symbol;
      for(int i=HistoryDealsTotal()-1; i>=0; i--)

   return ( deal_profit);
This sample returns only the result of the last deal, not the last position, nor the last trade. To get the result of the position, you have to loop through all the deals which belong to a specific position ticket. And regarding a trade, assuming that in such a strategy the definition of a trade is not just one position, you have to do this for every position in a loop as well. 
Unfortunately it´s a pity that there are no standard-classes which handle this for you and no standard-structs which simply return all informations about a deal. Functions like HistoryDealGetInteger() make the code really unreadable imho, but thats how it is. You should create some own libs if you want to create code which you will be able to read after a longer time without any headache.