![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
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
NormalizeDouble() can be viewed as equivalent to the Math.Round(number, digits) found in many languages, and thus has legitimate uses.
I'd say that the number of instruments whose tick-size is not a multiple of 10 is now decreasing, not increasing. For example, lots of brokers used to have S&P contracts which moved in increments of 0.25, like the CME e-mini contract. But I now can't immediately think of a broker whose S&P contract isn't priced in increments of 0.01 like the underlying index.
You explained it correctly by using the term "round", instead of "normalise". Independently of the fact that tick-size is mostly a multiple or factor of 10, it still is not an excuse, because as long as there is one such case where it is not, the use of NormalizeDouble fails.
If the correct solution, of which I gave one example, is valid for ALL cases, why then persist with a so called solution that does not.
In other trading languages, such as NinjaTrader or others, they have perpetuated the correct usage by offering functions that "Normalise" by aligning or rounding the prices based on tick-size. Only MetaTrader (with all its non-standard quirks) seems to think that it is better to "normalise" based on number of digits.
For the simple fact, that no other language has a NormaliseDouble function. It was only created due to "bad" design by the initial versions of MetaTrader which was initially designed only for Forex market.
That "bad" design has since been corrected, but the bad habit of its continued use is due to the persistent usage by fellow coders and due to MetaQuotes not removing it for good from the system.
MT5 has now extended its use to non-forex markets where the correct tick size alignment is much more important than ever before.
In all my code I don't use it at all and all prices are aligned by tick size and all volumes are aligned by lot step, and not once do I get any errors due to not using NormalizeDouble.
Defending its use is only making it more difficult for newbie coders to understand the correct way to set the price and adding to the confusion. Please don't defend its use.
Just because it exists, does not mean its usage is valid or correct. MetaTrader and MQL have many failings and this is one of them. So, defending these faults, does not help anyone.
You missed my point I think. Are you really thinking someone, which most of the time is a beginner in programming, can deduce all of that reading your sentence ?
Don't use NormalizeDouble(). It is a kludge! It is useless! If you do things correctly, you don't need it!
In short, NormalizeDouble() does nothing useful at all, and what does solve the problem is making sure the price is a aligned to the symbol's tick size.
So my point is : either give the solution and that's all, or explain it (or post a link where it's explained) correctly. The above sentence is useless, it's kludge, explain things correctly. We don't need slogan.
The function exists, it can be used when it's appropriate, and that's what you should explain to people wanting to learn. Nothing is black or white, nothing is good or bad in programming. I don't defend it's use or not, I defend scientific thinking, I am against any "binary thinking" (I hope it's clear what I mean).
If the correct solution, of which I gave one example, is valid for ALL cases, why then persist with a so called solution that does not.
The part where I agree with Alain's sentiment is that if one (not you) is going to copy and paste the same thing 5 times per day, at least make it truly informative without needing to click through 5 layers of hyperlinks and wade through pages of old topics.
For example, instead of "Don't use NormalizeDouble()" or "NormalizeDouble() is a kludge", copy-and-paste something which is more helpful such as "You are assuming that all symbols have prices with a minimum price movement which is a power of 10, such as 0.001 or 0.00001. This is not necessarily the case. Some symbols move in increments such as 0.5 or 0.25. As a result, NormalizeDouble() is not always a safe way of rounding prices".
In other trading languages, such as NinjaTrader or others, they have perpetuated the correct usage [...]
Having added classes into the MQL language, I have no idea why MQL still has kludges such as SymbolInfoInteger(), SymbolInfoDouble() etc rather than access to a collection of some sort of Symbol object which has members such as RoundPrice() and RoundLotSize().
Given the existence of classes in the language, I'd expect the platform framework to use them itself. For example:
True but irrelevant. Prices must be normalized to tick size, not point. Lots must be normalized to lot step which may not be a power of 10. It fails here when tick size is not point and/or brokers can change lot step.
That's not exact. Actually the problem in this topic is not about NormalizeDouble() but because the OP hardcoded 5 as a number of digits. Are you thinking it will understand that with "slogan" and dozens of links ?
The only one explaining it correctly is JC, and he used NormalizeDouble(). I am sure his post is more useful than any other one here to beginners.
The above sentence is useless, it's kludge, explain things correctly. We don't need slogan.
(That's exactly where we have just agreed.)
The part where I agree with Alain's sentiment is that if one (not you) is going to copy and paste the same thing 5 times per day, at least make it truly informative without needing to click through 5 layers of hyperlinks and wade through pages of old topics.
...
May I ask you which part you disagree ? Seems to me we are saying the same thing.
You missed my point I think. Are you really thinking someone, which most of the time is a beginner in programming, can deduce all of that reading your sentence ?
So my point is : either give the solution and that's all, or explain it (or post a link where it's explained) correctly. The above sentence is useless, it's kludge, explain things correctly. We don't need slogan.
The function exists, it can be used when it's appropriate, and that's what you should explain to people wanting to learn. Nothing is black or white, nothing is good or bad in programming. I don't defend it's use or not, I defend scientific thinking, I am against any "binary thinking" (I hope it's clear what I mean).
For example, instead of "Don't use NormalizeDouble()" or "NormalizeDouble() is a kludge", copy-and-paste something which is more helpful such as "You are assuming that all symbols have prices with a minimum price movement which is a power of 10, such as 0.001 or 0.00001. This is not necessarily the case. Some symbols move in increments such as 0.5 or 0.25. As a result, NormalizeDouble() is not always a safe way of rounding prices".
Having added classes into the MQL language, I have no idea why MQL still has kludges such as SymbolInfoInteger(), SymbolInfoDouble() etc rather than access to a collection of some sort of Symbol object which has members such as RoundPrice() and RoundLotSize().
Given the existence of classes in the language, I'd expect the platform framework to use them itself. For example:
Why should it be expected of me or any other user, that states that using NormalizeDouble is incorrect or not appropriate, to have to give a long winded History Lesson and a long winded Coding Lesson and a long winded Trading Lesson, when MetaQuotes themselves are perpetuating the incorrect usage.
I learned the correct way by my own knowledge, by my own research. No one taught me! I read the documentation, I read books, I looked at example code and in all of this incorrect usages, I came to my own conclusion that it was wrong based on my previous coding knowledge and experience. That took time and money. My only responsibility is to call others to take note of this incorrect usage and even provided an example of the correct way.
If the user does not understand, then he has the option of either using it blindly (in the same way that he is using NormalizaDouble blindly without really understanding it either), or he can go dedicate some time and effort into researching the subject on his own and coming to his own conclusion as I did.
EDIT: This will be the last time I will tell anyone to use proper tick-size or lot-step alignment. I am fed-up with being constantly called upon this. If you wish to help MetaQuotes perpetuate this "Idiocracy", then please be my guest!
May I ask you which part you disagree ? Seems to me we are saying the same thing.
I agree with Fernando and whroeder1 that it's rarely "correct" to use NormalizeDouble(), because the vast majority of uses are in relation to prices and lot sizes where the use isn't fully safe. It's helpful at some point to make this clear to people. But, given the realities of what all brokers' statistics say that 99.999% of people trade through MT4, it's usually a lower priority than addressing other issues. Like you said above, the key problem the OP had was hard-coding the price increment, not how they were rounding the price increment.
Telling people not to use NormalizeDouble(), in isolation, is mixing up a technical issue with a market-understanding issue. To appropriate a phrase from, er, elsewhere, it's "mixing apples and oranges".