Download MetaTrader 5
To add comments, please log in or register
All activity at MQL5.community is clearly visible. Have a look at the Wall!
Johnny Trainer
78
Johnny Trainer 2015.10.14 05:08 

i am dealing with very low values, like: 0.0000001 vs -0.0000001.

in comparison with zero the compiler seems to be confused.

is there any way to detect precisely (and not by comparison with zero) - which number is positive and negative.

it may sound stupid... still, it is not... please help !

regards 

Osama Shaban
1385
Osama Shaban 2015.10.14 12:00  
Calin Trainer:

i am dealing with very low values, like: 0.0000001 vs -0.0000001.

in comparison with zero the compiler seems to be confused.

is there any way to detect precisely (and not by comparison with zero) - which number is positive and negative.

it may sound stupid... still, it is not... please help !

regards 

I believe this must work ...

if your number is a, define it a as double, Not Integer (int). 

then, 

string result = "Neutral";

if(a>0)
   result = "Positive";

if(a<0)
   result = "Negative";

Marco vd Heijden
Moderator
4505
Marco vd Heijden 2015.10.14 12:31  
he said, and not by comparison with zero.
Stuart Browne
5718
Stuart Browne 2015.10.14 12:37  
You could try normalizing it on say a 0 to 100 scale, then comparing to the medium value ( in this case 50)
Snelle Moda
601
Snelle Moda 2015.10.14 13:08  

You can also try to use a string value to detect the negative numbers and use the "-" negative sign symbol for detection.

For example, this code uses the StringSubstr(); function to select the first symbol in the string and uses it for a reference. 

double dMyAlmostZeroValue = 0;

{

// Your code.
dMyAlmostZeroValue = -0.0000001;
}

string sTextValue = dMyAlmostZeroValue;  
sTextValue  = StringSubstr(sTextValue , 0, 1); // First symbol in the string.

if(sTextValue == "-" )
      {
      Alert("Value is negative");
      }

Snelle Moda
601
Snelle Moda 2015.10.14 15:30  

Your quote is: "in comparison with zero the compiler seems to be confused"

A "double" type variable has 15 significant digits. The compiler should be able to detect if a very small number (close to zero) is positive or negative.

-0.0000001 has only 7 digits.

https://www.mql5.com/en/docs/basis/types/double


Which variable type do you use?

Documentation on MQL5: Language Basics / Data Types / Real Types (double, float)
Documentation on MQL5: Language Basics / Data Types / Real Types (double, float)
  • www.mql5.com
Language Basics / Data Types / Real Types (double, float) - Reference on algorithmic/automated trading language for MetaTrader 5
Johnny Trainer
78
Johnny Trainer 2015.10.14 16:10  

i have them defined as doubles.

i like the idea with string (-) detection... but, really ?!!?! 

Johnny Trainer
78
Johnny Trainer 2015.10.14 16:13  
snelle_moda:

Your quote is: "in comparison with zero the compiler seems to be confused"

A "double" type variable has 15 significant digits. The compiler should be able to detect if a very small number (close to zero) is positive or negative.

-0.0000001 has only 7 digits.

https://www.mql5.com/en/docs/basis/types/double


Which variable type do you use?

you seem to have had a tough confrontation with this issue before (correct?)... two posts with two good ideas.

i have them as doubles and they are not recognized vs 0 comparison. 

 

thank you sir. 

Snelle Moda
601
Snelle Moda 2015.10.14 16:39  

A different simple solution is multiply your small number with a large number. 

Then the number of digits is smaller.

For example

-0.0000001 X 1.000.000 = -0.1

Now you can compare this number with zero as mentioned in the second post.

Johnny Trainer
78
Johnny Trainer 2015.10.14 18:34  
snelle_moda:

A different simple solution is multiply your small number with a large number. 

Then the number of digits is smaller.

For example

-0.0000001 X 1.000.000 = -0.1

Now you can compare this number with zero as mentioned in the second post.

that i done. not sure if works well... 

 

it is smthing like: if (MAArray[1]*1000000 >0){bla}

Alain Verleyen
Moderator
30295
Alain Verleyen 2015.10.15 08:44  
Calin Trainer:

you seem to have had a tough confrontation with this issue before (correct?)... two posts with two good ideas.

i have them as doubles and they are not recognized vs 0 comparison. 

 

thank you sir. 

Fix your code. The compiler doesn't have any problem with positive/negative number, all these "solutions" are useless.
/ /12
To add comments, please log in or register