Download MetaTrader 5
To add comments, please log in or register
Sign up for MQL5.community to leave your comments!
Justify
59
Justify 2014.11.08 14:24 

Why in the following code, does not draw logarithms?

//+------------------------------------------------------------------+
//|                                                   Logaritmos.mq4 |
//|                        Copyright 2014, MetaQuotes Software Corp. |
//|                                              https://www.mql5.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color2 Red
#property indicator_minimum    0
#property indicator_maximum    1
double A[];
double B[];



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexBuffer(0,B);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,2);
   IndicatorDigits(Digits+5);

   
    return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
  {
 int counted_bars=IndicatorCounted();


if (counted_bars>0)
counted_bars--;
int limit= Bars-counted_bars;


for (int i=0;i<limit;i++)
{
//----
  
  
   
     A[i]=(High[i]);
     B[i]=MathLog(A[i]);
   
   }
   return(0);
} 

  
//+------------------------------------------------------------------+

 Thank You very much

honest_knave
969
honest_knave 2014.11.08 14:43  

I'm guessing you have an array out of range error in your log? You do not SetIndexBuffer for A[].

 I suspect you'll also have problems with your color assignment (indicator_color2 Red)

And possibly also your indicator minimum (indicator_minimum    0) .... natural log of values >0  && <1 are negative (think USDCHF, for example).

Justify
59
Justify 2014.11.08 14:53  
honest_knave:

I'm guessing you have an array out of range error in your log? You do not SetIndexBuffer for A[].

 I suspect you'll also have problems with your color assignment (indicator_color2 Red)

And possibly also your indicator minimum (indicator_minimum    0) .... natural log of values >0  && <1 are negative (think USDCHF, for example).

Thank you very much for your reply.
I want to represent the logarithms of the high price.
The logarithms are represented by "B []."
Therefore, in SetIndexBuffer I use B [], right?

I modified the values in [-1,1] But I still get not the values of log.

#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color2 Red
#property indicator_minimum    -1
#property indicator_maximum    1
double A[];
double B[];



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexBuffer(0,B);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,indicator_color2);
   

   
    return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
  {
 int counted_bars=IndicatorCounted();


if (counted_bars>0)
counted_bars--;
int limit= Bars-counted_bars;


for (int i=0;i<limit;i++)
{
//----
  
  
   
     A[i]=(High[i]);
     B[i]=MathLog(A[i]);
   
   }
   return(0);
} 

  
//+------------------------------------------------------------------+

 

honest_knave
969
honest_knave 2014.11.08 15:26  

The problem is that you have declared an array A[] but it has no size.

So when you access A[i] it is going to be out of range. Have you checked your Experts Tab?

Why don't you dispense with A altogether:

 

#property copyright "Copyright 2014, MetaQuotes Software Corp."
#property link      "https://www.mql5.com"
#property version   "1.00"
#property strict
#property indicator_separate_window
//#property indicator_buffers 2
#property indicator_buffers 1
//#property indicator_color2 Red
#property indicator_color1 Red
//#property indicator_minimum    -1
//#property indicator_maximum    1
double A[];
//double B[];



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//   SetIndexBuffer(0,B);
//   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID,indicator_color2);
   SetIndexBuffer(0,A);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
 
    return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
  {
 int counted_bars=IndicatorCounted();


if (counted_bars>0)
counted_bars--;
int limit= Bars-counted_bars;


for (int i=0;i<limit;i++)
{
//----
  
  
//     A[i]=(High[i]);
//     B[i]=MathLog(A[i]);
     A[i]=MathLog(High[i]);
   
   }
   return(0);
} 

  
//+------------------------------------------------------------------+
Agent86
915
Agent86 2014.11.08 15:37  
honest_knave:

The problem is that you have declared an array A[] but it has no size.

So when you access A[i] it is going to be out of range. Have you checked your Experts Tab?

Why don't you dispense with A altogether:

 

I believe you meant dispense with B altogether right ?
As you have done in the corrected code with //B's related commenting ?
Justify
59
Justify 2014.11.08 16:06  
honest_knave:

The problem is that you have declared an array A[] but it has no size.

So when you access A[i] it is going to be out of range. Have you checked your Experts Tab?

Why don't you dispense with A altogether:

 

Thank you very much.
Another question,
how many decimal places at most shows MQL4?

I have understood that 15, but with this instruction, I do not get more than 8:

int init()
  {
//---- indicators
//   
   SetIndexBuffer(0,A);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
 IndicatorDigits(Digits+10);
    return(0);
  }

 

honest_knave
969
honest_knave 2014.11.08 16:40  
Agent86:
I believe you meant dispense with B altogether right ?
As you have done in the corrected code with //B's related commenting ?



Dispense with either because only 1 is necessary.

But you are quite right though, because of my code I should have written B not A. 

honest_knave
969
honest_knave 2014.11.08 16:43  
justify:
Thank you very much.
Another question,
how many decimal places at most shows MQL4?

I have understood that 15, but with this instruction, I do not get more than 8:

 

The values of A are stored as doubles, so their representation accuracy is 15 significant digits. You can see this by printing the values of A.

int start()
  {
 int counted_bars=IndicatorCounted();


if (counted_bars>0)
counted_bars--;
int limit= Bars-counted_bars;


for (int i=0;i<limit;i++)
{
//----
  
  
//     A[i]=(High[i]);
//     B[i]=MathLog(A[i]);
     A[i]=MathLog(High[i]);
     printf("%.15f",A[i]);   
   }
   return(0);
} 

 

 

 

However, I'm not sure how many digits the data window is capable of showing.

Justify
59
Justify 2014.11.08 16:56  
honest_knave:

The values of A are stored as doubles, so their representation accuracy is 15 significant digits. You can see this by printing the values of A.

 

However, I'm not sure how many digits the data window is capable of showing.

If it is a question I had about the decimals it supports. Still, I do not show me more than 8 decimal places, and I instuccion the previous post:

int init()
  {
//---- indicators
//   
   SetIndexBuffer(0,A);
   SetIndexStyle(0,DRAW_LINE,STYLE_SOLID);
 IndicatorDigits(Digits+10);
    return(0);
  }

int start()
  {
 int counted_bars=IndicatorCounted();


if (counted_bars>0)
counted_bars--;
int limit= Bars-counted_bars;


for (int i=0;i<limit;i++)
{
//----
  
  
//     A[i]=(High[i]);
//     B[i]=MathLog(A[i]);
     A[i]=MathLog(High[i]);
     printf("%.15f",A[i]);   
   }
   return(0);
} 

 

Justify
59
Justify 2014.11.08 17:26  
I know what I do not understand.
Decimal doing calculations with mt4?
That is, if I want to do calculations with decimals, I can take the number of decimal places to make those calculations ?.
For example, instead of using 18 decimal, I can use only 4?
honest_knave
969
honest_knave 2014.11.09 00:28  

Take a look at NormalizeDouble - it might be what you are after.

/
To add comments, please log in or register