Fixing decimals to 5 digits in outputds

 

friends,


When I use Comment(text) where text is defined as string, I get 8 digits decimal output for H3,L3 and pips value as 1.69451000 on mt4 screen in place of 5 digits decimal 1.69451 I want to exclude the zeros.

Any solution to get output with 5 digits

sunil


int start()
  {
   int    counted_bars=IndicatorCounted();
 string text ="";
 double range = iATR(NULL, PERIOD_D1, 14, 1);
 int pips;



pips=range*10000;
if(range<0.01000)
text = "TODAY TRADING NOT ADVISABLE\n";
else
text = "TRADING ALLOWED TODAY\n";

text=   text +
       " RESISTANCE LINE = "+H3+"      14 DAYS AVR RANGE = "+pips+"   SUPPORT LINE = "+L3;
Comment(text);
 
Use DoubleToStr( double, Digits) to convert your double to a string and use that with Comment
 
RaptorUK:
Use DoubleToStr( double, Digits) to convert your double to a string and use that with Comment

Thank you Now it is working with 5 digits ouput when I used DoubleToStr

sunil

 
string PriceToStr(double p){ return( DoubleToStr(p, Digits); }
string DeltaToPoints(double p){ return( DoubleToStr(p/Point(), Digits); }
Or variations from my code:
//++++ These are adjusted for 5 digit brokers.
int     pips2points;    // slippage  3 pips    3=points    30=points
double  pips2dbl;       // Stoploss 15 pips    0.015      0.0150
int     Digits.pips;    // DoubleToStr(dbl/pips2dbl, Digits.pips)
int     init(){                                                     OptParameters();
     if (Digits % 2 == 1){      // DE30=1/JPY=3/EURUSD=5 https://www.mql5.com/en/forum/135345
                pips2dbl    = Point*10; pips2points = 10;   Digits.pips = 1;
    } else {    pips2dbl    = Point;    pips2points =  1;   Digits.pips = 0; }
    // OrderSend(... Slippage.Pips * pips2points, Bid - StopLossPips * pips2dbl
//---- These are adjusted for 5 digit brokers.
    /* On ECN brokers you must open first and THEN set stops
    int ticket = OrderSend(..., 0,0,...)
    if (ticket < 0)
       Alert("OrderSend failed: ", GetLastError());
    else if (!OrderSelect(ticket, SELECT_BY_TICKET))
       Alert("OrderSelect failed: ", GetLastError());
    else if (!OrderModify(OrderTicket(), OrderOpenPrice(), SL, TP, 0)
       Alert("OrderModify failed: ", GetLastError());
     */
    :
}
string  PriceToStr(double p){
    string pFrc = DoubleToStr(p, Digits);       if(Digits.pips==0) return(pFrc);
    string pPip = DoubleToStr(p, Digits-1);
    if (pPip+"0" == pFrc)       return(pPip);           return(pFrc);          }
string  DeltaToPips(double d){
    if (d > 0)  string sign = "+";  else    sign = "";
    double pips = d / pips2dbl;
    string dPip = sign + DoubleToStr(pips, 0);  if(Digits.pips==0) return(dPip);
    string dFrc = sign + DoubleToStr(pips, Digits.pips);
    if (dPip+".0" == dFrc)      return(dPip);           return(dFrc);          }
Reason: