#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "www.forex-tsd.com"

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red

double gd_76 = 5000.0;
double gd_unused_84 = 0.0;
double g_ibuf_92[];
double g_ibuf_96[];
double gd_100;

int init() {
   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexBuffer(0, g_ibuf_92);
   SetIndexEmptyValue(0, 0.0);
   SetIndexStyle(1, DRAW_HISTOGRAM);
   SetIndexBuffer(1, g_ibuf_96);
   SetIndexEmptyValue(1, 0.0);
   gd_100 = MarketInfo(Symbol(), MODE_SPREAD) * Point;
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   double lda_72[100];
   string ls_0 = "2018.10.10";
   int l_str2time_8 = StrToTime(ls_0);
   int l_ind_counted_20 = IndicatorCounted();
   int li_24 = 7;
   double ld_28 = 0.7;
   int l_bars_36 = 2000;
   int li_40 = 0;
   bool li_44 = TRUE;
   double ld_48 = 0;
   double ld_56 = 0;
   double ld_64 = 0;
   int l_index_76 = 0;
   double ld_80 = 0;
   int l_index_88 = 0;
   double ld_92 = 0;
   double ld_100 = 0;
   double ld_108 = 0;
   int li_116 = 0;
   int li_120 = 0;
   double ld_124 = 0;
   double ld_132 = 2;
   double ld_unused_140 = 10;
   double ld_unused_148 = 0;
   double ld_unused_156 = 0;
   double ld_unused_164 = 0;
   double ld_unused_172 = 0;
   double ld_unused_180 = 0;
   double ld_unused_188 = 0;
   double ld_unused_196 = 0;
   double ld_unused_204 = 0;
   double ld_unused_212 = 0;
   double ld_unused_220 = 0;
   double ld_unused_228 = 0;
   double ld_unused_236 = 0;
   double ld_unused_244 = 0;
   double ld_unused_252 = 0;
   double ld_unused_260 = 0;
   double ld_unused_268 = 0;
   double ld_unused_276 = 0;
   double ld_unused_284 = 0;
   double ld_unused_292 = 0;
   double ld_unused_300 = 0;
   double ld_unused_308 = 0;
   double ld_unused_316 = 0;
   double ld_unused_324 = 0;
   double ld_unused_332 = 0;
   if (Bars < gd_76) l_bars_36 = Bars;
   else l_bars_36 = gd_76;
   if (Close[l_bars_36 - 2] > Close[l_bars_36 - 1]) li_44 = TRUE;
   else li_44 = FALSE;
   ld_48 = Close[l_bars_36 - 2];
   for (li_40 = l_bars_36 - 3; li_40 >= 0; li_40--) {
      ld_64 = gd_100 + High[li_40] - Low[li_40];
      if (MathAbs(gd_100 + High[li_40] - (Close[li_40 + 1])) > ld_64) ld_64 = MathAbs(gd_100 + High[li_40] - (Close[li_40 + 1]));
      if (MathAbs(Low[li_40] - (Close[li_40 + 1])) > ld_64) ld_64 = MathAbs(Low[li_40] - (Close[li_40 + 1]));
      if (li_40 == l_bars_36 - 3) for (l_index_88 = 0; l_index_88 <= li_24 - 1; l_index_88++) lda_72[l_index_88] = ld_64;
      lda_72[l_index_76] = ld_64;
      ld_80 = 0;
      ld_92 = li_24;
      li_120 = l_index_76;
      for (l_index_88 = 0; l_index_88 <= li_24 - 1; l_index_88++) {
         ld_80 += lda_72[li_120] * ld_92;
         ld_92 -= 1.0;
         li_120--;
         if (li_120 == -1) li_120 = li_24 - 1;
      }
      ld_80 = 2.0 * ld_80 / (li_24 * (li_24 + 1.0));
      l_index_76++;
      if (l_index_76 == li_24) l_index_76 = 0;
      ld_56 = ld_28 * ld_80;
      if (li_44 && Low[li_40] < ld_48 - ld_56) {
         li_44 = FALSE;
         ld_48 = gd_100 + High[li_40];
      }
      if (!li_44 && gd_100 + High[li_40] > ld_48 + ld_56) {
         li_44 = TRUE;
         ld_48 = Low[li_40];
      }
      if (li_44 && Low[li_40] > ld_48) ld_48 = Low[li_40];
      if (!li_44 && gd_100 + High[li_40] < ld_48) ld_48 = gd_100 + High[li_40];
      ld_124 = iATR(NULL, 0, 10, li_40) + gd_100 / 10.0;
      if (li_44) {
         if (Low[li_40] - ld_124 * ld_132 < ld_100 && ld_100 != 0.0) ld_108 = ld_100;
         else ld_108 = Low[li_40] - ld_124 * ld_132 / 3.0;
         if (li_116 == 2) ld_108 = Low[li_40] - ld_124 * ld_132 / 3.0;
         g_ibuf_92[li_40] = ld_108;
         g_ibuf_96[li_40] = 0;
         ld_100 = ld_108;
         li_116 = 1;
      } else {
         if (gd_100 + High[li_40] + ld_124 * ld_132 > ld_100 && ld_100 != 0.0) ld_108 = ld_100;
         else ld_108 = gd_100 + High[li_40] + ld_124 * ld_132 / 3.0;
         if (li_116 == 1) ld_108 = gd_100 + High[li_40] + ld_124 * ld_132 / 3.0;
         g_ibuf_92[li_40] = 0;
         g_ibuf_96[li_40] = ld_108;
         ld_100 = ld_108;
         li_116 = 2;
      }
   }
   return (0);
}