//+------------------------------------------------------------------+
//|                                          KG Average HLCC-S/R.mq4 |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2010, Goen n Fans"

#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Lime
#property indicator_color2 LimeGreen
#property indicator_color3 LimeGreen
#property indicator_color4 LimeGreen
#property indicator_color5 LimeGreen
#property indicator_color6 LimeGreen
#property indicator_color7 LimeGreen

extern int TimePeriod = 1440;
extern string Note = "4H=240 D=1440 W=10080 M=43200";
color LineColor = Lime;

double AvgBuff[],
       R1Buff[],
       S1Buff[],
       R2Buff[],
       S2Buff[],
       R3Buff[],
       S3Buff[];

//+------------------------------------------------------------------+
int init()
  {
  GetPeriod();
  IndicatorBuffers(7);

  SetIndexStyle(0,DRAW_LINE,0,2);
  SetIndexStyle(1,DRAW_LINE);
  SetIndexStyle(2,DRAW_LINE);
  SetIndexStyle(3,DRAW_LINE,2,0);
  SetIndexStyle(4,DRAW_LINE,2,0);
  SetIndexStyle(5,DRAW_LINE,2,0);
  SetIndexStyle(6,DRAW_LINE,2,0);

  SetIndexBuffer(0,AvgBuff);
  SetIndexBuffer(1,R1Buff);
  SetIndexBuffer(2,S1Buff);
  SetIndexBuffer(3,R2Buff);
  SetIndexBuffer(4,S2Buff);
  SetIndexBuffer(5,R3Buff);
  SetIndexBuffer(6,S3Buff);

  IndicatorShortName("KG Average HLCC - S/R,");  
  }

  return(0);
 
//+------------------------------------------------------------------+
int start()
  {
  datetime TimeArray[];
  int    i,shift,limit,y=0,counted_bars=IndicatorCounted();
  double Avg,H,L,C;

  ArrayCopySeries(TimeArray,MODE_TIME,Symbol(),TimePeriod);
  limit=Bars-counted_bars+TimePeriod/Period();
  for(i=0,y=0;i<limit;i++)
    {
    if (Time[i]<TimeArray[y]) y++;
      {
      H=iHigh(NULL,TimePeriod,y+1);
      L=iLow(NULL,TimePeriod,y+1);
      C=iClose(NULL,TimePeriod,y+1);
      Avg=(H+L+C+C)/4;
      }
      AvgBuff[i]=Avg;
      R1Buff[i]=Avg+((H+L+C+C)*0.001618);
      S1Buff[i]=Avg-((H+L+C+C)*0.001618);
      R2Buff[i]=Avg+((H+L+C+C)*0.002618);
      S2Buff[i]=Avg-((H+L+C+C)*0.002618);
      R3Buff[i]=Avg+((H+L+C+C)*0.004236);
      S3Buff[i]=Avg-((H+L+C+C)*0.004236);
    }

  return(0);
  }

//+------------------------------------------------------------------+
void GetPeriod()
  {
  switch(TimePeriod)
    {
    case 240 : LineColor = Blue; break;
    case 1440 : LineColor = Lime; break;
    case 10080 : LineColor = Magenta; break;
    case 43200 : LineColor = Aqua; break;
    }
  }
//+------------------------------------------------------------------+