/*
   Generated by EX4-TO-MQ4 decompiler V4.0.223.1b []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/

#property indicator_chart_window
#property indicator_buffers 7
#property indicator_color1 Lime
#property indicator_color2 Blue
#property indicator_color3 Red
#property indicator_color4 Blue
#property indicator_color5 Red
#property indicator_color6 Blue
#property indicator_color7 Red

extern int CountBars = 300;
double g_ibuf_80[];
double g_ibuf_84[];
double g_ibuf_88[];
double g_ibuf_92[];
double g_ibuf_96[];
double g_ibuf_100[];
double g_ibuf_104[];
string gs_unused_108 = "P";
string gs_unused_116 = "S 1";
string gs_unused_124 = "R 1";
string gs_unused_132 = "S 2";
string gs_unused_140 = "R 2";
string gs_unused_148 = "S 3";
string gs_unused_156 = "R 3";
int gi_unused_164 = 10;
double gd_168;
double gd_176;
double gd_184;
double gd_192;
double gd_200;
double gd_208;
double gd_216;
double gd_224;
double gd_232;
double g_timeframe_240;

int deinit() {
   ObjectDelete("Pivot");
   ObjectDelete("S1");
   ObjectDelete("R1");
   ObjectDelete("S2");
   ObjectDelete("R2");
   ObjectDelete("S3");
   ObjectDelete("R3");
   return (0);
}

int init() {
   IndicatorBuffers(7);
   SetIndexStyle(0, DRAW_ARROW, STYLE_DOT, 2, Lime);
   SetIndexArrow(0, 158);
   SetIndexStyle(1, DRAW_ARROW, STYLE_DOT, 2, Blue);
   SetIndexArrow(1, 158);
   SetIndexStyle(2, DRAW_ARROW, STYLE_DOT, 2, Red);
   SetIndexArrow(2, 158);
   SetIndexStyle(3, DRAW_ARROW, STYLE_DOT, 2, Blue);
   SetIndexArrow(3, 158);
   SetIndexStyle(4, DRAW_ARROW, STYLE_DOT, 2, Red);
   SetIndexArrow(4, 158);
   SetIndexStyle(5, DRAW_ARROW, STYLE_DOT, 2, Blue);
   SetIndexArrow(5, 158);
   SetIndexStyle(6, DRAW_ARROW, STYLE_DOT, 2, Red);
   SetIndexArrow(6, 158);
   SetIndexBuffer(0, g_ibuf_80);
   SetIndexBuffer(1, g_ibuf_84);
   SetIndexBuffer(2, g_ibuf_88);
   SetIndexBuffer(3, g_ibuf_92);
   SetIndexBuffer(4, g_ibuf_96);
   SetIndexBuffer(5, g_ibuf_100);
   SetIndexBuffer(6, g_ibuf_104);
   string ls_0 = "Pivot";
   IndicatorShortName(ls_0);
   SetIndexLabel(0, ls_0);
   ls_0 = "R1";
   IndicatorShortName(ls_0);
   SetIndexLabel(2, ls_0);
   ls_0 = "R2";
   IndicatorShortName(ls_0);
   SetIndexLabel(4, ls_0);
   ls_0 = "R3";
   IndicatorShortName(ls_0);
   SetIndexLabel(6, ls_0);
   ls_0 = "S1";
   IndicatorShortName(ls_0);
   SetIndexLabel(1, ls_0);
   ls_0 = "S2";
   IndicatorShortName(ls_0);
   SetIndexLabel(3, ls_0);
   ls_0 = "S3";
   IndicatorShortName(ls_0);
   SetIndexLabel(5, ls_0);
   SetIndexDrawBegin(0, 6);
   return (0);
}

int start() {
   int l_ind_counted_0 = IndicatorCounted();
   if (l_ind_counted_0 == 0) {
      g_timeframe_240 = Period();
      if (g_timeframe_240 > CountBars) return (-1);
      ObjectCreate("Pivot", OBJ_TEXT, 0, 0, 0);
      ObjectSetText("Pivot", "        Pivot", 10, "Arial", Lime);
      ObjectCreate("S1", OBJ_TEXT, 0, 0, 0);
      ObjectSetText("S1", "      S1", 10, "Arial", Blue);
      ObjectCreate("R1", OBJ_TEXT, 0, 0, 0);
      ObjectSetText("R1", "      R1", 10, "Arial", Red);
      ObjectCreate("S2", OBJ_TEXT, 0, 0, 0);
      ObjectSetText("S2", "      S2", 10, "Arial", Blue);
      ObjectCreate("R2", OBJ_TEXT, 0, 0, 0);
      ObjectSetText("R2", "      R2", 10, "Arial", Red);
      ObjectCreate("S3", OBJ_TEXT, 0, 0, 0);
      ObjectSetText("S3", "      S3", 10, "Arial", Blue);
      ObjectCreate("R3", OBJ_TEXT, 0, 0, 0);
      ObjectSetText("R3", "      R3", 10, "Arial", Red);
   }
   if (l_ind_counted_0 < 0) return (-1);
   int li_4 = Bars - l_ind_counted_0 - 1;
   for (int li_8 = li_4; li_8 >= 0; li_8--) {
      if (TimeDayOfWeek(Time[li_8]) != 0) {
         if (High[li_8 + 1] > gd_224) gd_224 = High[li_8 + 1];
         if (Low[li_8 + 1] < gd_232) gd_232 = Low[li_8 + 1];
      }
      if (TimeDay(Time[li_8]) != TimeDay(Time[li_8 + 1]) && TimeDayOfWeek(Time[li_8]) != 0) {
         gd_168 = (gd_224 + gd_232 + (Close[li_8 + 1])) / 3.0;
         gd_184 = 2.0 * gd_168 - gd_232;
         gd_176 = 2.0 * gd_168 - gd_224;
         gd_200 = gd_168 + (gd_224 - gd_232);
         gd_192 = gd_168 - (gd_224 - gd_232);
         gd_216 = 2.0 * gd_168 + (gd_224 - 2.0 * gd_232);
         gd_208 = 2.0 * gd_168 - (2.0 * gd_224 - gd_232);
         gd_232 = Open[li_8];
         gd_224 = Open[li_8];
         ObjectMove("Pivot", 0, Time[li_8], gd_168);
         ObjectMove("S1", 0, Time[li_8], gd_176);
         ObjectMove("R1", 0, Time[li_8], gd_184);
         ObjectMove("S2", 0, Time[li_8], gd_192);
         ObjectMove("R2", 0, Time[li_8], gd_200);
         ObjectMove("S3", 0, Time[li_8], gd_208);
         ObjectMove("R3", 0, Time[li_8], gd_216);
      }
      g_ibuf_80[li_8] = gd_168;
      g_ibuf_84[li_8] = gd_176;
      g_ibuf_88[li_8] = gd_184;
      g_ibuf_92[li_8] = gd_192;
      g_ibuf_96[li_8] = gd_200;
      g_ibuf_100[li_8] = gd_208;
      g_ibuf_104[li_8] = gd_216;
   }
   return (0);
}
