/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "SilverTrend rewritten by CrazyChart"
#property link      "http://viac.ru/ "

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Blue
#property indicator_color2 Red

extern int CountBars = 16000;
extern int SSP = 6;
extern double Kmin = 1.6;
extern double Kmax = 50.6;
extern int Filter = 10;
extern bool gAlert = TRUE;
double g_ibuf_108[];
double g_ibuf_112[];
bool gi_124 = FALSE;
bool gi_128 = FALSE;

int init() {
   SetIndexStyle(0, DRAW_LINE, STYLE_SOLID, 2);
   SetIndexBuffer(0, g_ibuf_108);
   SetIndexStyle(1, DRAW_LINE, STYLE_SOLID, 2);
   SetIndexBuffer(1, g_ibuf_112);
   if (CountBars >= Bars) CountBars = Bars;
   SetIndexDrawBegin(0, Bars - CountBars + SSP);
   SetIndexDrawBegin(1, Bars - CountBars + SSP);
   return (0);
}

int deinit() {
   return (0);
}

int start() {
   double ld_16;
   double ld_24;
   double ld_40;
   double ld_48;
   double ld_56;
   double ld_64;
   int l_ind_counted_12 = IndicatorCounted();
   if (Bars <= SSP + 1) return (0);
   if (l_ind_counted_12 < SSP + 1) {
      for (int li_0 = 1; li_0 <= SSP; li_0++) g_ibuf_108[CountBars - li_0] = 0.0;
      for (li_0 = 1; li_0 <= SSP; li_0++) g_ibuf_112[CountBars - li_0] = 0.0;
   }
   for (li_0 = CountBars - SSP; li_0 >= 0; li_0--) {
      ld_16 = High[iHighest(NULL, 0, MODE_HIGH, SSP, li_0 - SSP + 1)];
      ld_24 = Low[iLowest(NULL, 0, MODE_LOW, SSP, li_0 - SSP + 1)];
      ld_56 = NormalizeDouble(ld_24 - (ld_16 - ld_24) * Kmin / 100.0, Digits);
      ld_64 = NormalizeDouble(ld_16 - (ld_16 - ld_24) * Kmax / 100.0, Digits);
      g_ibuf_108[li_0 - SSP + 6] = ld_64;
      g_ibuf_112[li_0 - SSP - 1] = ld_64;
      ld_40 = g_ibuf_108[0];
      ld_48 = g_ibuf_112[0];
      if (ld_40 > ld_48) {
         Comment(Symbol() + " buy ");
         if (gAlert == TRUE && gi_128 == FALSE) {
            PlaySound("alert.wav");
            Alert(Symbol() + " Buy signal at " + DoubleToStr(ld_40, Digits) + " on " + Period() + " minute chart");
            gi_128 = TRUE;
            gi_124 = FALSE;
         }
      }
      if (ld_40 < ld_48) {
         Comment(Symbol() + " sell ");
         if (gAlert == TRUE && gi_124 == FALSE) {
            PlaySound("alert.wav");
            Alert(Symbol() + " Sell signal at " + DoubleToStr(ld_48, Digits) + " on " + Period() + " minute chart");
            gi_128 = FALSE;
            gi_124 = TRUE;
         }
      }
   }
   return (0);
}
