//------------------------------------------------------------------
//
//------------------------------------------------------------------
#property copyright "Copyright © GPL General Public License"
#property link      "open source fx community"

#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 LimeGreen
#property indicator_color2 Red
#property indicator_color3 DarkGray
#property indicator_color4 LimeGreen
#property indicator_color5 Red
#property indicator_style1 STYLE_DOT
#property indicator_style2 STYLE_DOT
#property indicator_style3 STYLE_DOT
#property indicator_width4 2
#property indicator_width5 3

//
//
//
//
//

extern int    ChannelPeriod = 20; 
extern int    AtrPeriod     = 14;
extern double AtrMultiplier =  1;

double UpLine[];
double DownLine[];
double MiddleLine[];
double UpDot[];
double DownDot[];

//------------------------------------------------------------------
//
//------------------------------------------------------------------
int init()
{
   SetIndexBuffer(0,UpLine);
   SetIndexBuffer(1,DownLine);
   SetIndexBuffer(2,MiddleLine);
   SetIndexBuffer(3,UpDot);     SetIndexStyle(3,DRAW_ARROW);
   SetIndexBuffer(4,DownDot);   SetIndexStyle(4,DRAW_ARROW);
   return(0);
}
int deinit()
{
   return(0);
}

//
//
//

int start()
{
   int counted_bars = IndicatorCounted();
      if(counted_bars<0) return(-1);
      if(counted_bars>0) counted_bars--;
           int limit=MathMin(Bars-counted_bars,Bars-1);
   
   for(int i = limit; i >= 0; i--)
   {
      double atr = iATR(NULL,0,AtrPeriod,i);
         UpLine[i]     = High[iHighest(NULL, 0, MODE_HIGH, ChannelPeriod, i+1)]+atr*AtrMultiplier;
         DownLine[i]   = Low[  iLowest(NULL, 0, MODE_LOW,  ChannelPeriod, i+1)]-atr*AtrMultiplier;
         MiddleLine[i] = (UpLine[i] + DownLine[i])/2;
         UpDot[i]      = EMPTY_VALUE;
         DownDot[i]    = EMPTY_VALUE;
            if (High[i]>UpLine[i])  UpDot[i]   = High[i];
            if (Low[i]<DownLine[i]) DownDot[i] = Low[i];
   }
   return(0);
}