Download MetaTrader 5
To add comments, please log in or register
Store your source codes in MQL5 Storage. It is secure!
francisco
125
francisco 2014.07.29 19:39 
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

francisco
125
francisco 2014.07.29 20:44  
//+------------------------------------------------------------------+
//|                                                       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);
}
francisco
125
francisco 2014.07.29 20:45  

I tried this. But error.

Thank you very much. 

Simon Gniadkowski
Moderator
17963
Simon Gniadkowski 2014.07.29 20:54  
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()
qjol
3243
qjol 2014.07.29 20:55  
can you please explain again why do need of using "DoubleToString" ?
francisco
125
francisco 2014.07.29 21:09  
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
qjol
3243
qjol 2014.07.29 21:20  
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 

francisco
125
francisco 2014.07.29 21:35  
Thank you very much qjol. 
You were right. Much easier that way. 
Thank you very much
/
To add comments, please log in or register