Did you check the history of the forum ?
jojocash:
How can I get History Profit in MQL5 ?
This is MT4 code...
Have any example ? Thank you.
- 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); }
- 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.
fxsaber:
- MQL5
- MQL5 + MQL4
wow! Thanks a lot.
The MQL5 + MQL4 were very cool.

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
How can I get History Profit in MQL5 ?
This is MT4 code...
Have any example ? Thank you.