//+------------------------------------------------------------------+
//|                                               WeekEndChennel.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 6
#property indicator_color1 Red
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Blue
#property indicator_color5 Red
#property indicator_color6 Red

extern int LastBarsCount=2;
extern int MinChanWidth=100;
extern bool Show_1xChannel=true;
extern bool Show_EnterBuffer=true;
extern int EnterBuf=10;

//---- buffers
double ChHighBuffer[];
double ChLowBuffer[];
double Ch1xHighBuffer[];
double Ch1xLowBuffer[];
double EnterHighBuffer[];
double EnterLowBuffer[];



//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,ChHighBuffer);
   SetIndexLabel(0,"BO top");
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,ChLowBuffer);
   SetIndexLabel(1,"BO bottom");
   
   SetIndexStyle(2,DRAW_LINE);
   SetIndexBuffer(2,Ch1xHighBuffer);
   SetIndexLabel(2,"1xBO top");
   SetIndexStyle(3,DRAW_LINE);
   SetIndexBuffer(3,Ch1xLowBuffer);
   SetIndexLabel(3,"1xBO bottom");
   
   SetIndexStyle(4,DRAW_LINE,STYLE_DASH);
   SetIndexBuffer(4,EnterHighBuffer);
   SetIndexLabel(4,"Enter buffer high");
   SetIndexStyle(5,DRAW_LINE,STYLE_DASH);
   SetIndexBuffer(5,EnterLowBuffer);
   SetIndexLabel(5,"Enter buffer low");
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
   int barshift;
   double H,L,dif;
//----
   if (counted_bars>0) counted_bars--;
   int    limit=Bars-counted_bars;
   
     for(int i=0;i<limit;i++)
   {
   barshift=((TimeDayOfWeek(Time[i])-1)*6)+MathFloor(TimeHour(Time[i])/4)+1;
   H=High[iHighest(NULL,0,MODE_HIGH,LastBarsCount,i+barshift)];
   L=Low[iLowest(NULL,0,MODE_LOW,LastBarsCount,i+barshift)];
   dif=(Point*MinChanWidth)-(H-L);
   if (dif<0) dif=0;
   ChHighBuffer[i]=H+dif/2;
   ChLowBuffer[i]=L-dif/2;
   
   if (Show_1xChannel==true)
   {
   Ch1xHighBuffer[i]=ChHighBuffer[i]+(ChHighBuffer[i]-ChLowBuffer[i]);
   Ch1xLowBuffer[i]=ChLowBuffer[i]-(ChHighBuffer[i]-ChLowBuffer[i]);
   }
   if (Show_EnterBuffer==true)
   {
   EnterHighBuffer[i]=ChHighBuffer[i]+Point*EnterBuf;
   EnterLowBuffer[i]=ChLowBuffer[i]-Point*EnterBuf;
   }
 
 //  Comment("BO top is ",ChHighBuffer[i],"\n","BO bottom is ",ChLowBuffer[i],"\n","BO channel width is ",(ChHighBuffer[i]-ChLowBuffer[i]) );
   
   }
//----
   return(0);
  }
//+------------------------------------------------------------------+