//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2018, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 White
#property indicator_color2 Red
#property indicator_color3 Blue

int period_ma;
double Gd_unused_80;
double G_ibuf_88[];
double G_ibuf_92[];
double G_ibuf_96[];
double Gd_100;
double Gd_108;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorBuffers(3);
   SetIndexBuffer(0, G_ibuf_96);
   SetIndexStyle(0, DRAW_LINE);
   SetIndexArrow(0, 159);
   SetIndexBuffer(1, G_ibuf_88);
   SetIndexStyle(1, DRAW_LINE);
   SetIndexArrow(1, 159);
   SetIndexBuffer(2, G_ibuf_92);
   SetIndexStyle(2, DRAW_LINE);
   SetIndexArrow(2, 159);
   switch(Period())
     {
      case PERIOD_M5:
         period_ma = 252;
         break;
      case PERIOD_M15:
         period_ma = 84;
         break;
      case PERIOD_H4:
         period_ma = 5;
         break;
      default:
         period_ma = 21;
     }
   return (0);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {
   ObjectDelete("Bar50");
   ObjectDelete("Bar50t");
   return (0);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   for(int Li_0 = Bars - period_ma; Li_0 >= 0; Li_0--)
     {
      if(Close[Li_0] > iMA(Symbol(), 0, period_ma, 0, MODE_EMA, PRICE_HIGH, Li_0 + 1))
         Gd_100 = 1;
      else
        {
         if(Close[Li_0] < iMA(Symbol(), 0, period_ma, 0, MODE_EMA, PRICE_LOW, Li_0 + 1))
            Gd_100 = -1;
         else
            Gd_100 = 0;
        }
      if(Gd_100 != 0.0)
         Gd_108 = Gd_100;
      if(Gd_108 == -1.0)
        {
         G_ibuf_96[Li_0] = iMA(Symbol(), 0, period_ma, 0, MODE_EMA, PRICE_HIGH, Li_0 + 1);
         G_ibuf_88[Li_0] = iMA(Symbol(), 0, period_ma, 0, MODE_EMA, PRICE_HIGH, Li_0 + 1);
         Gd_unused_80 = 255;
        }
      else
        {
         G_ibuf_96[Li_0] = iMA(Symbol(), 0, period_ma, 0, MODE_EMA, PRICE_LOW, Li_0 + 1);
         G_ibuf_92[Li_0] = iMA(Symbol(), 0, period_ma, 0, MODE_EMA, PRICE_LOW, Li_0 + 1);
         Gd_unused_80 = 16711680;
        }
     }
   return (0);
  }
//+------------------------------------------------------------------+
