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);
  }
//+------------------------------------------------------------------+
 
 
jojocash:

How can I get History Profit in MQL5 ?

This is  MT4 code...

Have any example ? Thank you.

  1. 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);
    }


  2. MQL5 + MQL4
    #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);
    }
 
jojocash:

How can I get History Profit in MQL5 ?

This is  MT4 code...

Have any example ? Thank you.


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.

 
Alain Verleyen:
Did you check the history of the forum ?

Not yet, sorry!I have no find before.

 
fxsaber:

  1. MQL5


  2. MQL5 + MQL4

wow! Thanks a lot.

The MQL5 + MQL4 were very cool. 

 
Vladimir Karputov:

HistoryPositionInfo version 2:


Thank you. ^^

Reason: