/*
   Generated by EX4-TO-MQ4 decompiler V4.0.224.1 []
   Website: http://purebeam.biz
   E-mail : purebeam@gmail.com
*/
#property copyright "Copyright © 2010, ForexSecretAgent"
#property link      "Copyright © 2010, www.ForexSecretAgent.com"

#import "ForexSecretAgentAlert.dll"
   int Activation();
   int CheckForLong(int a0, double a1, double a2, double a3, double a4, int a5, string a6, int a7);
   int CheckForShort(int a0, double a1, double a2, double a3, double a4, int a5, string a6, int a7);
#import

extern color Alert.Entry.Color = Blue;
extern color Alert.StopLoss.Color = Red;
extern color Alert.TakeProfit.Color = Green;
extern bool Show.Information.Label = TRUE;
extern color Label.Color = Red;
extern int Label.Font.Size = 12;
int gi_unused_100 = 32768;
int gi_unused_104 = 255;
bool gi_unused_108 = FALSE;
int gi_112 = 5;
int gi_116 = 1;
int gi_120 = 1;
int gi_unused_124 = 100;
int gi_unused_128 = 100;
int gi_unused_132 = 3;
double g_pips_136 = 1.0;
int g_time_144 = 0;
int gi_unused_148 = 0;
string gs_unused_152 = "";
int gi_160 = 5;
int gi_164 = 5;
double g_price_168 = 0.0;
double g_price_176 = 0.0;
double g_price_184 = 0.0;
string gs_192 = "";
string gs_unused_200 = "";
bool gi_unused_208 = FALSE;
bool gi_unused_212 = FALSE;
int gi_unused_216 = 0;
double g_icustom_220;
double g_icustom_244;
double g_icustom_252;
double g_icustom_260;
double g_icustom_268;
int gi_280;

int init() {
   if (IsDllsAllowed() == FALSE) {
      Print("DLL call is not allowed. Experts cannot run.");
      return (0);
   }
   if (IsLibrariesAllowed() == FALSE) {
      Print("Library call is not allowed.");
      return (0);
   }
   int li_0 = Activation();
   Comments();
   if (li_0 < 1) {
      Print("EA expired - Please download the new version from the link emailed to you.");
      return (0);
   }
   if (li_0 < 6) Print("Upgrade available! Please check your email for download link.");
   SetDigits();
   Comments();
   if (Show.Information.Label) SetLabels();
   HideTestIndicators(TRUE);
   switch (Period()) {
   case PERIOD_M1:
      gi_160 = 5.0 * Point * g_pips_136;
      gi_164 = 100;
      break;
   case PERIOD_M5:
      gi_160 = 7.0 * Point * g_pips_136;
      gi_164 = 100;
      break;
   case PERIOD_M15:
      gi_160 = 30.0 * Point * g_pips_136;
      gi_164 = 100;
      break;
   case PERIOD_M30:
      gi_160 = 50.0 * Point * g_pips_136;
      gi_164 = 100;
      break;
   case PERIOD_H1:
      gi_160 = 80.0 * Point * g_pips_136;
      gi_164 = 100;
      break;
   case PERIOD_H4:
      gi_160 = 80.0 * Point * g_pips_136;
      gi_164 = 100;
      break;
   case PERIOD_D1:
      gi_160 = 100.0 * Point * g_pips_136;
      gi_164 = 100;
      break;
   case PERIOD_W1:
      gi_160 = 100.0 * Point * g_pips_136;
      gi_164 = 100;
      break;
   default:
      Print("Not valid period");
   }
   return (0);
}

bool CheckTimeToTrade() {
   bool li_ret_0 = TRUE;
   if (Hour() == 0) li_ret_0 = TRUE;
   if (DayOfWeek() == 0 || (DayOfWeek() == 5 && Hour() < 19) || (DayOfWeek() == 1 && Hour() < 6)) li_ret_0 = FALSE;
   return (li_ret_0);
}

void DoAlert(string as_0, int ai_8) {
   int li_unused_16 = 1;
   ObjectsDeleteAll();
   MessageBox(as_0, "Forex Secret Agent Alert", 0);
   createArrow(ai_8);
}

void createArrow(int ai_0) {
   deleteObject("secret_down");
   deleteObject("secret_up");
   if (ai_0 == 0) {
      ObjectCreate("secret_down", OBJ_ARROW, 0, Time[0], High[1] + gi_160);
      ObjectSet("secret_down", OBJPROP_STYLE, STYLE_DOT);
      ObjectSet("secret_down", OBJPROP_ARROWCODE, SYMBOL_THUMBSDOWN);
      ObjectSet("secret_down", OBJPROP_COLOR, Alert.Entry.Color);
      ObjectSet("secret_down", OBJPROP_WIDTH, 4);
      ObjectCreate("SellSL", OBJ_HLINE, 0, 0, g_price_168);
      ObjectSetText("SellSL", "Stop Loss", 16, "Arial", Alert.StopLoss.Color);
      ObjectSet("SellSL", OBJPROP_WIDTH, 2);
      ObjectSet("SellSL", OBJPROP_STYLE, STYLE_DASH);
      ObjectSet("SellSL", OBJPROP_COLOR, Alert.StopLoss.Color);
      ObjectCreate("SellEP", OBJ_HLINE, 0, 0, g_price_176);
      ObjectSetText("SellEP", "Sell in " + g_price_176, 16, "Arial", Alert.Entry.Color);
      ObjectSet("SellEP", OBJPROP_WIDTH, 2);
      ObjectSet("SellEP", OBJPROP_STYLE, STYLE_DASH);
      ObjectSet("SellEP", OBJPROP_COLOR, Alert.Entry.Color);
      ObjectCreate("SellTP", OBJ_HLINE, 0, 0, g_price_184);
      ObjectSetText("SellTP", "Take Profit", 16, "Arial", Alert.TakeProfit.Color);
      ObjectSet("SellTP", OBJPROP_WIDTH, 2);
      ObjectSet("SellTP", OBJPROP_STYLE, STYLE_DASH);
      ObjectSet("SellTP", OBJPROP_COLOR, Alert.TakeProfit.Color);
      return;
   }
   ObjectCreate("secret_up", OBJ_ARROW, 0, Time[0], Low[1] - gi_160);
   ObjectSet("secret_up", OBJPROP_STYLE, STYLE_DOT);
   ObjectSet("secret_up", OBJPROP_ARROWCODE, SYMBOL_THUMBSUP);
   ObjectSet("secret_up", OBJPROP_COLOR, Alert.Entry.Color);
   ObjectSet("secret_up", OBJPROP_WIDTH, 4);
   ObjectCreate("BuySL", OBJ_HLINE, 0, 0, g_price_168);
   ObjectSetText("BuySL", "STOP LOSS", 16, "Arial", Alert.StopLoss.Color);
   ObjectSet("BuySL", OBJPROP_WIDTH, 2);
   ObjectSet("BuySL", OBJPROP_STYLE, STYLE_DASH);
   ObjectSet("BuySL", OBJPROP_COLOR, Alert.StopLoss.Color);
   ObjectCreate("BuyEP", OBJ_HLINE, 0, 0, g_price_176);
   ObjectSetText("BuyEP", "Sell in " + g_price_176, 16, "Arial", Alert.Entry.Color);
   ObjectSet("BuyEP", OBJPROP_WIDTH, 2);
   ObjectSet("BuyEP", OBJPROP_STYLE, STYLE_DASH);
   ObjectSet("BuyEP", OBJPROP_COLOR, Alert.Entry.Color);
   ObjectCreate("BuyTP", OBJ_HLINE, 0, 0, g_price_184);
   ObjectSetText("BuyTP", "Take Profit", 16, "Arial", Alert.TakeProfit.Color);
   ObjectSet("BuyTP", OBJPROP_WIDTH, 2);
   ObjectSet("BuyTP", OBJPROP_STYLE, STYLE_DASH);
   ObjectSet("BuyTP", OBJPROP_COLOR, Alert.TakeProfit.Color);
}

int deinit() {
   return (0);
}

int start() {
   Comments();
   if (Show.Information.Label) SetLabels();
   else {
      deleteObject("Time");
      deleteObject("Spread");
   }
   Comments();
   if (CheckTimeToTrade()) CheckForOpen();
   return (0);
}

void deleteObject(string a_name_0) {
   if (ObjectFind(a_name_0) != -1) ObjectDelete(a_name_0);
}

void SetLabels() {
   if (ObjectFind("Time") == -1) ObjectCreate("Time", OBJ_LABEL, 0, 0, 0);
   ObjectSet("Time", OBJPROP_CORNER, 1);
   ObjectSet("Time", OBJPROP_XDISTANCE, 15);
   ObjectSet("Time", OBJPROP_YDISTANCE, 35);
   ObjectSet("Time", OBJPROP_BACK, TRUE);
   int li_16 = Time[0] + 60 * Period() - TimeCurrent();
   int li_20 = li_16 % 60;
   li_16 = (li_16 - li_16 % 60) / 60;
   string l_text_0 = li_16 + " minutes " + li_20 + " seconds left to bar end ";
   ObjectSetText("Time", l_text_0, Label.Font.Size, "Tahoma", Label.Color);
   if (ObjectFind("Spread") == -1) ObjectCreate("Spread", OBJ_LABEL, 0, 0, 0);
   ObjectSet("Spread", OBJPROP_CORNER, 1);
   ObjectSet("Spread", OBJPROP_XDISTANCE, 15);
   ObjectSet("Spread", OBJPROP_YDISTANCE, 15);
   ObjectSet("Spread", OBJPROP_BACK, TRUE);
   double ld_24 = (Ask - Bid) / Point / g_pips_136;
   string l_text_8 = "Scanning for trade ... ";
   if (g_price_176 > 0.0) l_text_8 = "Recommended Entry Point: " + DoubleToStr(g_price_176, Digits) + " SL: " + DoubleToStr(g_price_168, Digits) + " TP: " + DoubleToStr(g_price_184, Digits);
   ObjectSetText("Spread", l_text_8, Label.Font.Size, "Tahoma", Label.Color);
}

void SetDigits() {
   if (Digits == 5 || Digits == 3) g_pips_136 = 10;
}

void CheckForOpen() {
   double l_ibearspower_36;
   double l_ibullspower_44;
   double l_iatr_52;
   double l_istochastic_60;
   double l_ibearspower_20 = 0;
   double l_ibullspower_28 = 0;
   RefreshRates();
   double ld_0 = MarketInfo(Symbol(), MODE_SPREAD) / g_pips_136;
   gi_280 = 0;
   for (g_icustom_220 = iCustom(Symbol(), 0, "ZigZag", gi_112, gi_116, gi_120, 0, gi_280); g_icustom_220 == 0.0; g_icustom_220 = iCustom(Symbol(), 0, "ZigZag", gi_112, gi_116, gi_120, 0, gi_280)) gi_280++;
   g_icustom_244 = g_icustom_220;
   gi_280++;
   for (g_icustom_220 = iCustom(Symbol(), 0, "ZigZag", gi_112, gi_116, gi_120, 0, gi_280); g_icustom_220 == 0.0; g_icustom_220 = iCustom(Symbol(), 0, "ZigZag", gi_112, gi_116, gi_120, 0, gi_280)) gi_280++;
   g_icustom_252 = g_icustom_220;
   gi_280++;
   for (g_icustom_220 = iCustom(Symbol(), 0, "ZigZag", gi_112, gi_116, gi_120, 0, gi_280); g_icustom_220 == 0.0; g_icustom_220 = iCustom(Symbol(), 0, "ZigZag", gi_112, gi_116, gi_120, 0, gi_280)) gi_280++;
   g_icustom_260 = g_icustom_220;
   l_ibearspower_20 = iBearsPower(NULL, 0, 13, PRICE_CLOSE, gi_280);
   l_ibullspower_28 = iBullsPower(NULL, 0, 13, PRICE_CLOSE, gi_280);
   if (g_icustom_244 > g_icustom_252) {
      if (gs_192 == "DOWN") {
      }
      gs_192 = "UP";
   } else {
      if (gs_192 == "UP") {
      }
      gs_192 = "DOWN";
   }
   if (g_icustom_268 != g_icustom_260) {
      l_ibearspower_36 = iBearsPower(NULL, 0, 13, PRICE_CLOSE, 0);
      l_ibullspower_44 = iBullsPower(NULL, 0, 13, PRICE_CLOSE, 0);
      l_iatr_52 = iATR(NULL, 0, 12, 0);
      l_istochastic_60 = iStochastic(NULL, 0, 5, 3, 3, MODE_SMA, 0, MODE_MAIN, 0);
      if (Time[0] > g_time_144 && CheckForLong(0, l_ibullspower_44, l_ibearspower_36, l_iatr_52, l_istochastic_60, 0, Symbol(), Period()) == 1 && l_ibullspower_44 > l_ibullspower_28 &&
         gs_192 == "UP" && Ask > g_icustom_260 + ld_0 * Point * g_pips_136 && Ask < g_icustom_260 + gi_164 * Point * g_pips_136) {
         Comments();
         g_icustom_268 = g_icustom_260;
         g_price_168 = g_icustom_252;
         g_price_176 = NormalizeDouble(g_icustom_260 + Point * g_pips_136 + ld_0 * Point, Digits);
         g_price_184 = NormalizeDouble(g_price_176 + (g_price_176 - g_price_168), Digits);
         DoAlert("Forex Secret Agent Buy " + Symbol() + " " + Period() + " min ", 1);
         g_time_144 = Time[0];
      }
      if (Time[0] > g_time_144 && CheckForShort(1, l_ibullspower_44, l_ibearspower_36, l_iatr_52, l_istochastic_60, 0, Symbol(), Period()) == 1 && gs_192 == "DOWN" && l_ibearspower_36 < l_ibearspower_20 &&
         Bid < g_icustom_260 && Bid > g_icustom_260 - gi_164 * Point * g_pips_136) {
         Comments();
         g_price_168 = NormalizeDouble(g_icustom_252 + Point * g_pips_136 + ld_0 * Point, Digits);
         g_price_176 = g_icustom_260;
         g_price_184 = NormalizeDouble(g_price_176 - (g_price_168 - g_price_176), Digits);
         g_icustom_268 = g_icustom_260;
         DoAlert("Forex Secret Agent Sell " + Symbol() + " " + Period() + " min ", 0);
         g_time_144 = Time[0];
      }
   }
}

void Comments() {
   string ls_4 = "\n";
   string ls_12 = "" 
      + "\n" 
      + "Copyright © 2010, www.ForexSecretAgent.com" 
      + "\n" 
      + "Forex Secret Agent Alert ver 1.0 © Build 01" 
      + "\n" 
      + "==============================" 
      + "\n" 
      + "ALERT INFORMATION:" 
      + "\n" 
      + "Recommended Entry Point " + DoubleToStr(g_price_176, Digits) + ls_4 + "Recommended StopLoss    " + DoubleToStr(g_price_168, Digits) + ls_4 + "Recommended TakeProfit  " + DoubleToStr(g_price_184, Digits) + ls_4 + "Current.Broker.Spread   " + DoubleToStr(MarketInfo(Symbol(), MODE_SPREAD) / g_pips_136, 2) + ls_4 + "Current Trend Direction         " + gs_192 + ls_4 
      + "\n" 
   + "==============================";
   for (int l_count_0 = 0; !IsStopped() && !IsConnected(); l_count_0++) {
      Comment("Waiting for connection");
      Sleep(150);
   }
   Comment(ls_12);
}
