//+------------------------------------------------------------------+
//|                                                      Channel.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © GPL General Public License"
#property link      "open source fx community"

#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1  Blue
#property indicator_color2  Red
#property indicator_color3  Aqua
#property indicator_color4  Magenta

//
//
//
//
//

extern int ChannelPeriod1 = 20; 
extern int ChannelPeriod2 = 55;

//
//
//
//
//

double Up1[];
double Dn1[];
double Up2[];
double Dn2[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
//
//

int init()
{
   SetIndexBuffer(0,Up1);
   SetIndexBuffer(1,Dn1);
   SetIndexBuffer(2,Up2);
   SetIndexBuffer(3,Dn2);
   
return(0);
}

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
//
//

int deinit() { return(0); }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
//
//

int start()
{
   int limit,i,counted_bars = IndicatorCounted();

   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
       limit = MathMin(Bars - counted_bars,Bars-1);     
   
   //
   //
   //
   //
   //
   
   for (i = limit; i >= 0 ; i--)
   {   
      Up1[i] = High[iHighest(NULL,0,MODE_HIGH,ChannelPeriod1, i+1)];            
      Dn1[i] =  Low[iLowest(NULL, 0,MODE_LOW, ChannelPeriod1, i+1)];
      Up2[i] = High[iHighest(NULL,0,MODE_HIGH,ChannelPeriod2, i+1)];            
      Dn2[i] =  Low[iLowest(NULL, 0,MODE_LOW, ChannelPeriod2, i+1)];
   }
return(0);
}

//+------------------------------------------------------------------+