
#property copyright "Copyright 2010, Learn Forex Live"
#property link      "http://www.LearnForexLive.com"

#property indicator_separate_window
#property indicator_minimum 0.0
#property indicator_maximum 0.1
#property indicator_buffers 2
#property indicator_color1 LightSalmon
#property indicator_color2 LightSkyBlue

double Buf1[];
double Buf2[];
double MA1[];
int MA_Method = MODE_EMA;
int MA_Period = 50;
int MA_Smechenie = 0;
int MA_Price = PRICE_CLOSE;

int init() {
   IndicatorBuffers(5);
   SetIndexBuffer(0, Buf1);
   SetIndexBuffer(1, Buf2);
   SetIndexBuffer(2, MA1);
   SetIndexStyle(0, DRAW_HISTOGRAM, STYLE_SOLID, 4);
   SetIndexStyle(1, DRAW_HISTOGRAM, STYLE_SOLID, 4);
   return (0);
}

int start() {
   for (int i = Bars - 10; i >= 0; i--) MA1[i] = iMA(NULL, 0, MA_Period, MA_Smechenie, MA_Method, MA_Price, i);
   if (MA1[0] > MA1[1]) {
      Buf1[0] = EMPTY_VALUE;
      Buf2[0] = MA1[0];
   } else {
      if (MA1[0] < MA1[1]) {
         Buf2[0] = EMPTY_VALUE;
         Buf1[0] = MA1[0];
      }
   }
   for (int h = Bars - 10; h >= 0; h--) {
      Buf1[h] = MA1[h];
      Buf2[h] = MA1[h];
      if (MA1[h] > MA1[h + 1] && MA1[h + 1] > MA1[h + 2]) {
         Buf1[h] = EMPTY_VALUE;
         Buf1[h + 1] = EMPTY_VALUE;
         Buf2[h + 1] = MA1[h + 1];
      } else {
         if (MA1[h] < MA1[h + 1] && MA1[h + 1] < MA1[h + 2]) {
            Buf2[h] = EMPTY_VALUE;
            Buf2[h + 1] = EMPTY_VALUE;
            Buf1[h + 1] = MA1[h + 1];
         }
      }
   }
   return (0);
}