-nan export

 

I'm getting an exported value of "-nan" to a csv file . I noticed that division by zero on mt5 produces "inf" . What is producing -nan ? if anyone has encountered it of course.

MT5 , not an indicator , not working with reading data live , data is picked up from the hard drive for processing .

Thank you

 
Lorentzos Roussos:I'm getting an exported value of "-nan" to a csv file . I noticed that division by zero on mt5 produces "inf" . What is producing -nan ? if anyone has encountered it of course. MT5 , not an indicator , not working with reading data live , data is picked up from the hard drive for processing .

One example would be "sqrt(-1)" which will give you a "-nan".

Print( sqrt(-1) );
EDIT: The square root of any negative number.
 

For an example of "nan" ...

double zero = 0;
Print( zero/zero );
 
Fernando Carreiro #:

For an example of "nan" ...

Thanks . I assume this spreads to what it touches afterwards , if a variable ,because a big portion of the csv is toast

 
Lorentzos Roussos #: Thanks . I assume this spreads to what it touches afterwards , if a variable ,because a big portion of the csv is toast

Yes, you will have to put some checks in place to prevent it.

 

It's defined in the IEEE754 Standard.

https://en.wikipedia.org/wiki/NaN

 
Fernando Carreiro #:

Yes, you will have to put some checks in place to prevent it.

Yeah , this is the only sqrt i have so i think if the numbers become really really small (not here but down the "process") and they get divided i'll hit a nan ... i assume.

Alain Verleyen #:

It's defined in the IEEE754 Standard.

https://en.wikipedia.org/wiki/NaN

Thanks , where have you been ? I still haven't passed your rating dam it.  😂

 

Also i guess MathMin can be used to "filter" these out

  double zero=0.0;
  double nan=zero/zero;
  double inf=3.22/zero;
  double neg_nan=MathSqrt(-1.0);
  double positive=1.23;
  double negative=-1.00*((double)INT_MAX);
  Print("MathMax(inf,"+positive+")="+MathMax(inf,positive));
  Print("MathMin(inf,"+positive+")="+MathMin(inf,positive));
  Print("MathMax(inf,nan)="+MathMax(inf,nan));
  Print("MathMin(inf,nan)="+MathMin(inf,nan));
  Print("MathMax(inf,-nan)="+MathMax(inf,neg_nan));
  Print("MathMin(inf,-nan)="+MathMin(inf,neg_nan));
  Print("MathMax(nan,-nan)="+MathMax(nan,neg_nan));
  Print("MathMin(nan,-nan)="+MathMin(nan,neg_nan));
  Print("MathMax(nan,"+positive+")="+MathMax(nan,positive));
  Print("MathMin(nan,"+positive+")="+MathMin(nan,positive));  
  Print("MathMax(-nan,"+positive+")="+MathMax(neg_nan,positive));
  Print("MathMin(-nan,"+positive+")="+MathMin(neg_nan,positive));    
  Print("MathMax(nan,"+negative+")="+MathMax(nan,negative));
  Print("MathMin(nan,"+negative+")="+MathMin(nan,negative));  
  Print("MathMax(-nan,"+negative+")="+MathMax(neg_nan,negative));
  Print("MathMin(-nan,"+negative+")="+MathMin(neg_nan,negative));  
 
Lorentzos Roussos #: Yeah , this is the only sqrt i have so i think if the numbers become really really small (not here but down the "process") and they get divided i'll hit a nan ... i assume.

Then only divide if "MathSqrt(std_x)*MathSqrt(std_y)" is greater than zero. 

Also a "log()" of a negative number will also give a "-nan".

 
Fernando Carreiro #:

Then only divide if "MathSqrt(std_x)*MathSqrt(std_y)" is greater than zero.

Also a "log()" of a negative number will also give a "-nan".

ow , i'm not checking if the covariance is 0.0 , good point . 

That must be it , and it indicates many correlations were 0.0 which indicates they may have no data :P
 
Lorentzos Roussos #: ow , i'm not checking if the covariance is 0.0 , good point . 

Or use ...

correlation = covariance / MathMax( MathSqrt( std_x ) * MathSqrt( std_y ), DBL_EPSILON );
Reason: