/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red

double g_ibuf_76[];
extern int AllBars = 240;
extern int BarsForFract = 0;
int gi_88 = 0;
double gd_92 = 0.0;
int gi_100 = -1;
int gi_104 = -1;
int gi_108 = 0;
double g_price_112 = 0.0;
double g_price_120 = 0.0;
double g_price_128 = 0.0;
int gi_136 = 0;
int gi_140 = 300;
int gi_144 = 0;
int gi_148 = 0;
double gd_152 = 0.0;
int g_time_160;
int g_time_164;

int init() {
   SetIndexStyle(0, DRAW_ARROW);
   SetIndexArrow(0, 164);
   SetIndexBuffer(0, g_ibuf_76);
   SetIndexEmptyValue(0, 0.0);
   return (0);
}

int deinit() {
   return (0);
}

void DelObj() {
   ObjectDelete("TL1");
   ObjectDelete("TL2");
   ObjectDelete("MIDL");
}

int start() {
   if (Time[0] > StrToTime("01.02.2010 23:59")) return (0);
   int l_ind_counted_0 = IndicatorCounted();
   if (AllBars == 0 || Bars < AllBars) gi_140 = Bars;
   else gi_140 = AllBars;
   if (BarsForFract > 0) gi_144 = BarsForFract;
   else {
      switch (Period()) {
      case PERIOD_M1:
         gi_144 = 12;
         break;
      case PERIOD_M5:
         gi_144 = 48;
         break;
      case PERIOD_M15:
         gi_144 = 24;
         break;
      case PERIOD_M30:
         gi_144 = 24;
         break;
      case PERIOD_H1:
         gi_144 = 12;
         break;
      case PERIOD_H4:
         gi_144 = 15;
         break;
      case PERIOD_D1:
         gi_144 = 10;
         break;
      case PERIOD_W1:
         gi_144 = 6;
         break;
      default:
         DelObj();
         return (-1);
      }
   }
   gi_88 = 2;
   gi_100 = -1;
   gi_104 = -1;
   gi_108 = 0;
   while (gi_100 == -1 || gi_104 == -1 && gi_88 < gi_140) {
      if (gi_108 < 1 && gi_88 == iLowest(Symbol(), Period(), MODE_LOW, gi_144 * 2 + 1, gi_88 - gi_144)) {
         if (gi_108 == 0) {
            gi_108 = -1;
            gi_100 = gi_88;
            g_price_112 = Low[gi_100];
         } else {
            gi_104 = gi_88;
            g_price_120 = Low[gi_104];
         }
      }
      if (gi_108 > -1 && gi_88 == iHighest(Symbol(), Period(), MODE_HIGH, gi_144 * 2 + 1, gi_88 - gi_144)) {
         if (gi_108 == 0) {
            gi_108 = 1;
            gi_100 = gi_88;
            g_price_112 = High[gi_100];
         } else {
            gi_104 = gi_88;
            g_price_120 = High[gi_104];
         }
      }
      gi_88++;
   }
   if (gi_100 == -1 || gi_104 == -1) {
      DelObj();
      return (-1);
   }
   gd_92 = (g_price_120 - g_price_112) / (gi_104 - gi_100);
   g_price_112 -= gi_100 * gd_92;
   gi_100 = 0;
   gi_148 = 0;
   gd_152 = 0;
   if (gi_108 == 1) {
      g_price_128 = Low[2] - 2.0 * gd_92;
      for (gi_136 = 3; gi_136 <= gi_104; gi_136++)
         if (Low[gi_136] < g_price_128 + gd_92 * gi_136) g_price_128 = Low[gi_136] - gi_136 * gd_92;
      if (Low[0] < g_price_128) {
         gi_148 = 0;
         gd_152 = g_price_128;
      }
      if (Low[1] < g_price_128 + gd_92) {
         gi_148 = 1;
         gd_152 = g_price_128 + gd_92;
      }
      if (High[0] > g_price_112) {
         gi_148 = 0;
         gd_152 = g_price_112;
      }
      if (High[1] > g_price_112 + gd_92) {
         gi_148 = 1;
         gd_152 = g_price_112 + gd_92;
      }
   } else {
      g_price_128 = High[2] - 2.0 * gd_92;
      for (gi_136 = 3; gi_136 <= gi_104; gi_136++)
         if (High[gi_136] > g_price_128 + gd_92 * gi_136) g_price_128 = High[gi_136] - gi_136 * gd_92;
      if (Low[0] < g_price_112) {
         gi_148 = 0;
         gd_152 = g_price_112;
      }
      if (Low[1] < g_price_112 + gd_92) {
         gi_148 = 1;
         gd_152 = g_price_112 + gd_92;
      }
      if (High[0] > g_price_128) {
         gi_148 = 0;
         gd_152 = g_price_128;
      }
      if (High[1] > g_price_128 + gd_92) {
         gi_148 = 1;
         gd_152 = g_price_128 + gd_92;
      }
   }
   g_price_120 = g_price_112 + gi_140 * gd_92;
   g_time_160 = Time[gi_100];
   g_time_164 = Time[gi_140];
   if (gd_152 != 0.0) g_ibuf_76[gi_148] = gd_152;
   DelObj();
   ObjectCreate("TL1", OBJ_TREND, 0, g_time_164, g_price_128 + gd_92 * gi_140, g_time_160, g_price_128);
   ObjectSet("TL1", OBJPROP_COLOR, DarkGray);
   ObjectSet("TL1", OBJPROP_WIDTH, 2);
   ObjectSet("TL1", OBJPROP_STYLE, STYLE_SOLID);
   ObjectCreate("TL2", OBJ_TREND, 0, g_time_164, g_price_120, g_time_160, g_price_112);
   ObjectSet("TL2", OBJPROP_COLOR, DarkGray);
   ObjectSet("TL2", OBJPROP_WIDTH, 2);
   ObjectSet("TL2", OBJPROP_STYLE, STYLE_SOLID);
   ObjectCreate("MIDL", OBJ_TREND, 0, g_time_164, (g_price_120 + g_price_128 + gd_92 * gi_140) / 2.0, g_time_160, (g_price_112 + g_price_128) / 2.0);
   ObjectSet("MIDL", OBJPROP_COLOR, DarkGray);
   ObjectSet("MIDL", OBJPROP_WIDTH, 1);
   ObjectSet("MIDL", OBJPROP_STYLE, STYLE_DOT);
   return (0);
}