//*******************************************************************//
#property description "Платим за каждую сделку Forex из 30+ брокеров"
#property description "Перед Вами новый инструмент трейдера ,Сервис, осуществляющий мгновенный возврат до 95% от спреда (рибейт) более чем в 30 самых надежных и проверенных брокеров с мировыми именами_"
#property description  "http://fxcash_ru/?id=X53657"
#property description  "http://fxcash_ru/?id=fxgeneral"
#property copyright "http://fxcash_ru/?id=_spred    "
#property link "http://www_roboforex_ru/?a=bywt "
//*******************************************************************//

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Red
#property indicator_color2 SkyBlue

#include <WinUser32.mqh>

extern int Limit = 1500;
extern bool ShowConfAlert = TRUE;
extern bool SendmailConfAlert = TRUE;
extern string OtherTimeFrames = "Select below 0=current tf,1,5,15,30,60,240,1440,10080,43200";
extern int select_other_tf_to_show = 0;
extern int AmountBarsToScan = 10;
int Gi_104 = 1;
int Gi_108 = 50;
int Gi_112 = 12;
int Gi_116 = 3;
int Gi_120 = 0;
extern int eintPeriod1 = 20;
extern int eintPeriod2 = 55;
extern double edblHigh1 = 0.4;
extern double edblLow1 = -0.4;
extern int atrPeriod = 100;
int Gi_152 = 16777215;
int Gi_156 = 1;
int Gi_160 = 25;
int Gi_164 = 3;
int Gi_168 = 14;
int Gi_172 = 11;
int Gi_176 = 1;
int Gi_180 = 1;
int Gi_184 = 3;
double G_ibuf_188[];
double G_ibuf_192[];
double G_ibuf_196[];
double G_ibuf_200[];
double G_ibuf_204[];
double G_ibuf_208[];
int Gi_216;
int G_datetime_220;
datetime G_time_228;
int Gi_232 = 0;
string Gs_240 = "LRFF-MV-TmaSlope-v.8-arrow4b_v1.2";

// E37F0136AA3FFAF149B351F6A4C948E9
int init() {
   int Li_4;
   IndicatorBuffers(6);
   SetIndexBuffer(0, G_ibuf_188);
   SetIndexBuffer(1, G_ibuf_192);
   SetIndexBuffer(2, G_ibuf_196);
   SetIndexBuffer(3, G_ibuf_200);
   SetIndexBuffer(4, G_ibuf_204);
   SetIndexBuffer(5, G_ibuf_208);
   SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID, 1);
   SetIndexBuffer(0, G_ibuf_188);
   SetIndexArrow(0, 234);
   SetIndexLabel(0, "ConfDn");
   SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID, 1);
   SetIndexBuffer(1, G_ibuf_192);
   SetIndexArrow(1, 233);
   SetIndexLabel(1, "ConfUp");
   IndicatorShortName("LRFF-MV-TmaSlope v.8 arrow");
   G_datetime_220 = TimeCurrent();
   Gi_232 = WindowHandle(Symbol(), Period());
   switch (Period()) {
   case PERIOD_M1:
      Gi_216 = 1;
      break;
   case PERIOD_M5:
      Gi_216 = 2;
      break;
   case PERIOD_M15:
      Gi_216 = 10;
      break;
   case PERIOD_M30:
      Gi_216 = 19;
      break;
   case PERIOD_H1:
      Gi_216 = 25;
      break;
   case PERIOD_H4:
      Gi_216 = 40;
      break;
   case PERIOD_D1:
      Gi_216 = 80;
      break;
   case PERIOD_W1:
      Gi_216 = 100;
      break;
   case PERIOD_MN1:
      Gi_216 = 400;
   }
   int Li_8 = MarketInfo(Symbol(), MODE_DIGITS);
   if (Li_8 == 2 || Li_8 == 4) Li_4 = 1;
   if (Li_8 == 3 || Li_8 == 5) Li_4 = 10;
   Gi_216 *= Li_4;
   return (0);
}

// 52D46093050F38C27267BCE42543EF60
int deinit() {
   Comment("");
   return (0);
}

// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   int Li_16;
   double Ld_24;
   double Ld_32;
   double Ld_40;
   double Ld_48;
   double Ld_56;
   bool Li_64;
   bool Li_68;
   double Ld_72;
   double Ld_80;
   double Ld_88;
   int ind_counted_8 = IndicatorCounted();
   int Li_12 = Bars - ind_counted_8 + 1;
   if (TimeCurrent() >= G_datetime_220 + 300 && Gi_232 != 0) {
      switch (Period()) {
      case PERIOD_M1:
         Li_16 = 33137;
         break;
      case PERIOD_M5:
         Li_16 = 33138;
         break;
      case PERIOD_M15:
         Li_16 = 33139;
         break;
      case PERIOD_M30:
         Li_16 = 33140;
         break;
      case PERIOD_H1:
         Li_16 = 33135;
         break;
      case PERIOD_H4:
         Li_16 = 33136;
         break;
      case PERIOD_D1:
         Li_16 = 33134;
         break;
      case PERIOD_W1:
         Li_16 = 33141;
         break;
      default:
         Li_16 = 33137;
      }
      PostMessageA(Gi_232, WM_COMMAND, 33141, 0);
      PostMessageA(Gi_232, WM_COMMAND, Li_16, 0);
      G_datetime_220 = TimeCurrent();
   }
   for (int Li_0 = 1; Li_0 < Li_12; Li_0++) {
      Ld_56 = f0_0(Li_0, eintPeriod1, 0);
      Li_64 = FALSE;
      Li_68 = FALSE;
      if (Ld_56 != 0.0 && Ld_56 != EMPTY_VALUE) {
         for (int Li_4 = Li_0; Li_4 <= Li_0 + AmountBarsToScan; Li_4++) {
            Ld_40 = f0_0(Li_4, eintPeriod2, 0);
            if (Ld_40 != 0.0 && Ld_40 != EMPTY_VALUE) {
               Li_68 = TRUE;
               break;
            }
         }
      }
      Ld_72 = f0_0(Li_0, eintPeriod2, 0);
      if (Ld_72 != 0.0 && Ld_72 != EMPTY_VALUE) {
         for (Li_4 = Li_0; Li_4 <= Li_0 + AmountBarsToScan; Li_4++) {
            Ld_24 = f0_0(Li_4, eintPeriod1, 0);
            if (Ld_24 != 0.0 && Ld_24 != EMPTY_VALUE) {
               Li_68 = TRUE;
               break;
            }
         }
      }
      if (Li_68) {
         G_ibuf_188[Li_0 + 1] = High[Li_0 + 1] + Gi_216 * Point;
         G_ibuf_192[Li_0 + 1] = EMPTY_VALUE;
         if (Li_0 == 1 && G_time_228 != Time[0]) {
            if (ShowConfAlert) Alert(Gs_240 + " is confirmed Bearish, " + Symbol() + "(" + Period() + ")");
            if (SendmailConfAlert) {
               SendMail(Gs_240 + " is confirmed Bearish, " + Symbol() + "(" + Period() + ")", "LRFF-10.2 TmaSlope v.8 arrow is confirmed Bearish, " + Symbol() + "(" + Period() +
                  ") " + TimeToStr(Time[0], TIME_DATE|TIME_SECONDS));
            }
            G_time_228 = Time[0];
         }
      }
      Ld_80 = f0_0(Li_0, eintPeriod1, 1);
      if (Ld_80 != 0.0 && Ld_80 != EMPTY_VALUE) {
         for (Li_4 = Li_0; Li_4 <= Li_0 + AmountBarsToScan; Li_4++) {
            Ld_48 = f0_0(Li_4, eintPeriod2, 1);
            if (Ld_48 != 0.0 && Ld_48 != EMPTY_VALUE) {
               Li_64 = TRUE;
               break;
            }
         }
      }
      Ld_88 = f0_0(Li_0, eintPeriod2, 1);
      if (Ld_88 != 0.0 && Ld_88 != EMPTY_VALUE) {
         for (Li_4 = Li_0; Li_4 <= Li_0 + AmountBarsToScan; Li_4++) {
            Ld_32 = f0_0(Li_4, eintPeriod1, 1);
            if (Ld_32 != 0.0 && Ld_32 != EMPTY_VALUE) {
               Li_64 = TRUE;
               break;
            }
         }
      }
      if (Li_64) {
         G_ibuf_192[Li_0 + 1] = Low[Li_0 + 1] - Gi_216 * Point;
         G_ibuf_188[Li_0 + 1] = EMPTY_VALUE;
         if (Li_0 == 1 && G_time_228 != Time[0]) {
            if (ShowConfAlert) Alert(Gs_240 + " is confirmed bullish, " + Symbol() + "(" + Period() + ")");
            if (SendmailConfAlert) {
               SendMail(Gs_240 + " is confirmed Bullish, " + Symbol() + "(" + Period() + ")", "LRFF-10.2 TmaSlope v.8 arrow is confirmed Bullish, " + Symbol() + "(" + Period() +
                  ") " + TimeToStr(Time[0], TIME_DATE|TIME_SECONDS));
            }
            G_time_228 = Time[0];
         }
      }
   }
   return (0);
}

// CA4ABB07A2E12B9008C49953DB2D0C0D
double f0_0(int Ai_0, int Ai_4, int Ai_8) {
   double icustom_48;
   double Ld_ret_64;
   double Ld_ret_72;
   double icustom_12 = iCustom(Symbol(), 0, "LRFF-10.2 TmaSlope v.8_2", OtherTimeFrames, select_other_tf_to_show, Gi_104, Gi_108, Gi_112, Gi_116, Gi_120, Ai_4, edblHigh1,
      edblLow1, atrPeriod, Gi_152, Gi_156, Gi_160, Gi_164, Gi_168, Gi_172, Gi_176, Gi_180, Gi_184, 6, Ai_0 + 1);
   double icustom_20 = iCustom(Symbol(), 0, "LRFF-10.2 TmaSlope v.8_2", OtherTimeFrames, select_other_tf_to_show, Gi_104, Gi_108, Gi_112, Gi_116, Gi_120, Ai_4, edblHigh1,
      edblLow1, atrPeriod, Gi_152, Gi_156, Gi_160, Gi_164, Gi_168, Gi_172, Gi_176, Gi_180, Gi_184, 6, Ai_0 + 2);
   bool Li_28 = FALSE;
   bool Li_32 = FALSE;
   if (icustom_12 > icustom_20) Li_28 = TRUE;
   if (icustom_12 < icustom_20) Li_32 = TRUE;
   bool Li_36 = FALSE;
   bool Li_40 = FALSE;
   for (int Li_44 = Ai_0 + 2; Li_44 < Bars - atrPeriod; Li_44++) {
      icustom_48 = iCustom(Symbol(), 0, "LRFF-10.2 TmaSlope v.8_2", OtherTimeFrames, select_other_tf_to_show, Gi_104, Gi_108, Gi_112, Gi_116, Gi_120, Ai_4, edblHigh1, edblLow1,
         atrPeriod, Gi_152, Gi_156, Gi_160, Gi_164, Gi_168, Gi_172, Gi_176, Gi_180, Gi_184, 6, Li_44);
      if (icustom_48 >= edblHigh1) {
         Li_40 = TRUE;
         break;
      }
      if (icustom_48 <= edblLow1) {
         Li_36 = TRUE;
         break;
      }
   }
   bool Li_56 = FALSE;
   bool Li_60 = FALSE;
   if (Li_28 && icustom_12 >= edblHigh1 && icustom_20 < edblHigh1 && Li_36) Li_56 = TRUE;
   if (Li_32 && icustom_12 <= edblLow1 && icustom_20 > edblLow1 && Li_40) Li_60 = TRUE;
   if (Li_56) {
      Ld_ret_64 = Low[Ai_0 + 1] - Gi_216 * Point;
      Ld_ret_72 = EMPTY_VALUE;
   }
   if (Li_60) {
      Ld_ret_72 = High[Ai_0 + 1] + Gi_216 * Point;
      Ld_ret_64 = EMPTY_VALUE;
   }
   if (Ai_8 == 0) return (Ld_ret_72);
   if (Ai_8 == 1) return (Ld_ret_64);
   return (0.0);
}
