Automatic rounding of double MT5

cmarconetti  

MT5 question, EA.

Hi,

Could not find a direct anwer to this strange issue.

I am simply setting-->   input double TP_Percent = 0.02; ---> in the input section of the code.

For some reason (TP_Percent is never changed in the code) when I call this variable for the first time it is transformed to 0.1 (!?). (I checked it with

a stop watch running a historical backtest)...

Is this a bug, is this some setting/rouding I overlooked?

Thank you in advance.

Fernando Carreiro  
cmarconetti: MT5 question, EA. Hi, Could not find a direct anwer to this strange issue. I am simply setting-->   input double TP_Percent = 0.02; ---> in the input section of the code. For some reason (TP_Percent is never changed in the code) when I call this variable for the first time it is transformed to 0.1 (!?). (I checked it with a stop watch running a historical backtest)... Is this a bug, is this some setting/rouding I overlooked?

When running in the tester, these values are set and saved in the Inputs section of the Strategy Tester. Verify that you are not setting it to 0.1 there.

cmarconetti  
Indeed, that was it. Thanks Fernando, always fast and reliable.
Fernando Carreiro  
cmarconetti #: Indeed, that was it. Thanks Fernando, always fast and reliable.
You are welcome!
Stephan Engberts  

I standard have a function, which uses 2 items as input from the user and after that, responds with the proper buy-in.

Input rules:

input double base_lot = 0.01;
input bool use_equity_lot = true;
input double equity_per_001 = 150;


Entry will be something like this:

ExtTrade.Buy(getAmountLots(),_Symbol,0.0,sl,tp);


Function to call:

double getAmountLots() {
   double div = base_lot;
   if (use_equity_lot) {
      double account_eq = AccountInfoDouble(ACCOUNT_EQUITY) / 100;
      div = account_eq / equity_per_001;
      if (div < 0.01) { div = 0.01; }
      div = NormalizeDouble(div, 2);
   }
   return div;
}
Reason: