GET 5 DECIMAL

 
Very good, 
Again I start learning to program in MQL. 
Now what I want is to calculate the average high and low price. 
First in a separate window, and 5 decimal places in the result. 

The problem is I know I have to use "DoubleToString". But I put it all the way and got the error.

//+------------------------------------------------------------------+
//|                                                       jejeje.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_minimum 1
double buf_0[];

  
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,buf_0);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
int i;
double HL= (high[i]+low[i])/2;

buf_0[i]=HL;
string DoubleToStr(HL, 5);

  
//--- return value of prev_calculated for next call
   return(rates_total);
}

 How and where should I put "DoubleToStr"? 

thank you very much

 
//+------------------------------------------------------------------+
//|                                                       jejeje.mq4 |
//|                        Copyright 2013, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2013, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_minimum 1
double buf_0[];
string DoubleToStr(HL, 5);

  
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
   SetIndexBuffer(0,buf_0);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
int i;
double HL= (high[i]+low[i])/2;

buf_0[i]=HL;


  
//--- return value of prev_calculated for next call
   return(rates_total);
}
 

I tried this. But error.

Thank you very much. 

 
burnssss:

 How and where should I put "DoubleToStr"? 


In a Print() or Comment() statement . . .  Doubles are more than 5 digits . . . you just can't see more than 4 when you Print or Comment unless you do something like DoubleToStr()
 
can you please explain again why do need of using "DoubleToString" ?
 
good, 
I want to use DoubleToStr
The problem is, that in calculating the average, the number contains 8 decimal. 
In my display 4 decimal is. 
I want to appear 5 decimal. 
DoubleToStr calculated change the format, the string, in order to limit the number of decimal number. 
DoubleToStr How should I use and where? 
Thank you very much
 
burnssss:

I want to use DoubleToStr. 

 

i get it but you still didn't explained why

 

burnssss:

The problem is, that in calculating the average, the number contains 8 decimal. 

In my display 4 decimal is. 

 

then use IndicatorDigits

 

burnssss:

DoubleToStr How should I use and where? 

 

see here 

 
Thank you very much qjol. 
You were right. Much easier that way. 
Thank you very much
Reason: