Draw the profit on the candle that closed the transaction

 
Hello guys,

I'm trying to create an element that writes the profit from the last transaction above on the candle that ended the transaction.

So far I've been able to get here, but I still haven't been able to make it do what I need.

void DrawProfit()
{
     double profit = 0;
     ulong  ticket;
     string CurrDate = TimeToString(TimeCurrent(), TIME_DATE);

     HistorySelect(StringToTime(CurrDate), TimeCurrent());
     for(int i = HistoryDealsTotal() - 1; i >= 0; i--) {
          ticket = HistoryDealGetTicket(i);
          if(ticket > 0) {
               if(HistoryDealGetString(ticket, DEAL_SYMBOL) == _Symbol && HistoryDealGetInteger(ticket, DEAL_MAGIC) == MagicNumber) {
                    profit = HistoryDealGetDouble(ticket, DEAL_PROFIT);
                    ObjectCreate(_Symbol,StringFormat("Profit %s",profit),OBJ_TEXT,0,0,0);
                    ObjectSetInteger(0,StringFormat("Profit %s",profit),OBJPROP_FONTSIZE,8);
                    ObjectSetInteger(0,StringFormat("Profit %s",profit),OBJPROP_COLOR,clrWhite);
                    ObjectSetInteger(0,StringFormat("Profit %s",profit),OBJPROP_BGCOLOR,clrGreen);
                    ObjectSetString(0,StringFormat("Profit %s",profit),OBJPROP_TEXT,profit);
                    break;
               }
          }
     }
}


As a demonstration, follow my goal: