Value from function 0.001 showing as 0 issue

 

I have this value from a function MAXVALUE(). the value is less then 0.004.

i need to show this value as it is; that is 0.004 and not 0 as it is currently shown. i've tried Normalize double and trying to multiple in the function then divide outside the function but the value is still 0. ideas?

double MV = NormalizeDouble((MaxValue()/100),_Digits);
 
12345abc22:

I have this value from a function MAXVALUE(). the value is less then 0.004.

i need to show this value as it is; that is 0.004 and not 0 as it is currently shown. i've tried Normalize double and trying to multiple in the function then divide outside the function but the value is still 0. ideas?

double MV = NormalizeDouble((MaxValue()/100),_Digits);

Why are you dividing by 100?

 
12345abc22:I have this value from a function MAXVALUE(). the value is less then 0.004. i need to show this value as it is; that is 0.004 and not 0 as it is currently shown. i've tried Normalize double and trying to multiple in the function then divide outside the function but the value is still 0. ideas?

Forum on trading, automated trading systems and testing trading strategies

Rare code issue

Fernando Carreiro, 2021.07.23 22:20

Please understand that dividing by 100 or dividing by 100.0 will give totally different results.

In the former, 100 is considered an Integer literal constant and so it will carry out integer division which will truncate the decimal values.

In the latter, 100.0 will be considered a floating-point literal constant and it will carry out floating-point division which will keep the decimal values.

This is the principal behind the problems you are having. So, to prevent this, either use a floating-point literal constant or typecast the variable into a (double).

Example:

Print( "90   / 100   = ", 90   / 100   );
Print( "90   / 100.0 = ", 90   / 100.0 );
Print( "90.0 / 100   = ", 90.0 / 100   );
Print( "90.0 / 100.0 = ", 90.0 / 100.0 );
2021.07.23 21:26:57.060 TestCopy EURUSD,H1: 90   / 100   = 0
2021.07.23 21:26:57.060 TestCopy EURUSD,H1: 90   / 100.0 = 0.9
2021.07.23 21:26:57.060 TestCopy EURUSD,H1: 90.0 / 100   = 0.9
2021.07.23 21:26:57.060 TestCopy EURUSD,H1: 90.0 / 100.0 = 0.9

Forum on trading, automated trading systems and testing trading strategies

MT4 forcing doubles into int

Fernando Carreiro, 2022.03.23 17:53

Typecast them into floating point — Typecasting - Data Types - Language Basics - MQL4 Reference

double Average = (double) Bars /          Found;
double Average =          Bars / (double) Found;
double Average = (double) Bars / (double) Found;