Download MetaTrader 5
To add comments, please log in or register
Trade with MetaTarder 5. Download it right now!
Elo
82
Elo 2014.02.10 01:10 

Hi guys,

I have this code in my indicator and I would like to get rounds the floating point values to the six digits for example -0.000092 as it is the value of the MACD indicator. The issue is that I get -0.0001. Could you help me how to fix this ?

double mMACD,mMACDSignal;
mMACD=iCustom(NULL,0,"#MTF_MACD",0,12,26,9,0,0,i);
mMACDSignal=iCustom(NULL,0,"#MTF_MACD",0,12,26,9,0,1,i);


Alert("-");
Alert("mMACD = ",mMACD," mMACDSignal = ",mMACDSignal);
Alert("-");

Fernando Carreiro
1502
Fernando Carreiro 2014.02.10 03:31  

Use the new "DoubleToString" function to convert the Double into a String of the precision you require (see example below).

Alert( "mMACD = ", DoubleToString( mMACD, Digits ), " mMACDSignal = ", DoubleToString( mMACDSignal, Digits ) );

This function was previously denoted as "DoubleToStr" in the previous builds, but use the new version for forward compatibility.

MQL5 Reference: https://www.mql5.com/en/docs/convert/doubletostring

Old MQL4 Reference: https://docs.mql4.com/convert/DoubleToStr

Elo
82
Elo 2014.02.10 23:39  
FMIC:

Use the new "DoubleToString" function to convert the Double into a String of the precision you require (see example below).

This function was previously denoted as "DoubleToStr" in the previous builds, but use the new version for forward compatibility.

MQL5 Reference: https://www.mql5.com/en/docs/convert/doubletostring

Old MQL4 Reference: https://docs.mql4.com/convert/DoubleToStr


Now it is fixed. Thank you very much!
Fernando Carreiro
1502
Fernando Carreiro 2014.02.11 08:38  
My pleasure! You are welcome!
/
To add comments, please log in or register