//+------------------------------------------------------------------+
//|                                                      Channel.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © GPL General Public License"
#property link      "open source fx community"

#property indicator_chart_window include ""
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_width1 2
#property indicator_width2 2



extern int       ChannelPeriod = 21; 


//---- buffers
double UpLine[];
double DownLine[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,UpLine);
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,DownLine);
   
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
  ObjectsDeleteAll();
//---- TODO: add your code here
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
      string short_name = "test("+ChannelPeriod+")";
      IndicatorShortName(ChannelPeriod);
   
  ObjectCreate("Wil's", OBJ_LABEL, 0,0,0);
  ObjectSet("Wil's", OBJPROP_CORNER, 3);
  ObjectSet("Wil's", OBJPROP_XDISTANCE,45);
  ObjectSet("Wil's", OBJPROP_YDISTANCE, 45);  
  ObjectSetText("Wil's", "Wil's ", 10, "Verdana", Black );
  
  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--)
   {
      
      UpLine[i] = High[ Highest(NULL, 0, MODE_HIGH, ChannelPeriod, i+0.5) ];            
      DownLine[i] = Low[ Lowest(NULL, 0, MODE_LOW, ChannelPeriod, i+0.5) ];
      
      
      

   
  }
//----
   return(0);
  }
//+------------------------------------------------------------------+