//+------------------------------------------------------------------+
//|                                                  ATR_Channel.mq4 |
//|                      Copyright © 2008, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Green
//---- buffers
double ExtMapBuffer1[];
double ExtMapBuffer2[];
double ExtMapBuffer3[];

extern int ATRper=5;
extern double ATRfactor=1;
extern int TF=0;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ExtMapBuffer1);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ExtMapBuffer2);
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,ExtMapBuffer3);
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   double ATR,pivot;
   if (counted_bars>0) counted_bars--;
   int    limit=Bars-counted_bars;
   int i,y=0;
   datetime TimeArray[];
   
   ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TF); 
   
   for(i=0,y=0;i<limit;i++)
   {
   if (Time[i]<TimeArray[y]) y++;
   ATR=iATR(NULL,TF,ATRper,y+1);
// pivot=(Close[i+1]+High[i+1]+Low[i+1])/3;
   pivot=Open[i];
   ExtMapBuffer1[i]=pivot+ATR*ATRfactor;
   ExtMapBuffer2[i]=pivot-ATR*ATRfactor;
   ExtMapBuffer3[i]=pivot;
   }
//----
//----
   return(0);
  }
//+------------------------------------------------------------------+