/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright(c)2009, DayAfterTrade"
#property link      "http://DayAfterTrade.blog45.fc2.com/"

#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 RoyalBlue


string gs_76;
string gs_84;
extern int Senkou = 26;
extern int SpanPeriod = 52;
extern int Chikou = 26;
extern int SwayPeriod = 0;
extern int FuturePeriod = 28;
extern bool Show_Signal = FALSE;
bool gi_116 = FALSE;
bool gi_120 = FALSE;
string gs_124 = "alert.wav";
bool gi_132 = FALSE;
bool gi_136 = FALSE;
extern bool Show_Title = TRUE;
extern bool Show_Value = FALSE;
extern int CalculateBars = 500;
extern int FixedBarCount = 1;
double g_ibuf_156[];
double g_ibuf_160[];
double g_ibuf_164[];
int g_time_168 = 315532800;
int g_time_172 = 315532800;
int g_time_176 = 315532800;
int g_datetime_180 = 315532800;
int gi_unused_184;
string gs_188;
int gi_196 = 0;
int gi_unused_200 = 1;
int gi_204 = 2;
int gi_unused_208 = 3;


int init() {
   gs_76 = "DAT_IchimokuSP2";
   if (Show_Title == FALSE) gs_76 = "";
   IndicatorShortName(gs_76);
   SetIndexBuffer(0, g_ibuf_156);
   SetIndexBuffer(1, g_ibuf_160);
   SetIndexBuffer(2, g_ibuf_164);
   SetIndexLabel(0, "Senkou Span B");
   SetIndexLabel(1, "Up Signal");
   SetIndexLabel(2, "Dn Signal");
   if (!Show_Value) {
      SetIndexLabel(0, NULL);
      SetIndexLabel(1, NULL);
      SetIndexLabel(2, NULL);
   }
   SetIndexStyle(0, DRAW_LINE);
   SetIndexStyle(1, DRAW_LINE);
   if (CalculateBars > 0) {
      SetIndexDrawBegin(0, Bars - CalculateBars);
      SetIndexDrawBegin(1, Bars - CalculateBars);
      SetIndexDrawBegin(2, Bars - CalculateBars);
   }
   if (FuturePeriod >= 0) {
      SetIndexShift(0, FuturePeriod);
      SetIndexShift(1, FuturePeriod);
      SetIndexShift(2, FuturePeriod);
   }
   gi_unused_184 = 0;
   gs_188 = gs_76 + "_";
   g_time_168 = Time[0];
   g_time_172 = Time[0];
   g_time_176 = Time[0];
   g_datetime_180 = TimeLocal();
   return (0);
}

int deinit() {
   DeleteObjects(gs_188);
   Comment("");
   return (0);
}

void DeleteObjects(string as_0) {
   string l_name_8;
   for (int li_16 = ObjectsTotal() - 1; li_16 >= 0; li_16--) {
      l_name_8 = ObjectName(li_16);
      if (StringFind(l_name_8, as_0) > -1) ObjectDelete(l_name_8);
   }
}

int start() {
   double ld_12;
   double ld_20;
   double ld_28;
   int li_0 = CalculateBars;
   int li_4 = li_0;
   int li_36 = Senkou + Chikou - FuturePeriod;
   while (li_4 >= 0) {
      ld_12 = High[li_4 + li_36 + SwayPeriod];
      ld_20 = Low[li_4 + li_36 + SwayPeriod];
      for (int li_8 = li_4 - 1 + li_36 + SpanPeriod + SwayPeriod; li_8 >= li_4 + li_36 + SwayPeriod; li_8--) {
         ld_28 = High[li_8];
         if (ld_12 < ld_28) ld_12 = ld_28;
         ld_28 = Low[li_8];
         if (ld_20 > ld_28) ld_20 = ld_28;
      }
      ld_28 = (ld_12 + ld_20) / 2.0;
      g_ibuf_156[li_4] = ld_28;
      li_4--;
   }
   if (Show_Signal) {
      for (li_4 = li_0 - 1; li_4 >= 0; li_4--) {
         g_ibuf_160[li_4] = EMPTY_VALUE;
         g_ibuf_164[li_4] = EMPTY_VALUE;
         if (Close[li_4] >= g_ibuf_156[li_4] && Close[li_4 + 1] < g_ibuf_156[li_4 + 1]) {
            g_ibuf_160[li_4] = g_ibuf_156[li_4];
            subShowAlert(gs_76, "BUY");
         }
         if (Close[li_4] <= g_ibuf_156[li_4] && Close[li_4 + 1] > g_ibuf_156[li_4 + 1]) {
            g_ibuf_164[li_4] = g_ibuf_156[li_4];
            subShowAlert(gs_76, "SELL");
         }
      }
   }
   return (0);
}

void subShowAlert(string as_0, string as_8) {
   string ls_unused_24;
   string ls_32;
   int li_40;
   string ls_44;
   int li_52;
   int li_56;
   double ld_60;
   double ld_68;
   double ld_76;
   double ld_84;
   string l_str_concat_16 = StringConcatenate(as_0, " ", as_8, " ", Close[0], " on ", gs_76, "-", gs_84, " ", TimeToStr(TimeLocal(), TIME_SECONDS), " ", Symbol());
   if (gi_116 == TRUE && g_time_168 != Time[0]) {
      Alert(l_str_concat_16);
      g_time_168 = Time[0];
   }
   if (gi_120 == TRUE && g_time_172 != Time[0]) {
      PlaySound(gs_124);
      g_time_172 = Time[0];
   }
   if (gi_132 == TRUE && g_time_176 != Time[0]) {
      ls_32 = "HighPerformance Exchange Indicators from DayAfterTrade";
      SendMail(l_str_concat_16, ls_32);
      g_time_176 = Time[0];
   }
   if (gi_136 == TRUE && g_datetime_180 != TimeLocal()) {
      li_40 = 8;
      ls_44 = "Arial";
      li_52 = 55295;
      li_56 = 55295;
      if (StringFind(as_8, "BUY") > -1) {
         li_52 = 65280;
         li_56 = 65280;
      }
      if (StringFind(as_8, "SELL") > -1) {
         li_52 = 3937500;
         li_56 = 3937500;
      }
      if (StringFind(as_8, "EXIT") > -1) {
         li_52 = 55295;
         li_56 = 55295;
      }
      ld_60 = 6;
      ld_68 = 32;
      ld_76 = 6;
      ld_84 = 32;
      DrawText("AlertChart", as_8, 0, gi_196, ld_76, ld_84, li_52, li_56, li_40, ls_44);
      DrawText("AlertChart", as_8, 0, gi_204, ld_60, ld_68, li_52, li_56, li_40, ls_44);
      g_datetime_180 = TimeLocal();
   }
}

void DrawText(string as_0, string a_text_8, int a_window_16, int a_corner_20, int a_x_24, int a_y_28, color a_color_32, color a_color_36, int a_fontsize_40 = 14, string a_fontname_44 = "Arial Black") {
   string l_name_52 = gs_188 + as_0;
   ObjectDelete(l_name_52);
   ObjectCreate(l_name_52, OBJ_LABEL, a_window_16, 0, 0);
   ObjectSet(l_name_52, OBJPROP_CORNER, a_corner_20);
   ObjectSet(l_name_52, OBJPROP_XDISTANCE, a_x_24);
   ObjectSet(l_name_52, OBJPROP_YDISTANCE, a_y_28);
   ObjectSet(l_name_52, OBJPROP_COLOR, a_color_32);
   ObjectSetText(l_name_52, a_text_8, a_fontsize_40, a_fontname_44, a_color_36);
}