

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 Blue

extern int AllBars = 9;
extern int Otstup = 90;
extern double Per = 9.0;
int gi_92;
int gi_96;
int gi_100;
int gi_104;
double gd_108;
double g_high_116;
double g_low_124;
double g_ibuf_132[];
double g_ibuf_136[];

int init() {
   if (Bars < AllBars + Per || AllBars == 0) gi_96 = Bars - Per;
   else gi_96 = AllBars;
   IndicatorBuffers(2);
   IndicatorShortName("SHI_SilverTrendSig");
   SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID, 3);
   SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID, 3);
   SetIndexArrow(0, 159);
   SetIndexArrow(1, 159);
   SetIndexBuffer(0, g_ibuf_136);
   SetIndexBuffer(1, g_ibuf_132);
   SetIndexDrawBegin(0, Bars - gi_96);
   SetIndexDrawBegin(1, Bars - gi_96);
   ArrayInitialize(g_ibuf_132, 0.0);
   ArrayInitialize(g_ibuf_136, 0.0);
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   int l_ind_counted_0 = IndicatorCounted();
   if (l_ind_counted_0 < 0) return (-1);
   if (gi_96 > Bars - l_ind_counted_0) gi_96 = Bars - l_ind_counted_0;
   for (gi_92 = 1; gi_92 < gi_96; gi_92++) {
      gd_108 = 0;
      for (gi_100 = gi_92; gi_100 < gi_92 + 10; gi_100++) gd_108 += (gi_92 + 10 - gi_100) * (High[gi_100] - Low[gi_100]);
      gd_108 /= 55.0;
      g_high_116 = High[iHighest(NULL, 0, MODE_HIGH, Per, gi_92)];
      g_low_124 = Low[iLowest(NULL, 0, MODE_LOW, Per, gi_92)];
      if (Close[gi_92] < g_low_124 + (g_high_116 - g_low_124) * Otstup / 100.0 && gi_104 != -1) {
         g_ibuf_136[gi_92] = Low[gi_92] - gd_108 / 2.0;
         gi_104 = -1;
      }
      if (Close[gi_92] > g_high_116 - (g_high_116 - g_low_124) * Otstup / 100.0 && gi_104 != 1) {
         g_ibuf_132[gi_92] = High[gi_92] + gd_108 / 2.0;
         gi_104 = 1;
      }
   }
   return (0);
}