//+------------------------------------------------------------------+
//|                                        #TMA+CHANNEL_END_POINT.mq4 |
//|                                                   by Sohocool |
 //////////////////////                               April 2012
//|                      Copyright © 2012, MetaQuotes Software Corp. |
//|                                        http://www.metaquotes.net |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2012, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 Blue
#property indicator_color2 Blue
#property indicator_color3 Blue


extern int     HalfLength = 56;
extern int     ATR_PERIOD = 100;
extern double  Deviations = 2.4;

 int     MA_MODE = MODE_LWMA;
/*
MODE_SMA  0 Простое скользящее среднее 
MODE_EMA  1 Экспоненциальное скользящее среднее 
MODE_SMMA 2 Сглаженное скользящее среднее 
MODE_LWMA 3 Линейно-взвешенное скользящее среднее 
*/
 int     PRICE_MODE = PRICE_WEIGHTED;
/*
PRICE_CLOSE    0 Цена закрытия 
PRICE_OPEN     1 Цена открытия 
PRICE_HIGH     2 Максимальная цена 
PRICE_LOW      3 Минимальная цена 
PRICE_MEDIAN   4 Средняя цена, (high+low)/2 
PRICE_TYPICAL  5 Типичная цена, (high+low+close)/3 
PRICE_WEIGHTED 6 Взвешенная цена закрытия, (high+low+close+close)/4 
*/

double upper[], middle[], lower[];

int init()
  {
   SetIndexStyle(0,DRAW_LINE,STYLE_DOT);
   SetIndexShift(0,0);
   SetIndexDrawBegin(0,0);
   SetIndexBuffer(0,middle);

   SetIndexStyle(1,DRAW_LINE);
   SetIndexShift(1,0);
   SetIndexDrawBegin(1,0);
   SetIndexBuffer(1,upper);

   SetIndexStyle(2,DRAW_LINE);
   SetIndexShift(2,0);
   SetIndexDrawBegin(2,0);
   SetIndexBuffer(2,lower);
    

//---- indicators
//----
   return(0);
  }

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
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, HalfLength, 0, MA_MODE, PRICE_MODE, x);
      
      avg  = iATR(NULL,0,ATR_PERIOD, x);
      
      upper[x] = middle[x] + Deviations * avg;
      lower[x] = middle[x] - Deviations * avg;
   }
   return(0);
}
//+------------------------------------------------------------------+