//+------------------------------------------------------------------+
//|                                                  drMAchannel.mq4 |
//|                                               (c) dr.Chaos, 2015 |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright  "(c) dr.Chaos, 2015"
#property link       ""
#property version    "1.00"

#property indicator_chart_window

#property indicator_buffers   4

#property indicator_color1    clrIndigo
#property indicator_color2    clrIndigo
#property indicator_color3    clrIndigo
#property indicator_color4    clrIndigo

#property indicator_width1    5
#property indicator_width2    5
#property indicator_width3    5
#property indicator_width4    5

extern   int   MA1Period = 20;
extern   int   MA1Method = MODE_EMA;
extern   int   MA1Price  = PRICE_HIGH;

extern   int   MA2Period = 20;
extern   int   MA2Method = MODE_EMA;
extern   int   MA2Price  = PRICE_LOW;

double   buffer1[];
double   buffer2[];
double   buffer3[];
double   buffer4[];

//+------------------------------------------------------------------+
//| Инициализация функций индикатора                                 |
//+------------------------------------------------------------------+
int OnInit()
{
   SetIndexBuffer(0, buffer3);   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexBuffer(1, buffer4);   SetIndexStyle(1, DRAW_HISTOGRAM);
   SetIndexBuffer(2, buffer1);
   SetIndexBuffer(3, buffer2);

   return(0);
}

int deinit()
{
   return(0);
}

//+------------------------------------------------------------------+
//| Старт индикатора                                                 |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
{
   int   counted_bars = IndicatorCounted();
   int   limit, i;
   
   if (counted_bars<0) return(-1); 
   if (counted_bars>0) counted_bars--;
   
   limit = Bars - counted_bars;
   
   for (i=limit; i>=0; i--) {
      buffer1[i] = iMA(NULL, 0, MA1Period, 0, MA1Method, MA1Price, i);
      buffer2[i] = iMA(NULL, 0, MA2Period, 0, MA2Method, MA2Price, i);
      buffer3[i] = buffer1[i];
      buffer4[i] = buffer2[i];
   }
   
   return(0);
}
//+------------------------------------------------------------------+
