//+------------------------------------------------------------------+
//|                                                      ProjectName |
//|                                      Copyright 2018, CompanyName |
//|                                       http://www.companyname.net |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 White
#property indicator_color2 Aqua
#property indicator_color3 Yellow
#property indicator_color4 Black
#property indicator_color5 Aqua
#property indicator_color6 Yellow
#property indicator_color7 Black

extern int period_stdev = 144;
extern double distance = 2.382;
int shift = 0;

double G_ibuf_92[];
double G_ibuf_96[];
double G_ibuf_100[];
double G_ibuf_104[];
double G_ibuf_108[];
double G_ibuf_112[];
double G_ibuf_116[];
double Gda_120[20][20];
double Gda_124[20];
double Gda_128[20];
double Gda_132[20];
int Gi_136;
int Gi_140;
int Gi_144;
int Gi_148;
int Gi_152;
int Gi_156;
int Gi_160;
double Gd_164;
double Gd_172;
double Gd_180;
double Gd_188;
double Gd_196;

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int init()
  {
   SetIndexStyle(0, DRAW_LINE);
   SetIndexBuffer(0, G_ibuf_92);
   SetIndexBuffer(1, G_ibuf_96);
   SetIndexBuffer(2, G_ibuf_100);
   SetIndexBuffer(3, G_ibuf_104);
   SetIndexBuffer(4, G_ibuf_108);
   SetIndexBuffer(5, G_ibuf_112);
   SetIndexBuffer(6, G_ibuf_116);
   return (0);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int deinit()
  {

   ObjectDelete("REG");
   ObjectDelete("X1");
   ObjectDelete("X2");
   ObjectDelete("X3");
   ObjectDelete("Z1");
   ObjectDelete("Z2");
   ObjectDelete("Z3");
   return (0);
  }

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
int start()
  {
   datetime time_0 = 0;
   SetIndexDrawBegin(0, Bars - period_stdev - 1);
   SetIndexDrawBegin(1, Bars - period_stdev - 1);
   SetIndexDrawBegin(2, Bars - period_stdev - 1);
   SetIndexDrawBegin(3, Bars - period_stdev - 1);
   SetIndexDrawBegin(4, Bars - period_stdev - 1);
   SetIndexDrawBegin(5, Bars - period_stdev - 1);
   SetIndexDrawBegin(6, Bars - period_stdev - 1);
   if(time_0 != Time[0])
     {
      ObjectDelete("REG");
      ObjectDelete("X1");
      ObjectDelete("X2");
      ObjectDelete("X3");
      ObjectDelete("Z1");
      ObjectDelete("Z2");
      ObjectDelete("Z3");
      time_0 = Time[0];
     }
   Gi_152 = shift + 1;
   Gda_124[1] = period_stdev + 1;
   for(Gi_160 = 1; Gi_160 <= Gi_152 * 2 - 2; Gi_160++)
     {
      Gd_164 = 0;
      for(Gi_156 = 0; Gi_156 <= period_stdev; Gi_156++)
         Gd_164 += MathPow(Gi_156, Gi_160);
      Gda_124[Gi_160 + 1] = Gd_164;
     }
   for(Gi_160 = 1; Gi_160 <= Gi_152; Gi_160++)
     {
      Gd_164 = 0;
      for(Gi_156 = 0; Gi_156 <= period_stdev; Gi_156++)
        {
         if(Gi_160 == 1)
            Gd_164 += (High[Gi_156] + Low[Gi_156]) / 2.0;
         else
            Gd_164 += (High[Gi_156] + Low[Gi_156]) / 2.0 * MathPow(Gi_156, Gi_160 - 1);
        }
      Gda_128[Gi_160] = Gd_164;
     }
   for(Gi_140 = 1; Gi_140 <= Gi_152; Gi_140++)
     {
      for(Gi_136 = 1; Gi_136 <= Gi_152; Gi_136++)
        {
         Gi_144 = Gi_136 + Gi_140 - 1;
         Gda_120[Gi_136][Gi_140] = Gda_124[Gi_144];
        }
     }
   for(Gi_144 = 1; Gi_144 <= Gi_152 - 1; Gi_144++)
     {
      Gi_148 = 0;
      Gd_188 = 0;
      for(Gi_136 = Gi_144; Gi_136 <= Gi_152; Gi_136++)
        {
         if(MathAbs(Gda_120[Gi_136][Gi_144]) > Gd_188)
           {
            Gd_188 = MathAbs(Gda_120[Gi_136][Gi_144]);
            Gi_148 = Gi_136;
           }
        }
      if(Gi_148 == 0)
         return (0);
      if(Gi_148 != Gi_144)
        {
         for(Gi_140 = 1; Gi_140 <= Gi_152; Gi_140++)
           {
            Gd_196 = Gda_120[Gi_144][Gi_140];
            Gda_120[Gi_144][Gi_140] = Gda_120[Gi_148][Gi_140];
            Gda_120[Gi_148][Gi_140] = Gd_196;
           }
         Gd_196 = Gda_128[Gi_144];
         Gda_128[Gi_144] = Gda_128[Gi_148];
         Gda_128[Gi_148] = Gd_196;
        }
      for(Gi_136 = Gi_144 + 1; Gi_136 <= Gi_152; Gi_136++)
        {
         Gd_180 = Gda_120[Gi_136][Gi_144] / Gda_120[Gi_144][Gi_144];
         for(Gi_140 = 1; Gi_140 <= Gi_152; Gi_140++)
           {
            if(Gi_140 == Gi_144)
               Gda_120[Gi_136][Gi_140] = 0;
            else
               Gda_120[Gi_136][Gi_140] = Gda_120[Gi_136][Gi_140] - Gd_180 * Gda_120[Gi_144][Gi_140];
           }
         Gda_128[Gi_136] = Gda_128[Gi_136] - Gd_180 * Gda_128[Gi_144];
        }
     }
   Gda_132[Gi_152] = Gda_128[Gi_152] / Gda_120[Gi_152][Gi_152];
   for(Gi_136 = Gi_152 - 1; Gi_136 >= 1; Gi_136--)
     {
      Gd_196 = 0;
      for(Gi_140 = 1; Gi_140 <= Gi_152 - Gi_136; Gi_140++)
        {
         Gd_196 += (Gda_120[Gi_136][Gi_136 + Gi_140]) * (Gda_132[Gi_136 + Gi_140]);
         Gda_132[Gi_136] = 1 / Gda_120[Gi_136][Gi_136] * (Gda_128[Gi_136] - Gd_196);
        }
     }
   for(Gi_156 = 0; Gi_156 <= period_stdev; Gi_156++)
     {
      Gd_164 = 0;
      for(Gi_144 = 1; Gi_144 <= shift; Gi_144++)
         Gd_164 += (Gda_132[Gi_144 + 1]) * MathPow(Gi_156, Gi_144);
      G_ibuf_92[Gi_156] = Gda_132[1] + Gd_164;
     }
   Gd_172 = iStdDev(NULL, 0, period_stdev, 0, MODE_SMA, PRICE_HIGH, 0) * distance;
   for(Gi_156 = 0; Gi_156 <= period_stdev; Gi_156++)
     {
      G_ibuf_104[Gi_156] = G_ibuf_92[Gi_156] + Gd_172;
      G_ibuf_100[Gi_156] = G_ibuf_92[Gi_156] + (G_ibuf_104[Gi_156] - G_ibuf_92[Gi_156]) / 1.382;
      G_ibuf_96[Gi_156] = G_ibuf_92[Gi_156] + (G_ibuf_100[Gi_156] - G_ibuf_92[Gi_156]) / 1.618;
      G_ibuf_116[Gi_156] = G_ibuf_92[Gi_156] - Gd_172;
      G_ibuf_112[Gi_156] = G_ibuf_92[Gi_156] - (G_ibuf_92[Gi_156] - G_ibuf_116[Gi_156]) / 1.382;
      G_ibuf_108[Gi_156] = G_ibuf_92[Gi_156] - (G_ibuf_92[Gi_156] - G_ibuf_112[Gi_156]) / 1.618;
     }
   ObjectCreate("REG", OBJ_ARROW, 0, Time[0], G_ibuf_92[0]);
   ObjectSet("REG", OBJPROP_ARROWCODE, SYMBOL_CHECKSIGN);
   ObjectSet("REG", OBJPROP_COLOR, White);
   ObjectCreate("X1", OBJ_ARROW, 0, Time[0], G_ibuf_96[0]);
   ObjectSet("X1", OBJPROP_ARROWCODE, SYMBOL_THUMBSDOWN);
   ObjectSet("X1", OBJPROP_COLOR, Red);
   ObjectCreate("X2", OBJ_ARROW, 0, Time[0], G_ibuf_100[0]);
   ObjectSet("X2", OBJPROP_ARROWCODE, SYMBOL_ARROWDOWN);
   ObjectSet("X2", OBJPROP_COLOR, Red);
   ObjectCreate("Z1", OBJ_ARROW, 0, Time[0], G_ibuf_108[0]);
   ObjectSet("Z1", OBJPROP_ARROWCODE, SYMBOL_THUMBSUP);
   ObjectSet("Z1", OBJPROP_COLOR, Blue);
   ObjectCreate("Z2", OBJ_ARROW, 0, Time[0], G_ibuf_112[0]);
   ObjectSet("Z2", OBJPROP_ARROWCODE, SYMBOL_ARROWUP);
   ObjectSet("Z2", OBJPROP_COLOR, Blue);
   return (0);
  }
//+------------------------------------------------------------------+
