#property indicator_separate_window
#property indicator_minimum -1.3
#property indicator_maximum 1.3
#property indicator_buffers 3
#property indicator_color1 Lime
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_level1 0.9
#property indicator_level2 -0.9
#property indicator_level3 0.75
#property indicator_level4 -0.75

extern int TimeFrame = 5;
extern string w1 = "Имя обьектов на графике";
extern string name = "OBJ";
extern string g1 = "Отоброжать сигнал на графике?";
extern bool vis = TRUE;
extern string c1 = "Показать историю сигналов?";
extern bool his = FALSE;
extern string a1 = "Звуковой сигнал?";
extern bool sou = FALSE;
extern color Buy = Blue;
extern color Sell = Red;
extern int SnakeRange = 3;
extern int FilterPeriod = 21;
extern double MartFiltr = 2.0;
extern int PriceConst = 6;
double Gl_ibuf_160[];
double Gl_ibuf_164[];
double Gld_unused_168;
double Gl_ibuf_176[];

// a1
int init() {
// Блок вывода алерта о несоответствии таймфрейма (не нужен)
//   if (TimeFrame != 0) {
//      if (TimeFrame < Period()) {
//         Alert("Настраиваемый таймфрейм должен быть больше текущего или равен 0");
//         return (0);
//      }
//   }
   bool Lci_0 = FALSE;
   switch (TimeFrame) {
   case 0:
      Lci_0 = TRUE;
      break;
   case 1:
      Lci_0 = TRUE;
      break;
   case 5:
      Lci_0 = TRUE;
      break;
   case 15:
      Lci_0 = TRUE;
      break;
   case 30:
      Lci_0 = TRUE;
      break;
   case 60:
      Lci_0 = TRUE;
      break;
   case 240:
      Lci_0 = TRUE;
      break;
   case 1440:
      Lci_0 = TRUE;
      break;
   case 10080:
      Lci_0 = TRUE;
      break;
   case 43200:
      Lci_0 = TRUE;
   }
   if (Lci_0 == FALSE) {
      Alert("Вы ввели некорректную цифру таймфрейма");
      return (0);
   }
   SetIndexBuffer(0, Gl_ibuf_160);
   SetIndexStyle(0, DRAW_LINE);
   if (Digits == 5 || Digits == 3) Gld_unused_168 = 10;
   else Gld_unused_168 = 1;
   SetIndexStyle(1, DRAW_ARROW, EMPTY, 0);
   SetIndexArrow(1, 234);
   SetIndexBuffer(1, Gl_ibuf_164);
   SetIndexStyle(2, DRAW_ARROW, EMPTY, 0);
   SetIndexArrow(2, 233);
   SetIndexBuffer(2, Gl_ibuf_176);
   return (0);
}

// a2
int deinit() {
   f0_1();
   return (0);
}

// a3
int start() {
   int Lci_4;
   datetime time_8;
   int shift_12;
   bool Lci_20;
   int ind_counted_0 = IndicatorCounted();
   if (TimeFrame > 0) Lci_4 = Bars - ind_counted_0 + TimeFrame / Period();
   else Lci_4 = Bars - ind_counted_0 - 1;
   if (Lci_4 == 0) return (0);
   for (int Lci_16 = Lci_4; Lci_16 >= 0; Lci_16--) {
      Lci_20 = Lci_16;
      time_8 = Time[Lci_16];
      shift_12 = iBarShift(NULL, TimeFrame, time_8, FALSE);
      Gl_ibuf_160[Lci_16] = iCustom(NULL, TimeFrame, "SSRC", SnakeRange, FilterPeriod, MartFiltr, PriceConst, 0, shift_12);
      if (vis == TRUE && Gl_ibuf_160[Lci_16 + 1] > -0.9 && Gl_ibuf_160[Lci_16 + 2] < -0.9) {
         Gl_ibuf_176[Lci_16] = Gl_ibuf_160[Lci_16];
         if (his == FALSE) Lci_20 = FALSE;
         f0_0(Lci_20 + name, 0, Time[Lci_16], Low[Lci_16] - 5.0 * Point, 233, Buy, 1);
         if (ObjectFind(Lci_20 + name) == 0 && sou == TRUE) PlaySound("expert");
      }
      if (vis == TRUE && Gl_ibuf_160[Lci_16] < 0.9 && Gl_ibuf_160[Lci_16 + 1] > 0.9) {
         Gl_ibuf_164[Lci_16] = Gl_ibuf_160[Lci_16];
         if (his == FALSE) Lci_20 = FALSE;
         f0_0(Lci_20 + name + 1, 0, Time[Lci_16], High[Lci_16] + 5.0 * Point, 234, Sell, 1);
         if (ObjectFind(Lci_20 + name + 1) == 0 && sou == TRUE) PlaySound("expert");
      }
      if (vis == TRUE && Gl_ibuf_160[Lci_16 + 1] > -0.75 && Gl_ibuf_160[Lci_16 + 2] < -0.75) {
         Gl_ibuf_176[Lci_16] = Gl_ibuf_160[Lci_16];
         if (his == FALSE) Lci_20 = FALSE;
         f0_0(Lci_20 + name + 2, 0, Time[Lci_16], Low[Lci_16] - 5.0 * Point, 233, Buy, 1);
         if (ObjectFind(Lci_20 + name + 2) == 0 && sou == TRUE) PlaySound("expert");
      }
      if (vis == TRUE && Gl_ibuf_160[Lci_16] < 0.75 && Gl_ibuf_160[Lci_16 + 1] > 0.75) {
         Gl_ibuf_164[Lci_16] = Gl_ibuf_160[Lci_16];
         if (his == FALSE) Lci_20 = FALSE;
         f0_0(Lci_20 + name + 3, 0, Time[Lci_16], High[Lci_16] + 5.0 * Point, 234, Sell, 1);
         if (ObjectFind(Lci_20 + name + 3) == 0 && sou == TRUE) PlaySound("expert");
      }
      if (vis == FALSE && Gl_ibuf_160[Lci_16 + 1] > -0.9 && Gl_ibuf_160[Lci_16 + 2] < -0.9) {
         Gl_ibuf_176[Lci_16] = Gl_ibuf_160[Lci_16];
         if (sou == TRUE) PlaySound("expert");
      }
      if (vis == FALSE && Gl_ibuf_160[Lci_16] < 0.9 && Gl_ibuf_160[Lci_16 + 1] > 0.9) {
         Gl_ibuf_164[Lci_16] = Gl_ibuf_160[Lci_16];
         if (sou == TRUE) PlaySound("expert");
      }
      if (vis == FALSE && Gl_ibuf_160[Lci_16 + 1] > -0.75 && Gl_ibuf_160[Lci_16 + 2] < -0.75) {
         Gl_ibuf_176[Lci_16] = Gl_ibuf_160[Lci_16];
         if (sou == TRUE) PlaySound("expert");
      }
      if (vis == FALSE && Gl_ibuf_160[Lci_16] < 0.75 && Gl_ibuf_160[Lci_16 + 1] > 0.75) {
         Gl_ibuf_164[Lci_16] = Gl_ibuf_160[Lci_16];
         if (sou == TRUE) PlaySound("expert");
      }
   }
   return (0);
}

// a4
void f0_0(string Ar_name_0, int Ar_window_8, int Ar_datetime_12, double Ard_16, int Ari_24, color Ar_color_28, int Ar_width_32 = 1) {
   ObjectCreate(Ar_name_0, OBJ_ARROW, Ar_window_8, 0, 0);
   ObjectSet(Ar_name_0, OBJPROP_TIME1, Ar_datetime_12);
   ObjectSet(Ar_name_0, OBJPROP_PRICE1, Ard_16);
   ObjectSet(Ar_name_0, OBJPROP_ARROWCODE, Ari_24);
   ObjectSet(Ar_name_0, OBJPROP_COLOR, Ar_color_28);
   ObjectSet(Ar_name_0, OBJPROP_WIDTH, Ar_width_32);
}

// a5
void f0_1() {
   for (int Lci_0 = 15000; Lci_0 >= -1; Lci_0--) {
      ObjectDelete(Lci_0 + "OBGECT");
      ObjectDelete(Lci_0 + "OBGEC");
      ObjectDelete(Lci_0 + "OBGE");
      ObjectDelete(Lci_0 + "OBG");
      ObjectDelete(Lci_0 + name);
      ObjectDelete(Lci_0 + name + 1);
      ObjectDelete(Lci_0 + name + 2);
      ObjectDelete(Lci_0 + name + 3);
   }
}