//+------------------------------------------------------------------+
//|                EA Name:  KeltnerChannel.mq4                      |
//|               Coded by:  Christina Li @ Wise-EA                  |
//|                    web:  http//www.wix.com/wiseea/wise-ea#!      |
//|                  email:  Contactchristinali@gmail.com            |
//|                 Update:  03.29/2012                              |
//+------------------------------------------------------------------+

//----
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 DimGray
#property indicator_color2 Black
#property indicator_color3 DimGray

extern int    MAType           = 1;
extern int    MAPeriod         = 20;
extern int    MAPrice          = 5;
extern int    ATRPeriod        = 60;
extern double ATRMultipler     = 1.18;
extern string TypeHelp        = "0=sma,1=ema,2=smma,3=lwma";
extern string PriceHelp       = "0=cls,1=op,2=hi,3=lo,4=median,5=typical";

int    BandsShift=0;
double upper[], middle[], lower[];
input int NotUsed   =  0;
//+------------------------------------------------------------------+
//| INITIALIZATION                                                   |
//+------------------------------------------------------------------+
int init() {
//----      
   SetIndexStyle(0,DRAW_LINE);
   SetIndexShift(0,0);
   SetIndexDrawBegin(0,0);
   SetIndexBuffer(0,upper);

   SetIndexStyle(1,DRAW_LINE);
   SetIndexShift(1,0);
   SetIndexDrawBegin(1,0);
   SetIndexBuffer(1,middle);

   SetIndexStyle(2,DRAW_LINE);
   SetIndexShift(2,0);
   SetIndexDrawBegin(2,0);
   SetIndexBuffer(2,lower);
   return(0);
}

//+------------------------------------------------------------------+
//| DEINITIALIZATION                                                 |
//+------------------------------------------------------------------+
int deinit() {
//----
//----
   return(0);
}

//+------------------------------------------------------------------+
//| MAIN LOOP                                                        |
//+------------------------------------------------------------------+
int start() {
//----
   int limit;
   int counted_bars=IndicatorCounted();
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   
   double avg;
   for(int x=0; x<limit; x++) {
      middle[x] = iMA(NULL, 0, MAPeriod, 0, MAType, MAPrice, x);
      avg  = iATR(NULL,0,ATRPeriod,x)*ATRMultipler;
      upper[x] = middle[x] + avg;
      lower[x] = middle[x] - avg;
   }
   return(0);
}


