//+------------------------------------------------------------------+
//|                                                   i-DayRange.mq4 |
//|                                           ��� ����� �. aka KimIV |
//|                                              http://www.kimiv.ru |
//|                                                                  |
//|   17.11.2005  ��������� �������� ���������                       |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Gainsboro
#property indicator_color2 Gainsboro
#property indicator_color3 LightSlateGray

//------- ������� ��������� ���������� -------------------------------
extern int NumberOfDays = 2;   // ���������� ���� (0-���)

double shifthigh[];
double shiftlow[];
double shiftaver[];

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void init() {
  SetIndexStyle(0,DRAW_LINE, 0,1);
  SetIndexBuffer(0,shifthigh);
  SetIndexLabel(0,"Up Channel");
  SetIndexDrawBegin(0,0);

  SetIndexStyle(1,DRAW_LINE, 0,1);
  SetIndexBuffer(1,shiftlow);
  SetIndexLabel(1,"Down Channel");
  SetIndexDrawBegin(1,0);

  SetIndexStyle(2,DRAW_LINE, 0,1);
  SetIndexBuffer(2,shiftaver);
  SetIndexLabel(2,"Average Channel");
  SetIndexDrawBegin(2,0);
}

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
void deinit() {
  Comment("");
}

//+------------------------------------------------------------------+ 
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+ 
void start() {
  double LowLine=0;
  double HighLine=0;
  double AverLine=0;

  for (int i=NumberBar(); i>0; i--) {
    if (TimeHour(Time[i])==0 && TimeMinute(Time[i])==0) {
      LowLine=iLow(Symbol(),0,i);
      HighLine=iHigh(Symbol(),0,i);
    } else {
      if (iLow(Symbol(),0,i)<LowLine) LowLine=iLow(Symbol(),0,i);
      if (iHigh(Symbol(),0,i)>HighLine) HighLine=iHigh(Symbol(),0,i);
    }
    AverLine=LowLine+(HighLine-LowLine)/2;

    shiftlow[i]=LowLine;
    shifthigh[i]=HighLine;
    shiftaver[i]=AverLine;
  }

  Comment("������� ������� ��������: "+DoubleToStr((HighLine-LowLine)/Point,0)+" �.");
}

//+------------------------------------------------------------------+ 
//| ���������� ����� ����                                            |
//+------------------------------------------------------------------+ 
int NumberBar() {
  int nd=0, i=0;

  while (nd<NumberOfDays) {
    i++;
    if (TimeHour(Time[i])==0 && TimeMinute(Time[i])==0) nd++;
  }
  return(i);
}
//+------------------------------------------------------------------+