
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
Wish you were right and it was that simple. I wouldn't be here if it was that easy and definitely not wasting so many work hours on this.
It is true that I need to:
1. control the number of digits after decimal point
2. dynamically adjust the number of digits and make it as short as possible
My doubles come from
Tickvalue -> SYMBOL_TRADE_TICK_VALUE
TickSize -> SYMBOL_TRADE_TICK_SIZE
and
LotValue = ((TickValue / TickSize) * lot);
Nothing strange, standard values, all good, but LotValue seems to be hard to format and show on screen.
The BIG issue is that my Doubles show as 1.000000000 but they are actually 1.000000001
(I know how doubles work, and understand that it is normal)
Print(), DoubleToString(), NormalizeDoubles() and StringFormat() basically rounds the number and the resulting number is terribly wrong; nothing worked, the desired precision was simply not achievable with build in MQL4 functions because they round the number, and 1.000000000 ended up equal to 1.1
(can't think of any circumstance where it is convenient for an application that constantly shows Prices to see a 'faked' number transformed from 1.04966 to 1.0497 but that is a discussion for another day)
That is why at first I was using a simple formula to get my desired precision
But the thing complicates when instead of Forex, is Crypto where I need a higher precision of 9-10, and above that I was not able to remove trailing zeros, so I reached your functions.
And all this trouble because I need to output to the user as much information as possible and screen space is limited, so that is why I need to squeeze the number in a fixed space.
Your function Trunc() does the trick for 99.9% of the numbers, but there are some that fail to cooperate and need a special treatment.
I was hoping you could give a reduced formula to do it.
And now adding to my troubles the function Round(double, int) stops MT4 execution with some doubles. Can't figure out why, the double is not that big, being 100000.0000000000
It is a common number representing the value of 1 Lot for EURUSD, and if I hand write the value everything is ok, but if it comes from the math LotValue = ((TickValue / TickSize) * lot); MT4 blocks.
Such a simple task and I already spent 40+ hours on this. It is killing me!!
It is true that I need to:
1. control the number of digits after decimal point
2. dynamically adjust the number of digits and make it as short as possible
It seems that after 4 messages I wasn't able to make you understand my problem, and I feel terribly disappointed of my failure.
And the stylizer on this site is completely bugged, so it is very time consuming to properly write a message here
I can't explain why, but we must assume that 1.000000000; has a decimal other than 0 somewhere, although graphically I was not able to output it.
But the results are that:
for numbers like 19.65400
works perfectly. And if I manually input 1.0000000; it will still work perfectly.
Just so you understand me, I use the function on more than 400 different parameters and each of them has a different value on each tick and Trunc() works perfectly.
But for:
double lotValue = ((_TickValue / _TickSize) * lot);
it doesn't, and that is why I also included the function Round(number, digits); and it used to do the trick, and I decided to simply ask you if there was a formula to combine my function Normalize_Double_ToString() into a simpler and more optimized code.
And you answered me something very very different (I assume that it is entirely my fault for not explaining properly)
But since yesterday Round() blocks MT4, and without Round I can't properly count Significant Digits on the decimals side.
The problem seems to be the typecasting to long. If I remove it from Round(double, int); MT4 executes without problem, but then I can't figure out how a double with 6 integer digits, multiplied by 10000, reaches the limits of long.
I guess at this point my question is:
Where is the exit??
Anyway I will have to let this go, will get back to it in a few weeks.
Try this:
however, it won't do much better than the 3 shorter methods in the previous post.
Note,
I use Round() from my library, not the wrong one you posted before, or instead use:
n = NormalizeDouble(n, d);
But, I doubt what you've said that Round() has errors.It seems that after 4 messages I wasn't able to make you understand my problem, and I feel terribly disappointed of my failure.
And the stylizer on this site is completely bugged, so it is very time consuming to properly write a message here
I can't explain why, but we must assume that 1.000000000; has a decimal other than 0 somewhere, although graphically I was not able to output it.
I am sure that I understand the cause of your problems on MT4.
The main reason that you cannot get expected results is a bug with MQL4's string(dbl) that is still not fixed on MT4.
Bug in MQL4 string() function. Wrong conversion of double -> string.
The bug was fixed on MT5, but not on MT4. see here: https://www.mql5.com/en/forum/367839/page3#comment_27477157 and the fix here: https://www.mql5.com/en/forum/367839/page5#comment_27613205
My recommendation:
if you want to dig deeper or debug your doubles as string in MT4, then always force explicit cast to string via the Repr() function from math_utils.mqh