Navigation:Home > Content >

MT4-LevelStop-Reverse-v2.mq4

Time: 2016-02-05 | Download file:MT4-LevelStop-Reverse-v2.mq4

#property copyright "Copyright © 2007-2008, Bruce Hellstrom (brucehvn)"
#property link      "http: //www.metaquotes.net/"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Fuchsia

extern bool UseATRMode = TRUE;
extern int NonATRStopPips = 40;
extern int ATRPeriod = 9;
extern double ATRMultiplier = 3.0;
extern int ATRSmoothing = 0;
extern color UpArrowColor = DodgerBlue;
extern color DnArrowColor = OrangeRed;
extern int ArrowDistance = 0;
extern bool AlertSound = TRUE;
extern bool AlertMail = FALSE;
extern bool ShowComment = TRUE;
double G_ibuf_124[];
double Gda_128[];
double Gda_132[];
string Gs_136;
int G_count_144 = 0;
int G_count_148;
int Gi_152 = 0;
datetime G_time_156 = 0;
bool Gi_160 = FALSE;
datetime G_time_164 = 0;
datetime G_time_168 = 0;

// E37F0136AA3FFAF149B351F6A4C948E9
int init() {
   bool Li_0 = FALSE;
   if (UseATRMode) Li_0 = ATRPeriod;
   if (ATRSmoothing <= 0) ATRSmoothing = 1;
   IndicatorBuffers(1);
   SetIndexStyle(0, DRAW_LINE, STYLE_DOT, 1);
   SetIndexBuffer(0, G_ibuf_124);
   SetIndexDrawBegin(0, Li_0);
   Gs_136 = "MT4-LevelStop-Reverse-" + "v2.0" + "(";
   if (UseATRMode) Gs_136 = StringConcatenate(Gs_136, "ATRMode ", ATRPeriod, ", ", ATRMultiplier, ", ", ATRSmoothing, " )");
   else Gs_136 = StringConcatenate(Gs_136, "Manual Mode Stop = ", NonATRStopPips, " )");
   IndicatorShortName(Gs_136);
   SetIndexLabel(0, Gs_136);
   Print(Gs_136);
   Print("Copyright (c) 2007 - Bruce Hellstrom, [email protected]");
   MathSrand(TimeLocal());
   f0_1();
   G_count_148 = 0;
   G_count_144 = 0;
   return (0);
}

// 52D46093050F38C27267BCE42543EF60
int deinit() {
   f0_1();
   return (0);
}

// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   double Ld_20;
   double Ld_28;
   double Ld_36;
   bool Li_44;
   bool Li_48;
   double price_52;
   string name_60;
   double price_68;
   Comment(Gs_136);
   int Li_4 = IndicatorCounted();
   if (Li_4 < 0) return (-1);
   if (Li_4 > 0) Li_4--;
   int Li_8 = Bars - Li_4;
   int Li_0 = Li_8 - 1;
   if (UseATRMode && Bars < ATRPeriod) return (0);
   int arr_size_12 = ArraySize(G_ibuf_124);
   if (ArraySize(Gda_128) != arr_size_12) {
      ArraySetAsSeries(Gda_128, FALSE);
      ArrayResize(Gda_128, arr_size_12);
      ArraySetAsSeries(Gda_128, TRUE);
      ArraySetAsSeries(Gda_132, FALSE);
      ArrayResize(Gda_132, arr_size_12);
      ArraySetAsSeries(Gda_132, TRUE);
   }
   if (UseATRMode) {
      for (int Li_16 = 0; Li_16 < Li_8; Li_16++) Gda_128[Li_16] = iATR(NULL, 0, ATRPeriod, Li_16);
      for (Li_16 = 0; Li_16 < Li_8; Li_16++) Gda_132[Li_16] = f0_2(Gda_128, ATRSmoothing, Li_16);
   }
   for (Li_16 = Li_0; Li_16 >= 0; Li_16--) {
      Ld_20 = NonATRStopPips * Point;
      if (UseATRMode) Ld_20 = NormalizeDouble(Gda_132[Li_16] * ATRMultiplier, 4);
      Ld_36 = G_ibuf_124[Li_16 + 1];
      Li_44 = FALSE;
      Li_48 = FALSE;
      if (Close[Li_16] == Ld_36) Ld_28 = Ld_36;
      else {
         if (Close[Li_16 + 1] <= Ld_36 && Close[Li_16] < Ld_36) Ld_28 = MathMin(Ld_36, Close[Li_16] + Ld_20);
         else {
            if (Close[Li_16 + 1] >= Ld_36 && Close[Li_16] > Ld_36) Ld_28 = MathMax(Ld_36, Close[Li_16] - Ld_20);
            else {
               if (Close[Li_16] > Ld_36) {
                  Ld_28 = Close[Li_16] - Ld_20;
                  Li_44 = TRUE;
               } else {
                  Ld_28 = Close[Li_16] + Ld_20;
                  Li_48 = TRUE;
               }
            }
         }
      }
      G_ibuf_124[Li_16] = Ld_28;
      if (Li_16 > 0) {
         if (Li_44) {
            if (Time[Li_16] > G_time_156) {
               price_52 = G_ibuf_124[Li_16] - ArrowDistance * Point;
               name_60 = f0_3();
               ObjectCreate(name_60, OBJ_ARROW, 0, Time[Li_16], price_52);
               ObjectSet(name_60, OBJPROP_COLOR, UpArrowColor);
               ObjectSet(name_60, OBJPROP_ARROWCODE, 233);
               G_count_144++;
               G_time_156 = Time[Li_16];
               Gi_160 = TRUE;
            }
         }
         if (Li_48) {
            if (Time[Li_16] > G_time_156) {
               price_68 = G_ibuf_124[Li_16] + 2.0 * Point + ArrowDistance * Point;
               name_60 = f0_3();
               ObjectCreate(name_60, OBJ_ARROW, 0, Time[Li_16], price_68);
               ObjectSet(name_60, OBJPROP_COLOR, DnArrowColor);
               ObjectSet(name_60, OBJPROP_ARROWCODE, 234);
               G_count_144++;
               G_time_156 = Time[Li_16];
               Gi_160 = FALSE;
            }
         }
      }
      if (Li_16 == 1)
         if (G_time_156 == Time[Li_16]) f0_0();
      if (Li_16 == 0) {
         if (Time[Li_16] != G_time_168) {
            WindowRedraw();
            G_time_168 = Time[Li_16];
         }
      }
   }
   if (G_count_144 != Gi_152) {
      Print("Total Arrow Objects: ", G_count_144);
      Gi_152 = G_count_144;
   }
   return (0);
}

// 82120C894B17377FC34598621D8E21C4
string f0_3() {
   G_count_148++;
   string Ls_ret_0 = "vtsbh2483-" + G_count_148;
   return (Ls_ret_0);
}

// 5D8C0C734C25641587B398A84614C874
double f0_2(double &Ada_0[], int Ai_4, int Ai_8) {
   double ima_on_arr_12 = 0.0;
   ima_on_arr_12 = iMAOnArray(Ada_0, 0, Ai_4 * 2 - 1, 0, MODE_EMA, Ai_8);
   return (ima_on_arr_12);
}

// 507A2E9FF87DFF7929428E47EA3005EB
void f0_1() {
   string name_8;
   int count_0 = 0;
   for (int Li_4 = 1; Li_4 <= G_count_148; Li_4++) {
      name_8 = "vtsbh2483-" + ((Li_4 + 1));
      if (ObjectDelete(name_8)) count_0++;
   }
   Print("Objects deleted: ", count_0);
}

// 3BEBDBF39866D2F719D187268C69411D
void f0_0() {
   int timeframe_0;
   string Ls_4;
   int datetime_16;
   string Ls_20;
   string Ls_28;
   if (G_time_156 > G_time_164) {
      if (AlertSound) PlaySound("alert.wav");
      if (AlertMail) {
         timeframe_0 = Period();
         Ls_4 = "";
         switch (timeframe_0) {
         case PERIOD_M1:
            Ls_4 = "M1";
            break;
         case PERIOD_M5:
            Ls_4 = "M5";
            break;
         case PERIOD_M15:
            Ls_4 = "M15";
            break;
         case PERIOD_M30:
            Ls_4 = "M30";
            break;
         case PERIOD_H1:
            Ls_4 = "H1";
            break;
         case PERIOD_H4:
            Ls_4 = "H4";
            break;
         case PERIOD_D1:
            Ls_4 = "D1";
            break;
         case PERIOD_W1:
            Ls_4 = "W1";
            break;
         case PERIOD_MN1:
            Ls_4 = "MN1";
            break;
         default:
            Ls_4 = "" + timeframe_0 + " Min";
         }
         datetime_16 = TimeCurrent();
         Ls_20 = "LONG";
         if (!Gi_160) Ls_20 = "SHORT";
         Ls_28 = "MT4-SLReverse Alert " + TimeToStr(datetime_16, TIME_DATE|TIME_SECONDS);
         SendMail(Ls_28, "The StopLevelReverse has given a " + Ls_20 + " signal for pair " + Symbol() + " " + Ls_4 + ".");
      }
      G_time_164 = G_time_156;
   }
}

Recommend