HistoryDealGetDouble(ticket, DEAL_PROFIT) always = 0.0?

Hung Dinh Van  

Hi all,

My funtion:

double ProfitCheck(long const magic_number)
{
   double profit=0.0;
   HistorySelect(0, TimeCurrent());
   int trades_total = HistoryDealsTotal();
   
   for(int i=0; i < trades_total; i++)
     {
      long ticket = HistoryDealGetTicket(i);
      long type   = HistoryDealGetInteger(ticket, DEAL_TYPE);

      //--- Initial deposit is not considered
      if((i == 0)&&(type == DEAL_TYPE_BALANCE)) continue;
      
      if((type != DEAL_TYPE_BUY)&&(type != DEAL_TYPE_SELL)) continue;

      if( magic_number != HistoryDealGetInteger(ticket, DEAL_MAGIC)) continue;

      //--- Calculation of profit
      Print(   "Ticket: "        + ticket + 
               " type: "         + type + 
               " DEAL_SYMBOL: "  + HistoryDealGetString(ticket,DEAL_SYMBOL) + 
               " DEAL_VOLUME: "  + HistoryDealGetDouble(ticket, DEAL_VOLUME) +
               " DEAL_PROFIT: "  + HistoryDealGetDouble(ticket, DEAL_PROFIT) +
               " DEAL_COMMISSION: " + HistoryDealGetDouble(ticket, DEAL_COMMISSION) +
               " DEAL_SWAP: "    + HistoryDealGetDouble(ticket, DEAL_SWAP));
      
      profit =+ HistoryDealGetDouble(ticket, DEAL_PROFIT) +
               HistoryDealGetDouble(ticket, DEAL_COMMISSION) +
               HistoryDealGetDouble(ticket, DEAL_SWAP);
               
     }
   return(profit);        
}

I backtest, but it's always =0.


Please help me!

Thanks!

Nguyen Nga  

remove it

 if((type != DEAL_TYPE_BUY)&&(type != DEAL_TYPE_SELL)) continue;
Hung Dinh Van  
Nguyen Nga:

remove it

Thanks! But it's not work

I want to calculate the total profit for all market deal.

Please help me!

HJaq86SNN8Ue2zzt  

It is very strange that the classes work differently when tested and run in production mode. All the same, we are operating here with money, and not something else.

Vladimir Karputov  
Hung Dinh Van :

Thanks! But it's not work

I want to calculate the total profit for all market deal.

Please help me!

You need to look for market exit trades (DEAl_ENTRY_INOUT and DEAL_ENTRY_OUT).

Reason: