/*
   G e n e r a t e d  by ex4-to-mq4 decompiler FREEWARE 4.0.509.5
   Website:  Htt p: //WWw. mEtAQUO T Es.neT
   E-mail : sUpP O rT @ME T AQ UotES.N E t
*/

#property indicator_chart_window
#property indicator_buffers 3
#property indicator_color1 DodgerBlue
#property indicator_color2 Yellow
#property indicator_color3 Crimson

int Gi_76 = 20;
int Gi_80 = 0;
int G_ma_method_84 = MODE_LWMA;
int G_applied_price_88 = PRICE_CLOSE;
double Gd_92 = 2.0;
bool Gi_100 = TRUE;
int Gi_unused_104 = 48;
int Gi_unused_108 = 38;
bool Gi_112 = FALSE;
bool Gi_116 = FALSE;
bool Gi_120 = FALSE;
bool Gi_124 = FALSE;
double G_ibuf_128[];
double G_ibuf_132[];
double G_ibuf_136[];
double G_ibuf_140[];
int Gi_144;
string Gs_148;
datetime G_time_156 = 0;

string GetTimeFrameStr() {
   string timeframe_4;
   switch (Period()) {
   case PERIOD_M1:
      timeframe_4 = "M1";
      break;
   case PERIOD_M5:
      timeframe_4 = "M5";
      break;
   case PERIOD_M15:
      timeframe_4 = "M15";
      break;
   case PERIOD_M30:
      timeframe_4 = "M30";
      break;
   case PERIOD_H1:
      timeframe_4 = "H1";
      break;
   case PERIOD_H4:
      timeframe_4 = "H4";
      break;
   case PERIOD_D1:
      timeframe_4 = "D1";
      break;
   case PERIOD_W1:
      timeframe_4 = "W1";
      break;
   case PERIOD_MN1:
      timeframe_4 = "MN1";
      break;
   default:
      timeframe_4 = Period();
   }
   return (timeframe_4);
}

int init() {
   IndicatorBuffers(4);
   if ((!SetIndexBuffer(0, G_ibuf_128)) && (!SetIndexBuffer(1, G_ibuf_132)) && (!SetIndexBuffer(2, G_ibuf_136)) && (!SetIndexBuffer(3, G_ibuf_140))) Print("cannot set indicator buffers!");
   if (Gi_100) {
      SetIndexStyle(0, DRAW_ARROW);
      SetIndexStyle(1, DRAW_ARROW);
      SetIndexStyle(2, DRAW_ARROW);
      SetIndexArrow(0, 1);
      SetIndexArrow(1, 1);
      SetIndexArrow(2, 1);
   } else {
      SetIndexStyle(0, DRAW_LINE);
      SetIndexStyle(1, DRAW_LINE);
      SetIndexStyle(2, DRAW_LINE);
   }
   Gi_144 = Gi_76 + MathFloor(MathSqrt(Gi_76));
   SetIndexDrawBegin(0, Gi_144);
   SetIndexDrawBegin(1, Gi_144);
   SetIndexDrawBegin(2, Gi_144);
   IndicatorDigits(MarketInfo(Symbol(), MODE_DIGITS) + 1.0);
   IndicatorShortName("Trend(" + Gi_76 + ")");
   SetIndexLabel(0, "Trend");
   Gs_148 = Symbol() + " (" + GetTimeFrameStr() + "):  ";
   return (0);
}

int start() {
   double ima_on_arr_20;
   int Li_8 = IndicatorCounted();
   if (Li_8 < 1) {
      for (int Li_4 = 1; Li_4 <= Gi_144; Li_4++) G_ibuf_140[Bars - Li_4] = 0;
      for (Li_4 = 1; Li_4 <= Gi_76; Li_4++) {
         G_ibuf_128[Bars - Li_4] = 0;
         G_ibuf_132[Bars - Li_4] = 0;
         G_ibuf_136[Bars - Li_4] = 0;
      }
   }
   if (Li_8 > 0) Li_8--;
   int Li_0 = Bars - Li_8;
   for (Li_4 = 0; Li_4 < Li_0; Li_4++) {
      G_ibuf_140[Li_4] = 2.0 * iMA(NULL, 0, MathFloor(Gi_76 / Gd_92), Gi_80, G_ma_method_84, G_applied_price_88, Li_4) - iMA(NULL, 0, Gi_76, Gi_80, G_ma_method_84, G_applied_price_88,
         Li_4);
   }
   double ima_on_arr_12 = iMAOnArray(G_ibuf_140, 0, MathFloor(MathSqrt(Gi_76)), 0, G_ma_method_84, 0);
   for (Li_4 = 1; Li_4 < Li_0; Li_4++) {
      ima_on_arr_20 = iMAOnArray(G_ibuf_140, 0, MathFloor(MathSqrt(Gi_76)), 0, G_ma_method_84, Li_4);
      if (ima_on_arr_20 > ima_on_arr_12) {
         G_ibuf_128[Li_4] = EMPTY_VALUE;
         G_ibuf_132[Li_4] = EMPTY_VALUE;
         G_ibuf_136[Li_4] = ima_on_arr_20;
         G_ibuf_136[Li_4 - 1] = ima_on_arr_12;
      } else {
         if (ima_on_arr_20 < ima_on_arr_12) {
            G_ibuf_128[Li_4] = ima_on_arr_20;
            G_ibuf_128[Li_4 - 1] = ima_on_arr_12;
            G_ibuf_132[Li_4] = EMPTY_VALUE;
            G_ibuf_136[Li_4] = EMPTY_VALUE;
         } else {
            G_ibuf_128[Li_4] = -1;
            G_ibuf_132[Li_4] = ima_on_arr_20;
            G_ibuf_136[Li_4 - 1] = ima_on_arr_12;
            G_ibuf_136[Li_4] = -1;
         }
      }
      if (Gi_112) {
         if (ima_on_arr_20 < ima_on_arr_12) {
            if (!Gi_120) {
               if (BarChanged()) {
                  if (Gi_116) {
                  }
               }
               Gi_120 = TRUE;
               Gi_124 = FALSE;
            }
         }
         if (ima_on_arr_20 > ima_on_arr_12) {
            if (!Gi_124) {
               if (BarChanged()) {
                  if (Gi_116) {
                  }
               }
               Gi_124 = TRUE;
               Gi_120 = FALSE;
            }
         }
      }
      ima_on_arr_12 = ima_on_arr_20;
   }
   return (0);
}

int BarChanged() {
   if (G_time_156 != Time[0]) {
      G_time_156 = Time[0];
      return (1);
   }
   return (0);
}
