No appears the indicator line - page 2

 
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.


?


Sorry. I forgot to take into consideration that the parameters A and B must be different. Otherwise, ATR1-ATR2=0

ATR1=iATR(NULL, PERIOD_CURRENT, A, i);
ATR2=iATR(NULL, PERIOD_CURRENT, B, i);

If A=B, then ATR1-ATR2=0, and then you will not be able to see the line of an indicator.
 

I can write 1 (where is "i") , and is happening the same.

when I change only period, it work:

       ATR1=iATR(NULL, PERIOD_CURRENT, 14, i);
       ATR2=iATR(NULL, PERIOD_CURRENT, 24, i);
       Buffer[i]=ATR1-ATR2;

But, How about if I want is ATR14 of previous candle and the previous to that one:

iATR(NULL, PERIOD_CURRENT, 14, 1)-iATR(NULL, PERIOD_CURRENT, 14, 2)


For example. Let says I do a ATR band (But is not drawing the lines):


int i,
   Counted_bars;
  
   Counted_bars = IndicatorCounted();
   i= Bars - Counted_bars - 1;
   while (i>0)
      {
       price=iClose(NULL, PERIOD_CURRENT, 1);
       ATR=iATR(NULL, PERIOD_CURRENT, 24, 1);
       Buffer1[i]=price-ATR;
       Buffer2[i]=price+ATR;        
       i--;
      }  


When I write that is happening the same problem: it does not draw the line of the indicator.


With A and B are you refering to the candle (1, 2). I ask because "iATR(NULL, PERIOD_CURRENT, 1, i)" is not the format. Where do you write it?


This is the code I am using right now for the ATR band:

//+------------------------------------------------------------------+
//|                                                 Aprendiendo2.mq4 |
//|                                                Copyright 2014,JE |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright "Copyright 2014,JE"
#property link      ""
#property version   "1.00"
#property strict
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 White
#property indicator_color2 White

//--- buffers
double Buffer1[], Buffer2[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
 SetIndexBuffer (0, Buffer1);
 SetIndexStyle (0, DRAW_LINE, STYLE_SOLID, 2, White);
 
 SetIndexBuffer (0, Buffer2);
 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 price,ATR;

  
//---
 
int i,
   Counted_bars;
  
   Counted_bars = IndicatorCounted();
   i= Bars - Counted_bars - 1;
   while (i>0)
      {
       price=iClose(NULL, PERIOD_CURRENT, 1);
       ATR=iATR(NULL, PERIOD_CURRENT, 24, 1);
       Buffer1[i]=price-ATR;
       Buffer2[i]=price+ATR;        
       i--;
      }  


//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
 
int OnInit()
  {
//--- indicator buffers mapping
SetIndexBuffer (0, Buffer1);
SetIndexStyle (0, DRAW_LINE, STYLE_SOLID, 2, White);

SetIndexBuffer (0, Buffer2);
SetIndexStyle (0, DRAW_LINE, STYLE_SOLID, 2, White); // DONT USE THE SAME BUFFER INDEX FOR BOTH BUFFERS 
//---
   return(INIT_SUCCEEDED);
  }

   while (i>0) //WHAT ABOUT THE ZERO BAR. i>=0
      {
       price=iClose(NULL, PERIOD_CURRENT, 1); // YOU ARE CALLING THE SAME VALUES FROM BAR 1 FOR THE ENTIRE INDICATOR
       ATR=iATR(NULL, PERIOD_CURRENT, 24, 1); // WHY ARE YOU NOT USING YOUR COUNTER "i" OR i+1 ?
       Buffer1[i]=price-ATR;
       Buffer2[i]=price+ATR;        
       i--;
      } 

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[])
  {

   price=iClose(NULL, PERIOD_CURRENT, 1); // WHY CALL iCLOSE WHEN YOU ALREADY PASSED CLOSE PRICES ARRAY IN THE PARAMETERS.
 
trader201:
ATR1=iATR(NULL, PERIOD_CURRENT, 14, i);
ATR2=iATR(NULL, PERIOD_CURRENT, 24, i);
Buffer[i]=ATR1-ATR2;
But, How about if I want is ATR14 of previous candle and the previous to that one:
ATR1=iATR(NULL, PERIOD_CURRENT, 14, i+1);
ATR2=iATR(NULL, PERIOD_CURRENT, 14, i+2);
Buffer[i]=ATR1-ATR2;
Reason: