#property indicator_chart_window
#property indicator_buffers 5
#property indicator_color1 CLR_NONE
#property indicator_color2 CLR_NONE
#property indicator_color3 CLR_NONE
#property indicator_color4 CLR_NONE
#property indicator_color5 CLR_NONE

extern color LRCColor = Red;
double Gd_80;
double Gd_88;
double Gd_96;
double Gd_104;
int G_index_112;
int Gi_116;
int Gi_120;
int Gi_124;
int Gi_128;
int Gi_132;
int G_count_136;
int Gi_140;
int Gi_144;
double Gd_148;
double Gd_156;
double Gd_172;
double Gd_180;
int G_time_188;
int G_time_192;
double G_price_196;
double G_price_204;
double G_ibuf_212[];
double G_ibuf_216[];
double G_ibuf_220[];
double G_ibuf_224[];
double G_ibuf_228[];

int init() {
   IndicatorBuffers(6);
   SetIndexStyle(0, DRAW_NONE);
   SetIndexBuffer(0, G_ibuf_212);
   SetIndexStyle(1, DRAW_NONE);
   SetIndexBuffer(1, G_ibuf_216);
   SetIndexStyle(2, DRAW_NONE);
   SetIndexBuffer(2, G_ibuf_220);
   SetIndexStyle(3, DRAW_NONE);
   SetIndexBuffer(3, G_ibuf_224);
   SetIndexStyle(4, DRAW_NONE);
   SetIndexBuffer(4, G_ibuf_228);
   return (0);
}

int deinit() {
   ObjectDelete("DTL1");
   ObjectDelete("DQL1");
   ObjectDelete("DLRC");
   ObjectDelete("DTL2");
   ObjectDelete("DQL4");
   return (0);
}

int start() {
   int count_8;
   bool Li_12 = FALSE;
   for (int Li_16 = Li_12; Li_16 >= 0; Li_16--) {
      G_index_112 = 0;
      for (int index_4 = Li_16; index_4 <= 24; index_4++) {
         if (TimeHour(Time[index_4]) == 0) {
            Gi_116 = 1;
            Gi_128 = index_4;
            break;
         }
      }
      for (index_4 = Li_16; index_4 <= 744; index_4++) {
         if (TimeHour(Time[index_4]) == 0) {
            if (TimeDay(Time[index_4]) == 1) {
               if (index_4 == Li_16) {
                  Gi_124 = 48;
                  G_index_112 = 3;
                  Gi_120 = 3;
                  break;
               }
               Gi_124 = index_4;
               Gi_120 = G_index_112 - Gi_116 + 1;
               break;
            }
            G_index_112++;
         }
      }
      G_count_136 = 0;
      Gi_140 = 0;
      Gd_172 = 0;
      Gi_144 = 0;
      Gd_180 = 0;
      Gi_132 = Gi_120;
      for (int Li_0 = G_index_112; Li_0 >= Gi_116; Li_0--) {
         G_count_136++;
         Gi_140 += G_count_136;
         Gd_172 += iClose(NULL, PERIOD_D1, Li_0);
         Gi_144 += G_count_136 * G_count_136;
         Gd_180 += G_count_136 * iClose(NULL, PERIOD_D1, Li_0);
      }
      Gd_156 = (Gi_132 * Gd_180 - Gi_140 * Gd_172) / (Gi_132 * Gi_144 - Gi_140 * Gi_140);
      Gd_148 = (Gd_172 - Gd_156 * Gi_140) / Gi_132;
      Gd_96 = 0;
      Gd_104 = 0;
      for (Li_0 = G_index_112; Li_0 >= Gi_116; Li_0--) {
         Gd_96 = iClose(NULL, PERIOD_D1, Li_0) - Gd_172 / Gi_132;
         Gd_104 += Gd_96 * Gd_96;
      }
      Gd_88 = MathSqrt(Gd_104 / Gi_132);
      index_4 = 0;
      for (Li_0 = G_index_112; Li_0 >= Gi_116; Li_0--) {
         index_4++;
         G_ibuf_220[Li_0] = Gd_148 + Gd_156 * index_4;
      }
      index_4 = 0;
      count_8 = 0;
      while (index_4 == 0) {
         for (Li_0 = G_index_112; Li_0 >= Gi_116; Li_0--)
            if (iClose(NULL, PERIOD_D1, Li_0) > G_ibuf_220[Li_0] + Gd_88 || iClose(NULL, PERIOD_D1, Li_0) < G_ibuf_220[Li_0] - Gd_88) count_8++;
         if (count_8 > 0) {
            Gd_88 += 1.0 * Point;
            count_8 = 0;
         } else index_4++;
      }
      Gd_80 = Gd_88 / 2.0;
      index_4 = 0;
      for (Li_0 = G_index_112; Li_0 >= Li_16; Li_0--) {
         index_4++;
         G_ibuf_220[Li_0] = Gd_148 + Gd_156 * index_4;
         G_ibuf_212[Li_0] = G_ibuf_220[Li_0] + Gd_88;
         G_ibuf_216[Li_0] = G_ibuf_220[Li_0] + Gd_80;
         G_ibuf_224[Li_0] = G_ibuf_220[Li_0] - Gd_80;
         G_ibuf_228[Li_0] = G_ibuf_220[Li_0] - Gd_88;
      }
      G_time_188 = Time[Gi_124];
      G_time_192 = Time[Gi_128];
      G_price_196 = G_ibuf_220[G_index_112];
      G_price_204 = G_ibuf_220[Gi_116];
      ObjectDelete("DTL1");
      ObjectDelete("DQL1");
      ObjectDelete("DLRC");
      ObjectDelete("DTL2");
      ObjectDelete("DQL4");
      ObjectCreate("DTL1", OBJ_TREND, 0, G_time_188, G_price_196 + Gd_88, G_time_192, G_price_204 + Gd_88);
      ObjectSet("DTL1", OBJPROP_COLOR, LRCColor);
      ObjectSet("DTL1", OBJPROP_WIDTH, 1);
      ObjectSet("DTL1", OBJPROP_STYLE, STYLE_SOLID);
      ObjectCreate("DQL1", OBJ_TREND, 0, G_time_188, G_price_196 + Gd_80, G_time_192, G_price_204 + Gd_80);
      ObjectSet("DQL1", OBJPROP_COLOR, LRCColor);
      ObjectSet("DQL1", OBJPROP_WIDTH, 1);
      ObjectSet("DQL1", OBJPROP_STYLE, STYLE_DOT);
      ObjectCreate("DLRC", OBJ_TREND, 0, G_time_188, G_price_196, G_time_192, G_price_204);
      ObjectSet("DLRC", OBJPROP_COLOR, LRCColor);
      ObjectSet("DLRC", OBJPROP_WIDTH, 1);
      ObjectSet("DLRC", OBJPROP_STYLE, STYLE_SOLID);
      ObjectCreate("DQL4", OBJ_TREND, 0, G_time_188, G_price_196 - Gd_80, G_time_192, G_price_204 - Gd_80);
      ObjectSet("DQL4", OBJPROP_COLOR, LRCColor);
      ObjectSet("DQL4", OBJPROP_WIDTH, 1);
      ObjectSet("DQL4", OBJPROP_STYLE, STYLE_DOT);
      ObjectCreate("DTL2", OBJ_TREND, 0, G_time_188, G_price_196 - Gd_88, G_time_192, G_price_204 - Gd_88);
      ObjectSet("DTL2", OBJPROP_COLOR, LRCColor);
      ObjectSet("DTL2", OBJPROP_WIDTH, 1);
      ObjectSet("DTL2", OBJPROP_STYLE, STYLE_SOLID);
   }
   return (0);
}
