How to get Total Profit of Closed Position by Magic Number ??

 

Hello, below code is to show information of Total profit at current symbol and with time range 15 minutes.

double CANDLE_POROFIT()
{
   datetime CurentTime = TimeCurrent(); 
   datetime PrevTime   = iTime(Symbol(),PERIOD_M15,1); 

   HistorySelect(PrevTime,CurentTime);
   
   int    trades_of_day = 0;
   double wining_trade  = 0.0;
   double losing_trade  = 0.0;
   double total_profit  = 0.0;
   uint   total         = HistoryDealsTotal();
   ulong  ticket        = 0;
   
   for(uint i=0; i<total; i++)
     {
      if((ticket=HistoryDealGetTicket(i))>0)
         trades_of_day++;
         string symbol          = HistoryDealGetString(ticket,DEAL_SYMBOL);
         double deal_commission = HistoryDealGetDouble(ticket,DEAL_COMMISSION);
         double deal_swap       = HistoryDealGetDouble(ticket,DEAL_SWAP);
         double deal_profit     = HistoryDealGetDouble(ticket,DEAL_PROFIT);
         double profit          = deal_commission + deal_swap + deal_profit;
         if(Symbol() == symbol)
         {
          if(profit>0.0) wining_trade+=profit;
          if(profit<0.0) losing_trade+=profit;
          total_profit += profit;
         }
     }

return(total_profit);
}

Then how to filter result for only Specific Magic number or order comment maybe.

Someone help me please, thank you, in MQL4 is easy, but on MQL5 more complicated.

 
Syarif Nur Arief: Then how to filter result for only Specific Magic number or order comment maybe.

You have selected the deal and got the ticket. Read the MN, compare and continue. Exactly the same as you would in MT4

 
William Roeder #:

You have selected the deal and got the ticket. Read the MN, compare and continue. Exactly the same as you would in MT4

Thank you
Reason: