Use typecasting.
int nMy_Value = int(Close[0]);
Check this:
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);
- Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
- Lot size must also be adjusted to a multiple of LotStep. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
- If
you want the integer part of a double just cast it int y = int(d)
- 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:
whroeder1:
-
- If
you want the integer part of a double just cast it int y = int(d)
- If you want the nearest multiple of a double, (round numbers,) compute it.
Thanks all for your help
William Roeder #:
- Do NOT use NormalizeDouble, EVER. For ANY Reason. It's a kludge, don't use it. It's use is always wrong
- SL/TP (stops) need to be normalized to tick size (not Point.) (On 5Digit Broker Stops are only allowed to be placed on full pip values. How to find out in mql? - MQL4 forum) and abide by the limits Requirements and Limitations in Making Trades - Appendixes - MQL4 Tutorial and that requires understanding floating point equality Can price != price ? - MQL4 forum
- Open price for pending orders need to be adjusted. On Currencies, Point == TickSize, so you will get the same answer, but it won't work on Metals. So do it right: Trailing Bar Entry EA - MQL4 forum or Bid/Ask: (No Need) to use NormalizeDouble in OrderSend - MQL4 forum
- Lot size must also be adjusted to a multiple of LotStep. If that is not a power of 1/10 then NormalizeDouble is wrong. Do it right.
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
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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 1