[Resolved] MathRound overload misbehaving with doubles

 

Hi,

All the variables bellow are doubles, I'm accumulating them summing with other doubles like:

profit = (double)HistoryDealGetDouble(deal_ticket, DEAL_PROFIT);

but in the end, when trying to do a`MathRound`, simple as this, it returns error:

withdrawn_sum = MathRound(withdrawn_sum, 2);

Error:

'MathRound' - no one of the overloads can be applied to the function call

According to the documentation, It should work:


Whole Code:

   double profit_sum = 0.0;
   double swap_sum = 0.0;
   double commission_sum = 0.0;
   double deposit_sum = 0.0;
   double withdrawn_sum = 0.0;

   HistorySelect(from_date,to_date);

   int deals = HistoryDealsTotal();
   
   for(int i=0; i < deals; i++){
      deal_ticket = HistoryDealGetTicket(i);
      if(deal_ticket){
         deal_type = (ENUM_DEAL_TYPE)HistoryDealGetInteger(deal_ticket, DEAL_TYPE);
         
         // Skip deposits and withdraws
         if(deal_type == DEAL_TYPE_BUY || deal_type == DEAL_TYPE_SELL){
         
            profit = HistoryDealGetDouble(deal_ticket, DEAL_PROFIT);
            swap = HistoryDealGetDouble(deal_ticket, DEAL_SWAP);
            comission = HistoryDealGetDouble(deal_ticket, DEAL_COMMISSION);
            
            profit_sum += profit;
            swap_sum += swap;
            commission_sum += comission;

         } else if(deal_type == DEAL_TYPE_BALANCE){
            profit = (double)HistoryDealGetDouble(deal_ticket, DEAL_PROFIT);
            
            if (profit < 0)
               withdrawn_sum += profit;
               
            else if(profit > 0)
               deposit_sum += profit;

         }
      }
   }
   
   withdrawn_sum = MathRound(withdrawn_sum, 2);
   deposit_sum = MathRound(deposit_sum, 2);
   profit_sum = MathRound(profit_sum, 2);
   swap_sum = MathRound(swap_sum, 2);
   commission_sum = MathRound(commission_sum, 2);


Removing the ending MathRound, the variables are printed correctly, so they are being filled:


 
Rafael Alfredo Capucho:

Hi,

All the variables bellow are doubles, I'm accumulating them summing with other doubles like:

but in the end, when trying to do a`MathRound`, simple as this, it returns error:

Error:

According to the documentation, It should work:


Whole Code:


Removing the ending MathRound, the variables are printed correctly, so they are being filled:


You are referring to the wrong function.

This is what you are actually calling, while you are trying to use the documentation for standard library...



 

I got it sorted,

Looks like that I needed to import this library, probably because they decided to have 2 totally different functions with the same name hehe, so it doesn't complain about a missing import

#include <Math/Stat/Math.mqh>

Thanks!

Edit: Thanks Dominik, for clarifying it.

Dominik Egert
Dominik Egert
  • 2024.01.28
  • www.mql5.com
Trader's profile