MT5 update [build 3180] decimal input variable bug - page 3

 
Fernando Carreiro #:

No, NormalizeDouble seems to be working just as before with no change. It seems to be only a "display" problem. See my previous posts here on the thread, especially Post #17 .

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void  OnStart () {
//---
   Print ( "Normalize double test: ee = ",  NormalizeDouble ( 0.45678,  2 ));
   Print ( "Normalize double test: ee = ",  NormalizeDouble ( 1.45678,  2 ));   
} 
//+------------------------------------------------------------------+
My orders are sent on like 0.45678 so how can i fix that, I see it works if value above 1 maybe
 
Dark Ryd3r #: My orders are sent on like 0.45678 so how can i fix that, I see it works if value above 1 maybe

You should not be using "NormalizeDouble" to set the price nor the volume on orders placed. You should be adjusting the price to the "tick size" and the "lot step" for the volume for the symbol in question.

This has been discussed many times over on the forum, so if you do a search you should find many threads/topics about how to round or adjust them correctly.
 
Dark Ryd3r #:
My EA Stopped sending orders due to this bug, so i explored and found this. Its an issue with NormalizeDouble which output can be seen


The bug is your EA, you are treating doubles as if they were precise but they are not, you are not using them correctly and the NormalizeDouble function should not even exist.
Read the links I posted and start using floating points the right way.
 
Alexandre Borela #:
The bug is your EA, you are treating doubles as if they were precise but they are not, you are not using them correctly and the NormalizeDouble function should not even exist.
Read the links I posted and start using floating points the right way.

My EA does not work on tick price and it does not recognize Bid Ask, it recognizes close price and trigger orders on that. so i am using NormalizeDouble

 double step_ = SymbolInfoDouble(_Symbol,SYMBOL_VOLUME_STEP);
  int digitsx = DigitsCount(step_);
   
   double dSize = NormalizeDouble(maxqty,digitsx);

int DigitsCount(double number)

{

   int digits = 0;

   while (NormalizeDouble(number, digits) != number) {
      digits +=1;
   }

   return digits;

}
 
Dark Ryd3r #: My EA does not work on tick price and it does not recognize Bid Ask, it recognizes close price and trigger orders on that. so i am using NormalizeDouble

Have a look at the final section of the code below, namely the section "Adjust Volume for allowable conditions". The same logic can be applied to prices and the "tick size".

Forum on trading, automated trading systems and testing trading strategies

How to calculate lots using multiplier according to number of opened orders?

Fernando Carreiro, 2017.09.01 21:57

Don't use NormalizeDouble(). Here is some guidance (code is untested, just serves as example):

// Variables for Symbol Volume Conditions
double
   dblLotsMinimum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MIN  ),
   dblLotsMaximum = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_MAX  ),
   dblLotsStep    = SymbolInfoDouble( _Symbol, SYMBOL_VOLUME_STEP );
   
// Variables for Geometric Progression
double
   dblGeoRatio = 2.8,
   dblGeoInit  = dblLotsMinimum;
   
// Calculate Next Geometric Element
double
   dblGeoNext  = dblGeoInit * pow( dblGeoRatio, intOrderCount + 1 );
   
// Adjust Volume for allowable conditions
double
   dblLotsNext = fmin( dblLotsMaximum,                                     // Prevent too greater volume
                   fmax( dblLotsMinimum,                                   // Prevent too smaller volume
                     round( dblGeoNext / dblLotsStep ) * dblLotsStep ) );  // Align to Step value

 
Fernando Carreiro #:

Have a look at the final section of the code below, namely the section " Adjust Volume for allowable conditions ". The same logic can be applied to prices and the "tick size".


thanks, I'll look
 
Dark Ryd3r #:

My EA does not work on tick price and it does not recognize Bid Ask, it recognizes close price and trigger orders on that. so i am using NormalizeDouble

That's not how you compare doubles, read this:

https://floating-point-gui.de/errors/comparison/


https://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html

 
Fernando Carreiro #:
You are using DoubleToString to the same number of digits, which cancels out any possible "bug" that NormalizeDouble may or may not have. Your test does not serve as a satisfactory evaluation of the situation.

Sorry. The former test code was wrong.

I just corrected it as:

void OnStart()
  {
//---
      double value = 0.29999999;
      double norm_val = NormalizeDouble(value, 2);
      
      Print("Not normalized: ", DoubleToString(value, 8));
      Print("Normalized: ", DoubleToString(norm_val, 8));   
  }
//+------------------------------------------------------------------+


 The output is:

2022.01.31 12:10:03.846 MyTest1 (EURUSD,H1)     Not normalized: 0.29999999

2022.01.31 12:10:03.846 MyTest1 (EURUSD,H1)     Normalized: 0.30000000
 
Dark Ryd3r #:
I confirm NormalizeDouble does not work and its an official bug and must be reported to ServiceDesk

Sorry, but your expectation of NormalizeDoulbe is wrong.

It changes a number only to the exponential value closest to the target value (x = a*e^b), but not to the target value if it cannot be represented by the mentioned formula.

To achieve this visually you have to use DoubleToString(), because this turns the internal representation a*e^b into a string of digits and a decimal point - but then you can't calculate with it any more.

 
I don't understand why people keep on discussing NormalizeDouble().
Unless I have misunderstood something, I don't see how it is related to this thread.