Hello, I'm coding a basket indicator which alerts me when/if a pair from the list reaches a round number (000/500).
I've been able to obtain the last 3 digits from each pair as string (with StringLen and StringSubstr) but when i try to convert them to double or integer all the zeros got removed from the number, for example 015 becomes 15. I know this is supposed to be logical but i need those zero to be able to compare them with the round numbers.
I also tried with NormalizeDouble and StringFormat but nothing seems to work in my case. How can i make it work?
Also if somebody has a different solution to reach my goal i'm all ears :)
Thanks.
You don't need the zero to compare numbers
015==15 will be true.
You don't need the zero to compare numbers
015==15 will be true.
But the problem is that it also removes the zeros after, for example 0.98100 becomes 981 and that number can't be compared with a round number.
MT4:NormalizeDouble - General - MQL5 programming forum 2017.01.04
How to Normalize - Expert Advisors and Automated Trading - MQL5 programming forum 2017.05.19
I don't need to "roundup" prices, I just wanted to check when prices reach a round level like 1.90500 or 141.000.
Anyway i found a solution. I realized the problem is not happening when i convert from string to double/integer but simply MarketInfo(pair,MODE_BID) doesn't consider any zero after decimal numbers. For example now AUDCAD price is 0.98100 and if you Print its MarketInfo it just prints 0.981.
I find it a bit odd since those zeros can be used in a lot of different algorithm calculations. Maybe there is already a function to do that which i'm not aware.
Thanks anyway.
- www.mql5.com
Doubles are rarely equal. Understand the links in:
The == operand. - MQL4 programming forum #2 2013.06.07
Yep i realized that when i was testing the indicator, infact i changed the code and now i compare the price in a range of numbers. Rather than "==" im using "(>=0 && <020) || (<=999 && >=980)".
But rounding up before the target price seems a better choice, the problem is: how i decide when to round up the number before the comparing? Should i still wait the price to reach a range before rounding up?
If you can write a small example for me it would help me understand as i'm not a professional coder.
Cheers.
- www.mql5.com
Yep i realized that when i was testing the indicator, infact i changed the code and now i compare the price in a range of numbers. Rather than "==" im using "(>=0 && <020) || (<=999 && >=980)".
But rounding up before the target price seems a better choice, the problem is: how i decide when to round up the number before the comparing? Should i still wait the price to reach a range before rounding up?
If you can write a small example for me it would help me understand as i'm not a professional coder.
Cheers.
double x = round(price/rounding)*rounding;then compare it to your nearest level
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Hello, I'm coding a basket indicator which alerts me when/if a pair from the list reaches a round number (000/500).
I've been able to obtain the last 3 digits from each pair as string (with StringLen and StringSubstr) but when i try to convert them to double or integer all the zeros got removed from the number, for example 015 becomes 15. I know this is supposed to be logical but i need those zero to be able to compare them with the round numbers.
I also tried with NormalizeDouble and StringFormat but nothing seems to work in my case. How can i make it work?
Also if somebody has a different solution to reach my goal i'm all ears :)
Thanks.