Total Current Profit

10284

Hi,

I know how to get the profit of a position on the current symbol the EA is running on. But how to get the total profit for all the position opened by the EA ?

Thanks.

Moderator
10184

blouf:

Hi,

I know how to get the profit of a position on the current symbol the EA is running on. But how to get the total profit for all the position opened by the EA ?

Thanks.

Hello blouf, if you want to receive a "notification" for the current topic, an option would be to mark it as favorite (select the yellow star at the right side of the topic name). Once any answer is added to the topic a yellow star will apear at the upper part of the MQL5.com website after you've logged in.

Regarding your question, an approach to compute the total EA profit (as a function of the EA Magic Number) would be:

double total_EA_profit(long _EA_Magic)
{
datetime start   = 0;
datetime end     = TimeCurrent();
HistorySelect(start,end);
int deals_total = HistoryDealsTotal();
double deal_result = 0;
double cum_result = 0;
for(int i=0;i<deals_total;i++)
{
if(HistoryDealGetInteger(HistoryDealGetTicket(HistoryDealsTotal()-i),DEAL_MAGIC)==_EA_Magic)
{
if(HistoryDealGetInteger(HistoryDealGetTicket(HistoryDealsTotal()-i),DEAL_ENTRY)==DEAL_ENTRY_OUT || HistoryDealGetInteger(HistoryDealGetTicket(HistoryDealsTotal()-i),DEAL_ENTRY)==DEAL_ENTRY_INOUT)
{
deal_result = HistoryDealGetDouble(HistoryDealGetTicket(HistoryDealsTotal()-i),DEAL_PROFIT);
cum_result += deal_result;
}
}
};
return cum_result;
};
10284

Malacarne:

Hello blouf, if you want to receive a "notification" for the current topic, an option would be to mark it as favorite (select the yellow star at the right side of the topic name). Once any answer is added to the topic a yellow star will apear at the upper part of the MQL5.com website after you've logged in.

Regarding your question, an approach to compute the total EA profit (as a function of the EA Magic Number) would be:

Thanks very much. I'll give a try. I believed the magic number was only for MT4 EA
2806

Add per profit,what is total profit.

code like,

for(...)

profittotal+=profit;