MT4:NormalizeDouble

 
NormalizeDouble(Close[0],0);


 

a simple question please:

in order to remove the digits after the .

how to get the integer value that will not be modified

I am getting 2 for values like 1.6 while I need

 

Use typecasting.

int nMy_Value = int(Close[0]);


Check this:

https://www.mql5.com/en/docs/basis/types/casting

Documentation on MQL5: Language Basics / Data Types / Typecasting
Documentation on MQL5: Language Basics / Data Types / Typecasting
  • www.mql5.com
Language Basics / Data Types / Typecasting - Reference on algorithmic/automated trading language for MetaTrader 5
 

maybe 

int y = (int) NormalizeDouble(Close[0],0);

 
  1. Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
  2. If you want the integer part of a double just cast it int y = int(d)
  3. If you want the nearest multiple of a double, (round numbers,) compute it.
    double MathNearest(  double v, double to){ return to * MathRound(v / to); }
    double MathRoundDown(double v, double to){ return to * MathFloor(v / to); }
    double MathRoundUp(  double v, double to){ return to * MathCeil( v / to); }
    :
    double   pip        = StringFind(_Symbol,"JPY") < 0 ? 0.01 : 0.0001;
    int      pipDigits  = (int)MathLog10(pip/_Point);
    int      slippage   = 3 * int(pip / _Point);

    double market    = Bid;                             // 1.012345 122.012
    double lower100  = MathRoundDown(market, 100*pip);  // 1.01200  122.00
    double upper100  = MathRoundUp(  market, 100*pip);  // 1.01300  123.00

 
Snelle Moda:

Use typecasting.

int nMy_Value = int(Close[0]);


Check this:

https://www.mql5.com/en/docs/basis/types/casting

whroeder1:

  1. If you want the integer part of a double just cast it int y = int(d)
  2. If you want the nearest multiple of a double, (round numbers,) compute it.

 

Thanks all for your help 

 

William Roeder #:

  1. Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong

Hello!

Thanks for this.

If instead of this:

double NormalizePrice(double p, string pair=""){
        // https://forum.mql4.com/43064#515262 zzuegg reports for non-currency DE30:
        // MarketInfo(chart.symbol,MODE_TICKSIZE) returns 0.5
        // MarketInfo(chart.symbol,MODE_DIGITS) return 1
        // Point = 0.1
        // Prices to open must be a multiple of ticksize 
    if (pair == "") pair = Symbol();
    double ts = MarketInfo(pair, MODE_TICKSIZE)
    return( MathRound(p/ts) * ts );

I use this:

double GetNormalised(double price)
  {
   return(StrToDouble(DoubleToStrMorePrecision(price,_Digits)));
  }

Or this :

double nNormalizePrice(double price)
  {
   return StrToDouble(StringSubstr(DoubleToStr(price),0,_Digits+2));
  }

The diference between the three of them, is that first two versions are rounding up last digit.

I tried to normalize 0.123456789 number.

First two versions if  apply to a 5 digit pair, will give result 0.12346, the last version will give 0.12345