No appears the indicator line

 
when I compile the code (indicator), it does not say any errors. But when I try mounting indicator in the window price, the indicator box appears, but not the line of the indicator.

Does anyone knows why is happening that?


This is the code:


//+------------------------------------------------------------------+
//|                                 ATR.mq4 |
//|                    Copyright 2014,J|
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014,J"
#property link      ""
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 White
//--- buffers
double Buffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
 SetIndexBuffer (0, Buffer);
 SetIndexStyle (0, DRAW_LINE, STYLE_SOLID, 2, White);
  
//---
   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[])
  {
   double ATR1, ATR2;
   ATR1=iATR(NULL, 14, PERIOD_CURRENT, 1);
   ATR2=iATR(NULL, 14, PERIOD_CURRENT, 1);
  
//---
 

int i,
   Counted_bars;
  
   Counted_bars = IndicatorCounted();
   i= Bars - Counted_bars - 1;
   while (i>0)
      {
      Buffer[i]=ATR1-ATR2;
      i--;

      }  


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

 
All true. Because ATR1-ATR2=0.

and

ATR1=iATR(NULL, 14, PERIOD_CURRENT, 1);

ATR2=iATR(NULL, 14, PERIOD_CURRENT, 1);

are not correct.


should be:

ATR1=iATR(NULL, PERIOD_CURRENT, 14, 1);

ATR2=iATR(NULL, PERIOD_CURRENT, 14, 1);


//+------------------------------------------------------------------+
//|                                 ATR.mq4 |
//|                    Copyright 2014,J|
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014,J"
#property link      ""
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 White
extern int  Period_ATR1 = 9;
extern int  Period_ATR2 = 14;
//--- buffers
double Buffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
 SetIndexBuffer (0, Buffer);
 SetIndexStyle (0, DRAW_LINE, STYLE_SOLID, 2, White);
  
//---
   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[])
  {
   double ATR1, ATR2;

  
//---
 
int i,
   Counted_bars;
  
   Counted_bars = IndicatorCounted();
   i= Bars - Counted_bars - 1;
   while (i>0)
      {
       ATR1=iATR(NULL, PERIOD_CURRENT, Period_ATR1, i);
       ATR2=iATR(NULL, PERIOD_CURRENT, Period_ATR2, i);
       Buffer[i]=ATR1-ATR2;
       i--;
      }  


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


 
Don't paste code
Play video
Please edit your post.
For large amounts of code, attach it.
 
Boeing747:
All true. Because ATR1-ATR2=0.

and

ATR1=iATR(NULL, 14, PERIOD_CURRENT, 1);

ATR2=iATR(NULL, 14, PERIOD_CURRENT, 1);

are not correct.


should be:

ATR1=iATR(NULL, PERIOD_CURRENT, 14, 1);

ATR2=iATR(NULL, PERIOD_CURRENT, 14, 1);





Ready. Thank you!
 

Why this part?:

and what it means?

extern int  Period_ATR1 = 9;
extern int  Period_ATR2 = 14;

 

If you don't know what a stop sign means, you don't belong behind the wheel.

If you don't know what extern means, stop playing with code and read the documentation. Do your homework. What does break mean? What does while mean? How many more question are you going to waste our time with?

 

rephrase my question:


Why you wrote the period in in the header? I remember, before was not necesary to do that in that way. the period should be placed at the head now, when is about indicators?
 
trader201:

rephrase my question:


Why you wrote the period in in the header? I remember, before was not necesary to do that in that way. the period should be placed at the head now, when is about indicators?

Because Period_ATR1 and Period_ATR2  are the input parameters of the indicator ATR. So it is accepted. But if you do not want to change these settings, you can do so:


//+------------------------------------------------------------------+
//|                                 ATR.mq4 |
//|                    Copyright 2014,J|
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014,J"
#property link      ""
#property version   "1.00"
#property strict
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 White
//--- buffers
double Buffer[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
 SetIndexBuffer (0, Buffer);
 SetIndexStyle (0, DRAW_LINE, STYLE_SOLID, 2, White);
  
//---
   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[])
  {
   double ATR1, ATR2;

  
//---
 
int i,
   Counted_bars;
  
   Counted_bars = IndicatorCounted();
   i= Bars - Counted_bars - 1;
   while (i>0)
      {
       ATR1=iATR(NULL, PERIOD_CURRENT, 14, i);
       ATR2=iATR(NULL, PERIOD_CURRENT, 14, i);
       Buffer[i]=ATR1-ATR2;
       i--;
      }  


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

Thank for everything Boeing747. You has  definitely helped me with all this. I'm already doing EAs again.


 

When I used the first way (period declared in the header), it worked. When I used the second, is not the line of the indicator. Even, I copy and pasted the 2 codes you placed, and the same thing happened.


?

 
trader201: When I used the first way (period declared in the header), it worked. When I used the second, is not the line of the indicator. Even, I copy and pasted the 2 codes you placed, and the same thing happened.
Because you are now back to
Boeing747: All true. Because ATR1-ATR2=0
ATR1=iATR(NULL, PERIOD_CURRENT, 14, i);
ATR2=iATR(NULL, PERIOD_CURRENT, 14, i);
Buffer[i]=ATR1-ATR2; < ZERO
Reason: