History Profit in MQL5 ?

jojocash
307
jojocash  

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);
  }
//+------------------------------------------------------------------+
Alain Verleyen
40754
Alain Verleyen  
fxsaber
18931
fxsaber  
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);
    }
Vladimir Karputov
Moderator
219433
Vladimir Karputov  
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.

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

Not yet, sorry!I have no find before.

jojocash
307
jojocash  
fxsaber:

  1. MQL5


  2. MQL5 + MQL4

wow! Thanks a lot.

The MQL5 + MQL4 were very cool. 

jojocash
307
jojocash  
Vladimir Karputov:

HistoryPositionInfo version 2:


Thank you. ^^