calculate profit of last closed position

 

I want to calculate the profit of last closed position as it would by traded with 0.1 LOT, but have a problem with understanding the MQL5 concept. I try this code but it doesn't work, could somebody help, or refer to some code where is discused similar problem

bool CalculateOneLotProfit()
{  
   datetime end = TimeCurrent();
   datetime start=end-5*PeriodSeconds(PERIOD_D1);
   HistorySelect(start,end);
//--- obtain the number of deals in history
   int deals=HistoryDealsTotal();
   for (int i=0;i<deals;i++)
   { 
      ulong ticket=  HistoryDealGetTicket(i);  
      ENUM_DEAL_ENTRY entry_type=(ENUM_DEAL_ENTRY)HistoryDealGetInteger(ticket,DEAL_ENTRY);
      if(entry_type==DEAL_ENTRY_OUT)
      {
         profit = HistoryDealGetDouble(ticket,DEAL_PROFIT)/ (HistoryDealGetDouble(ticket,DEAL_VOLUME)*10);
         balanceOne = balanceOne+profit;
         printf("Profit: %f",profit);
         return true;
      }
   }
   return false;     
}

 

 

i looked at it i tried to work with it

but  mabey this will help

//---bool CalculateOneLotProfit()
     {
      datetime end=TimeCurrent();
      datetime start=end-5*PeriodSeconds(PERIOD_D1);
      HistorySelect(start,end);
      //--- obtain the number of deals in history
      int deals=HistoryDealsTotal();
      for(int i=0;i<deals;i++)
        {

         ulong ticket=HistoryDealGetTicket(i);

         ENUM_DEAL_ENTRY entry_type=(ENUM_DEAL_ENTRY)HistoryDealGetInteger(ticket,DEAL_ENTRY);
         if(HistoryDealGetInteger(ticket,DEAL_ENTRY)==DEAL_ENTRY_OUT)
           {
            double balanceOne;
            double profit=HistoryDealGetDouble(ticket,DEAL_PROFIT)/(HistoryDealGetDouble(ticket,DEAL_VOLUME)*10);
            balanceOne+=profit;
            printf("Profit: %f",profit);
            return true;
           }
        }
      return false;
     }

  }
 
gery18:

I want to calculate the profit of last closed position as it would by traded with 0.1 LOT, but have a problem with understanding the MQL5 concept. I try this code but it doesn't work, could somebody help, or refer to some code where is discused similar problem

 


sorry about the mix up with the other code i think this will help test it and get back to me
//---bool CalculateOneLotProfit()
     {
      datetime end=TimeCurrent();
      datetime start=end-5*PeriodSeconds(PERIOD_D1);
      HistorySelect(start,end);
      //--- obtain the number of deals in history
      int deals=HistoryDealsTotal();
      for(int i=0;i<deals;i++)
        {

         ulong ticket=HistoryDealGetTicket(i);

         ENUM_DEAL_ENTRY entry_type=(ENUM_DEAL_ENTRY)HistoryDealGetInteger(ticket,DEAL_ENTRY);
         if(entry_type==DEAL_ENTRY_OUT)
           {
            double balanceOne;
            balanceOne+=(HistoryDealGetDouble(ticket,DEAL_PROFIT)/(HistoryDealGetDouble(ticket,DEAL_VOLUME)*10));
            printf("Profit: %f",balanceOne);//profit);
            //printf(entry_type==DEAL_ENTRY_OUT);
            return true;
           }
           printf(entry_type==DEAL_ENTRY_OUT);
           return false;
        }
      //return false;
     }

sorry about that have to take out the printf(entry_type==DEAL_ENTRY_OUT);

but i think this is what you want hope this helped 

 
I have solved my problem, I used global variable and managed it also in another functions, basic programing error, thank you
Reason: