
#property copyright "Copyright © 2009, TradeWays"
#property link      "http://www.tradeways.org"

#property indicator_separate_window
#property indicator_minimum -0.8
#property indicator_maximum 0.2
#property indicator_buffers 8
#property indicator_color1 Blue
#property indicator_color2 Red
#property indicator_color3 Blue
#property indicator_color4 Red
#property indicator_color5 Blue
#property indicator_color6 Red
#property indicator_color7 Blue
#property indicator_color8 Red

extern int P = 38;
extern int P2 = 14;
extern int P3 = 39;
extern int P4 = 33;
extern int DrawBars = -1;
extern bool EmailON = TRUE;
extern bool SoundON = TRUE;
extern bool AlertON = TRUE;
extern int AlertRepeat = 3;
extern bool EndLessRepeat = FALSE;
extern string SoundFile = "Alert";
int gi_124 = 30;
int gi_128 = 70;
extern int CountBars = 500;
double g_ibuf_136[];
double g_ibuf_140[];
double g_ibuf_144[];
double g_ibuf_148[];
double g_ibuf_152[];
double g_ibuf_156[];
double g_ibuf_160[];
double g_ibuf_164[];
string gs_168 = "#PalladaSE_Entry©2009 TradeWays";
int gi_176;
int gi_180;
int g_datetime_184;
int g_datetime_188;
int gi_192;
int gi_196;
int g_datetime_200;
int g_datetime_204;
int gi_208;
int gi_212;
int g_datetime_216;
int g_datetime_220;
int gi_224;
int gi_228;
int g_datetime_232;
int g_datetime_236;
int g_time_240 = 0;
int g_time_244 = 0;
int g_time_248 = 0;
int g_time_252 = 0;
int g_time_256 = 0;
int g_time_260 = 0;
int g_time_264 = 0;
int g_time_268 = 0;

int init() {
   ObjectDelete("Entry_Bell");
   IndicatorBuffers(8);
   SetIndexStyle(0, DRAW_ARROW, STYLE_SOLID, 1);
   SetIndexStyle(1, DRAW_ARROW, STYLE_SOLID, 1);
   SetIndexBuffer(0, g_ibuf_144);
   SetIndexBuffer(1, g_ibuf_148);
   SetIndexStyle(2, DRAW_ARROW, STYLE_SOLID, 0);
   SetIndexStyle(3, DRAW_ARROW, STYLE_SOLID, 0);
   SetIndexBuffer(2, g_ibuf_136);
   SetIndexBuffer(3, g_ibuf_140);
   SetIndexStyle(4, DRAW_ARROW, STYLE_SOLID, 0);
   SetIndexStyle(5, DRAW_ARROW, STYLE_SOLID, 0);
   SetIndexBuffer(4, g_ibuf_152);
   SetIndexBuffer(5, g_ibuf_156);
   SetIndexStyle(6, DRAW_ARROW, STYLE_SOLID, 0);
   SetIndexStyle(7, DRAW_ARROW, STYLE_SOLID, 0);
   SetIndexBuffer(6, g_ibuf_160);
   SetIndexBuffer(7, g_ibuf_164);
   SetIndexArrow(0, 233);
   SetIndexArrow(1, 234);
   SetIndexArrow(2, 110);
   SetIndexArrow(3, 110);
   SetIndexArrow(4, 110);
   SetIndexArrow(5, 110);
   SetIndexArrow(6, 110);
   SetIndexArrow(7, 110);
   SetIndexLabel(0, "WPR Entry Up");
   SetIndexLabel(1, "WPR Entry Down");
   SetIndexLabel(2, "WPR Trend Up");
   SetIndexLabel(3, "WPR Trend Down");
   SetIndexLabel(4, "CCI Trend Up");
   SetIndexLabel(5, "CCI Trend Down");
   SetIndexLabel(6, "Force Trend Up");
   SetIndexLabel(7, "Force Trend Down");
   IndicatorShortName(gs_168);
   return (0);
}

int deinit() {
   ObjectDelete("Entry_Bell");
   return (0);
}

int start() {
   double l_iwpr_8;
   double l_iwpr_16;
   double l_icci_24;
   double l_iforce_32;
   //if (TimeCurrent() > StrToTime("2050.04.20")) {
   //   Alert("New version available! Download it using re-activated link from Plimus");
   //  return;
   //}
   //if (AccountNumber() != 0 && 0) {
   //   Alert("This expert is not licensed to your account number!");
   //   return;
   //}
   int li_0 = Bars - IndicatorCounted();
   if (DrawBars != -1) li_0 = MathMin(li_0, DrawBars);
   for (int li_4 = li_0 - 1; li_4 >= 0; li_4--) {
      g_ibuf_136[li_4] = EMPTY_VALUE;
      g_ibuf_140[li_4] = EMPTY_VALUE;
      g_ibuf_144[li_4] = EMPTY_VALUE;
      g_ibuf_148[li_4] = EMPTY_VALUE;
      g_ibuf_152[li_4] = EMPTY_VALUE;
      g_ibuf_156[li_4] = EMPTY_VALUE;
      g_ibuf_160[li_4] = EMPTY_VALUE;
      g_ibuf_164[li_4] = EMPTY_VALUE;
      l_iwpr_8 = iWPR(NULL, 0, P, li_4);
      l_iwpr_16 = iWPR(NULL, 0, P2, li_4);
      l_icci_24 = iCCI(NULL, 0, P3, PRICE_TYPICAL, li_4);
      l_iforce_32 = iForce(NULL, 0, P4, MODE_EMA, PRICE_TYPICAL, li_4);
      if (l_iwpr_8 > -50.0) g_ibuf_136[li_4] = -0.2;
      if (l_iwpr_8 < -50.0) g_ibuf_140[li_4] = -0.2;
      if (l_iwpr_16 > -gi_124) g_ibuf_144[li_4] = 0;
      if (l_iwpr_16 < -gi_128) g_ibuf_148[li_4] = 0;
      if (l_icci_24 > 0.0) g_ibuf_152[li_4] = -0.6;
      if (l_icci_24 < 0.0) g_ibuf_156[li_4] = -0.6;
      if (l_iforce_32 > 0.0) g_ibuf_160[li_4] = -0.4;
      if (l_iforce_32 < 0.0) g_ibuf_164[li_4] = -0.4;
   }
   int li_40 = 1;
   int li_44 = WindowFind(gs_168);
   if (g_ibuf_144[li_40] != EMPTY_VALUE && g_ibuf_144[li_40 + 1] == EMPTY_VALUE) {
      if (Time[0] != g_time_240) {
         g_time_240 = Time[0];
         if (EmailON) SendMail("Entry(" + Symbol() + " " + fTimeFrameName(Period()) + ")", "WPR Entry Up");
         if (SoundON || AlertON) {
            fObjLabel("Entry_Bell", 10, 10, StringSetChar("", 0, '%'), 1, Red, 16, li_44, "Wingdings", FALSE);
            if (EndLessRepeat) gi_176 = 1;
            else gi_176 = AlertRepeat;
            g_datetime_184 = 0;
            gi_180 = 0;
         }
      }
   }
   if (g_ibuf_148[li_40] != EMPTY_VALUE && g_ibuf_148[li_40 + 1] == EMPTY_VALUE) {
      if (Time[0] != g_time_244) {
         g_time_244 = Time[0];
         if (EmailON) SendMail("Entry" + Symbol() + " " + fTimeFrameName(Period()) + ")", "WPR Entry Down");
         if (SoundON || AlertON) {
            fObjLabel("Entry_Bell", 10, 10, StringSetChar("", 0, '%'), 1, Red, 16, li_44, "Wingdings", FALSE);
            if (EndLessRepeat) gi_180 = 1;
            else gi_180 = AlertRepeat;
            g_datetime_188 = 0;
            gi_176 = 0;
         }
      }
   }
   if (g_ibuf_136[li_40] != EMPTY_VALUE && g_ibuf_136[li_40 + 1] == EMPTY_VALUE) {
      if (Time[0] != g_time_248) {
         g_time_248 = Time[0];
         if (EmailON) SendMail("Entry(" + Symbol() + " " + fTimeFrameName(Period()) + ")", "WPR Trend Up");
         if (SoundON || AlertON) {
            fObjLabel("Entry_Bell", 10, 10, StringSetChar("", 0, '%'), 1, Red, 16, li_44, "Wingdings", FALSE);
            if (EndLessRepeat) gi_192 = 1;
            else gi_192 = AlertRepeat;
            g_datetime_200 = 0;
            gi_196 = 0;
         }
      }
   }
   if (g_ibuf_140[li_40] != EMPTY_VALUE && g_ibuf_140[li_40 + 1] == EMPTY_VALUE) {
      if (Time[0] != g_time_252) {
         g_time_252 = Time[0];
         if (EmailON) SendMail("Entry" + Symbol() + " " + fTimeFrameName(Period()) + ")", "WPR Trend Down");
         if (SoundON || AlertON) {
            fObjLabel("Entry_Bell", 10, 10, StringSetChar("", 0, '%'), 1, Red, 16, li_44, "Wingdings", FALSE);
            if (EndLessRepeat) gi_196 = 1;
            else gi_196 = AlertRepeat;
            g_datetime_204 = 0;
            gi_192 = 0;
         }
      }
   }
   if (g_ibuf_152[li_40] != EMPTY_VALUE && g_ibuf_152[li_40 + 1] == EMPTY_VALUE) {
      if (Time[0] != g_time_256) {
         g_time_256 = Time[0];
         if (EmailON) SendMail("Entry(" + Symbol() + " " + fTimeFrameName(Period()) + ")", "CCI Trend Up");
         if (SoundON || AlertON) {
            fObjLabel("Entry_Bell", 10, 10, StringSetChar("", 0, '%'), 1, Red, 16, li_44, "Wingdings", FALSE);
            if (EndLessRepeat) gi_208 = 1;
            else gi_208 = AlertRepeat;
            g_datetime_216 = 0;
            gi_212 = 0;
         }
      }
   }
   if (g_ibuf_156[li_40] != EMPTY_VALUE && g_ibuf_156[li_40 + 1] == EMPTY_VALUE) {
      if (Time[0] != g_time_260) {
         g_time_260 = Time[0];
         if (EmailON) SendMail("Entry" + Symbol() + " " + fTimeFrameName(Period()) + ")", "CCI Trend Down");
         if (SoundON || AlertON) {
            fObjLabel("Entry_Bell", 10, 10, StringSetChar("", 0, '%'), 1, Red, 16, li_44, "Wingdings", FALSE);
            if (EndLessRepeat) gi_212 = 1;
            else gi_212 = AlertRepeat;
            g_datetime_220 = 0;
            gi_208 = 0;
         }
      }
   }
   if (g_ibuf_160[li_40] != EMPTY_VALUE && g_ibuf_160[li_40 + 1] == EMPTY_VALUE) {
      if (Time[0] != g_time_264) {
         g_time_264 = Time[0];
         if (EmailON) SendMail("Entry(" + Symbol() + " " + fTimeFrameName(Period()) + ")", "Force Trend Up");
         if (SoundON || AlertON) {
            fObjLabel("Entry_Bell", 10, 10, StringSetChar("", 0, '%'), 1, Red, 16, li_44, "Wingdings", FALSE);
            if (EndLessRepeat) gi_224 = 1;
            else gi_224 = AlertRepeat;
            g_datetime_232 = 0;
            gi_228 = 0;
         }
      }
   }
   if (g_ibuf_164[li_40] != EMPTY_VALUE && g_ibuf_164[li_40 + 1] == EMPTY_VALUE) {
      if (Time[0] != g_time_268) {
         g_time_268 = Time[0];
         if (EmailON) SendMail("Entry" + Symbol() + " " + fTimeFrameName(Period()) + ")", "Force Trend Down");
         if (SoundON || AlertON) {
            fObjLabel("Entry_Bell", 10, 10, StringSetChar("", 0, '%'), 1, Red, 16, li_44, "Wingdings", FALSE);
            if (EndLessRepeat) gi_228 = 1;
            else gi_228 = AlertRepeat;
            g_datetime_236 = 0;
            gi_224 = 0;
         }
      }
   }
   if (ObjectFind("Entry_Bell") == li_44) {
      if (gi_176 > 0) {
         if (TimeLocal() > g_datetime_184 + 1) {
            if (!EndLessRepeat) gi_176--;
            g_datetime_184 = TimeLocal();
            if (AlertON) Alert("Entry(" + Symbol() + " " + fTimeFrameName(Period()) + "): WPR Entry Up");
            if (SoundON) {
               Print("Entry(" + Symbol() + " " + fTimeFrameName(Period()) + "): WPR Entry Up");
               PlaySound(SoundFile);
            }
         }
      }
      if (gi_180 > 0) {
         if (TimeLocal() > g_datetime_188 + 1) {
            if (!EndLessRepeat) gi_180--;
            g_datetime_188 = TimeLocal();
            if (AlertON) Alert("Entry(" + Symbol() + " " + fTimeFrameName(Period()) + "): WPR Entry Down");
            if (SoundON) {
               Print("Entry(" + Symbol() + " " + fTimeFrameName(Period()) + "): WPR Entry Down");
               PlaySound(SoundFile);
            }
         }
      }
      if (gi_192 > 0) {
         if (TimeLocal() > g_datetime_200 + 1) {
            if (!EndLessRepeat) gi_192--;
            g_datetime_200 = TimeLocal();
            if (AlertON) Alert("Entry(" + Symbol() + " " + fTimeFrameName(Period()) + "): WPR Trend Up");
            if (SoundON) {
               Print("Entry(" + Symbol() + " " + fTimeFrameName(Period()) + "): WPR Trend Up");
               PlaySound(SoundFile);
            }
         }
      }
      if (gi_196 > 0) {
         if (TimeLocal() > g_datetime_204 + 1) {
            if (!EndLessRepeat) gi_196--;
            g_datetime_204 = TimeLocal();
            if (AlertON) Alert("Entry(" + Symbol() + " " + fTimeFrameName(Period()) + "): WPR Trend Down");
            if (SoundON) {
               Print("Entry(" + Symbol() + " " + fTimeFrameName(Period()) + "): WPR Trend Down");
               PlaySound(SoundFile);
            }
         }
      }
      if (gi_208 > 0) {
         if (TimeLocal() > g_datetime_216 + 1) {
            if (!EndLessRepeat) gi_208--;
            g_datetime_216 = TimeLocal();
            if (AlertON) Alert("Entry(" + Symbol() + " " + fTimeFrameName(Period()) + "): CCI Trend Up");
            if (SoundON) {
               Print("Entry(" + Symbol() + " " + fTimeFrameName(Period()) + "): CCI Trend Up");
               PlaySound(SoundFile);
            }
         }
      }
      if (gi_212 > 0) {
         if (TimeLocal() > g_datetime_220 + 1) {
            if (!EndLessRepeat) gi_212--;
            g_datetime_220 = TimeLocal();
            if (AlertON) Alert("Entry(" + Symbol() + " " + fTimeFrameName(Period()) + "): CCI Trend Down");
            if (SoundON) {
               Print("Entry(" + Symbol() + " " + fTimeFrameName(Period()) + "): CCI Trend Down");
               PlaySound(SoundFile);
            }
         }
      }
      if (gi_224 > 0) {
         if (TimeLocal() > g_datetime_232 + 1) {
            if (!EndLessRepeat) gi_224--;
            g_datetime_232 = TimeLocal();
            if (AlertON) Alert("Entry(" + Symbol() + " " + fTimeFrameName(Period()) + "): Force Trend Up");
            if (SoundON) {
               Print("Entry(" + Symbol() + " " + fTimeFrameName(Period()) + "): Force Trend Up");
               PlaySound(SoundFile);
            }
         }
      }
      if (gi_228 > 0) {
         if (TimeLocal() > g_datetime_236 + 1) {
            if (!EndLessRepeat) gi_228--;
            g_datetime_236 = TimeLocal();
            if (AlertON) Alert("Entry(" + Symbol() + " " + fTimeFrameName(Period()) + "): Force Trend Down");
            if (SoundON) {
               Print("Entry(" + Symbol() + " " + fTimeFrameName(Period()) + "): Force Trend Down");
               PlaySound(SoundFile);
            }
         }
      }
   }
   if (gi_180 <= 0 && gi_176 <= 0 && gi_196 <= 0 && gi_192 <= 0 && gi_212 <= 0 && gi_208 <= 0 && gi_228 <= 0 && gi_224 <= 0) ObjectDelete("Entry_Bell");
   return (0);
}

string fTimeFrameName(int ai_0) {
   int l_timeframe_4;
   if (ai_0 == 0) l_timeframe_4 = Period();
   else l_timeframe_4 = ai_0;
   switch (l_timeframe_4) {
   case 0:
      return ("0");
   case PERIOD_M1:
      return ("M1");
   case PERIOD_M5:
      return ("M5");
   case PERIOD_M15:
      return ("M15");
   case PERIOD_M30:
      return ("M30");
   case PERIOD_H1:
      return ("H1");
   case PERIOD_H4:
      return ("H4");
   case PERIOD_D1:
      return ("D1");
   case PERIOD_W1:
      return ("W1");
   case PERIOD_MN1:
      return ("MN1");
   }
   return ("Wrong TimeFrame");
}

void fObjLabel(string a_name_0, int a_x_8, int a_y_12, string a_text_16, int a_corner_24 = 0, color a_color_28 = 255, int a_fontsize_32 = 8, int a_window_36 = 0, string a_fontname_40 = "Arial", bool a_bool_48 = FALSE) {
   if (ObjectFind(a_name_0) != a_window_36) ObjectCreate(a_name_0, OBJ_LABEL, a_window_36, 0, 0);
   ObjectSet(a_name_0, OBJPROP_XDISTANCE, a_x_8);
   ObjectSet(a_name_0, OBJPROP_YDISTANCE, a_y_12);
   ObjectSetText(a_name_0, a_text_16, a_fontsize_32, a_fontname_40, a_color_28);
   ObjectSet(a_name_0, OBJPROP_BACK, a_bool_48);
   ObjectSet(a_name_0, OBJPROP_CORNER, a_corner_24);
}