Getting history Profit in MQL5

How can I get History Profit in MQL5 ?

This is MT4 code…

Have any example ? Thank you.

double Profit()
  {
   double pp;

   for(int i=OrdersHistoryTotal()-1; i>=0; i--)
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_HISTORY)==true )
        {
         if(OrderSymbol()==Symbol() && OrderMagicNumber()==MagicNumber )
           {
            pp=OrderProfit()+pp;
           }
        }
     }
   return (pp);
  }
//+------------------------------------------------------------------+

MQL5:

double Profit( void )
{
 double Res = 0;

 if (HistorySelect(0, INT_MAX))
   for (int i = HistoryDealsTotal() - 1; i >= 0; i--)
   {
     const ulong Ticket = HistoryDealGetTicket(i);
     
     if((HistoryDealGetInteger(Ticket, DEAL_MAGIC) == MagicNumber) && (HistoryDealGetString(Ticket, DEAL_SYMBOL) == Symbol()))
       Res += HistoryDealGetDouble(Ticket, DEAL_PROFIT);
   }
     
  return(Res);
}



MQL4+MQL5:

#include <MT4Orders.mqh> // https://www.mql5.com/ru/code/16006

double Profit( void )
{
 double Res = 0;

 for (int i = OrdersHistoryTotal() - 1; i >= 0; i--)
   if(OrderSelect(i, SELECT_BY_POS, MODE_HISTORY) && (OrderMagicNumber() == MagicNumber) && (OrderSymbol() == Symbol()))
     Res += OrderProfit();
     
  return(Res);
}

HistoryPositionInfo version 2:

The CHistoryPositionInfo class is designed for getting the profit of a position in points, commission, swap and profit in money based on the trading history.

wow! Thanks a lot.

The MQL5 + MQL4 were very cool.

Thank you. ^^ …