Print 5 Decimal place

 

hello,

how to get 5 decimal places because when i used OrderClosePrice() it will round off to 4 decimal only but broker is 5 decimal.

thank you

 
you can use NormalizeDouble(numer,digits) function
 
DanSoah:
you can use NormalizeDouble(numer,digits) function

i think there are no 5 decimal because double only 4 decimal.

for example:

double value=StrToDouble("1.2345678");
Print(value);

// output: 1.2346


just found it.

 

Double can store values to the 15th digit at least... tbh i don't know what's the accuracy of double beyond 15th digit. It's iffy at 15 digits anyway and it's highly probable you don't need more digits for financial math.

Floating-point constants can assume values from -1.7 * e-308 to 1.7 * e308. If a constant exceeds this range, the result is undefined.

However the Print() function normalizes double value to 4 decimal places by default. Always use Print in conjuction with NormalizeDouble(X, Digits). Or any string operation that involves doubles for that matter.

 
fdoehpp:
how to get 5 decimal places because when i used OrderClosePrice() it will round off to 4 decimal only but broker is 5 decimal.
OCP() returns a double, infinite decimal places. You only see 4 digits when you print()/alert()/comment(). You must use doubleToStr to keep the last digit
string  PriceToStr(double p){ return( DoubleToStr(p, Digits) ); }
NormalizeDouble will NOT work. OCP() is already normalized to 5 digits, normalizing it again changes nothing, and printing it still drops to 4 digits. I've never found a single reason to ever use normalize.
 
WHRoeder:
I've never found a single reason to ever use normalize.

I use NormalizeDouble when I'm calculating position sizes in order to truncate everything after the first decimal place. Is this not necessary?
 
I use normalizeDouble to clear the "double inaccuracies" when using double variables as prices to be used for entering,exiting, sl or tp and volume. That's it.
 
Anomalous:

I use NormalizeDouble when I'm calculating position sizes in order to truncate everything after the first decimal place. Is this not necessary?
No it will not work. You are assuming that lot step is 0.1. Any other broker defined step size (like 0.2) will not work. You must use
    double lotStep         = MarketInfo(Symbol(), MODE_LOTSTEP),   //IBFX= 0.01
    double size=MathCeil(lotsNew/lotStep)*lotStep;
 
forexCoder:
I use normalizeDouble to clear the "double inaccuracies" when using double variables as prices to be used for entering,exiting, sl or tp and volume. That's it.
Not necessary as long as you do not violate one of the broker boundaries
double  minGapStop  = MarketInfo(Symbol(), MODE_STOPLEVEL)*Point,
/* If the current price is closer than this to the TP, SL, (or pending
 * price,) then the existing order can not be modified, closed, or deleted.
 * On IBFX it's equal to zero (in tester,) but I still can't change it if
 * market is closer than minGapStop either. */

SetStops(oo.SL, oo.TP, size, oo.price);
if (oo.TP != TPorig){                   // Handle TP
    double  TPmin = now.close +DIR* minGapStop;
    if ((oo.TP-TPmin)*DIR < 0){         // Below min?
        oo.TP = TPmin;                  // Can't.
    if ((TPorig != 0) && (oo.TP-TPorig)*DIR < Point)
        oo.TP = TPorig;                 // TP up only.
}...