//+------------------------------------------------------------------+
//|                                                 ATR Channels.mq4 |
//|                         Copyright © 2005, Luis Guilherme Damiani |
//|                                      http://www.damianifx.com.br |
//+------------------------------------------------------------------+

#property copyright "Copyright © 2005, Luis Guilherme Damiani"
#property link      "http://www.damianifx.com.br"
#property indicator_chart_window
#property  indicator_buffers 2
#property  indicator_color1  DeepSkyBlue // Lower band 1
#property  indicator_color2  DeepSkyBlue // Upper band 1
//---- indicator buffers
double     Ch1up_Buffer1[];
double     Ch1dn_Buffer2[];

//---- input parameters
extern int                 PeriodsATR   = 24;
extern int                 MA_Periods   = 100;
extern ENUM_MA_METHOD      MA_type      = MODE_LWMA;
extern double              Mult_Factor1 = 3.62;
extern ENUM_APPLIED_PRICE  applied_price = PRICE_TYPICAL;
extern int                 fontsize     = 8;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  //string mat;
 
//---7- indicators
  // ATR 1 up
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Ch1up_Buffer1);
   SetIndexDrawBegin(0,0);
   SetIndexLabel(0,"ATRu "+PeriodsATR+", "+Mult_Factor1);
  // ATR 1 down
   SetIndexStyle(1,DRAW_LINE);
   SetIndexBuffer(1,Ch1dn_Buffer2);
   SetIndexDrawBegin(1,0);
   SetIndexLabel(1,"ATRd "+PeriodsATR+", "+Mult_Factor1);

////----

   ObjectCreate("lf3", OBJ_TEXT, 0, 0, 0);
   ObjectSetString(0, "lf3", OBJPROP_TOOLTIP, "\n");
   ObjectSetInteger(0, "lf3", OBJPROP_ANCHOR, ANCHOR_LEFT);   
   ObjectSetText("lf3", DoubleToStr(Mult_Factor1,3),fontsize,"Arial",Red);
   ObjectCreate("lf4", OBJ_TEXT, 0, 0, 0);
   ObjectSetString(0, "lf4", OBJPROP_TOOLTIP, "\n");
   ObjectSetInteger(0, "lf4", OBJPROP_ANCHOR, ANCHOR_LEFT);   
   ObjectSetText("lf4", DoubleToStr(Mult_Factor1,3),fontsize,"Arial",Red);
   return(0);
  }
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {//---- 
   ObjectDelete("lf3");
   ObjectDelete("lf4");
   
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int fixed_bars=IndicatorCounted();
   for(int i=0;i< Bars - fixed_bars;i++)
     {
         double atr=iATR(NULL,0,PeriodsATR,i);
         double ma=iMA(NULL,0,MA_Periods,0,MA_type,applied_price,i);
         Ch1up_Buffer1[i]=ma+atr*Mult_Factor1;
         Ch1dn_Buffer2[i]=ma-atr*Mult_Factor1;
     }
         ObjectMove("lf3", 0, Time[0],Ch1up_Buffer1[0]);
         ObjectMove("lf4", 0, Time[0],Ch1dn_Buffer2[0]);
//---- 
   
//----
   return(0);
  }

