extern string A = "          Account Management";
extern double Lots = 0.1;
extern double MaxLots = 100.0;
extern bool MoneyManagement = TRUE;
extern double Risk = 10.0;
extern double ProfitMultiplier = 2.0;
extern string B = "              Trading Control";
extern bool UseShadowTargets = TRUE;
extern int TakeProfit = 10;
extern int StopLoss = 20;
extern int Slippage = 3;
int gi_144 = 1;
int gi_148 = 2;
int gi_152 = 3;
int gi_156 = 1;
int gi_160 = 2;
int gi_164 = 3;
extern string C = "               Time Control";
extern bool TimeControl = FALSE;
extern int FromTime1 = 0;
extern int ToTime1 = 0;
extern int FromTime2 = 0;
extern int ToTime2 = 0;
int gi_unused_196 = 0;
double g_irsi_200 = 0.0;
int gi_208 = 0;
string gs_unused_212 = "";
string gs_unused_220 = "";
string gs_unused_228 = "";

int start() {
   int li_32;
   int li_36;
   if (Year() > 2010) {
      Alert("Expired Version.. Contract tonybarlo@mail.com for an update");
      return (0);
   }
   if (TimeControl && FromTime1 == 0 || ToTime1 == 0) {
      Alert("Invalid Time: Time cannot be zero hours ");
      return (0);
   }
   if (TakeProfit < 10) {
      Alert("Invalid TakeProfit value: cannot be less than 10 pips");
      return (0);
   }
   if (StopLoss < 20) {
      Alert("Invalid StopLoss value: cannot be less than 20 pips ");
      return (0);
   }
   iBands(Symbol(), 0, 14, 2, 0, PRICE_OPEN, MODE_UPPER, 0);
   iMA(NULL, 0, 7, 2, MODE_SMA, PRICE_CLOSE, 0);
   iMACD(Symbol(), PERIOD_M30, 33, 22, 1, PRICE_HIGH, 3, 0);
   g_irsi_200 = iRSI(Symbol(), 0, 14, PRICE_CLOSE, 0);
   int l_ticket_0 = 0;
   if (TakeProfit == 0 || StopLoss == 0) {
      Alert("TakeProfit & StopLoss are essential options");
      return (0);
   }
   double ld_4 = 0;
   if (StringSubstr(Symbol(), 1, 6) == "EURUSD" || StringSubstr(Symbol(), 1, 6) == "GBPUSD" || StringSubstr(Symbol(), 1, 6) == "NZDUSD" || StringSubstr(Symbol(), 1, 6) == "AUDUSD") ld_4 = 10;
   else {
      if (StringSubstr(Symbol(), 1, 6) == "EURGBP") ld_4 = 19.5;
      else ld_4 = 8.5;
   }
   if (MoneyManagement) Lots = MathRound(AccountBalance() / 1000.0) * Risk / 100.0;
   gi_208 = 100 * Hour() + Minute();
   int l_count_12 = 0;
   double ld_unused_16 = 0;
   int li_24 = 0;
   for (int l_pos_28 = 0; l_pos_28 <= OrdersTotal(); l_pos_28++) {
      OrderSelect(l_pos_28, SELECT_BY_POS, MODE_TRADES);
      if (OrderLots() > 0.0) li_24 = 1.0 * (OrderProfit() / ld_4 * OrderLots()) / OrderLots() / OrderLots();
      if (OrderSymbol() == Symbol()) l_count_12++;
      li_32 = 1;
      li_36 = 1;
      if (l_ticket_0 == 2) {
         li_36 = StopLoss * gi_144;
         li_32 = TakeProfit * gi_156;
      }
      if (l_ticket_0 == 3) {
         li_36 = StopLoss * gi_148;
         li_32 = TakeProfit * gi_160;
      }
      if (l_ticket_0 == 4) {
         li_36 = StopLoss * gi_152;
         li_32 = TakeProfit * gi_164;
      }
      if (OrderType() == OP_BUY)
         if (li_24 >= TakeProfit * li_32 || li_24 <= (-StopLoss) * li_36) OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Blue);
      if (OrderType() == OP_SELL)
         if (li_24 >= TakeProfit * li_32 || li_24 <= (-StopLoss) * li_36) OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, Red);
   }
   if (l_count_12 == 0) {
      if (g_irsi_200 < 40.0 && g_irsi_200 > 30.0) l_ticket_0 = Open_Order("BUY", TakeProfit, StopLoss, Lots, 1);
      if (g_irsi_200 > 60.0 && g_irsi_200 < 70.0) l_ticket_0 = Open_Order("SELL", TakeProfit, StopLoss, Lots, 1);
      if (g_irsi_200 < 30.0 && g_irsi_200 > 20.0) l_ticket_0 = Open_Order("BUY", TakeProfit, StopLoss * gi_144, 2.0 * Lots, 2);
      if (g_irsi_200 > 70.0 && g_irsi_200 < 80.0) l_ticket_0 = Open_Order("SELL", TakeProfit, StopLoss * gi_144, 2.0 * Lots, 2);
      if (g_irsi_200 < 20.0 && g_irsi_200 > 10.0) l_ticket_0 = Open_Order("BUY", TakeProfit * gi_160, StopLoss * gi_148, 4.0 * Lots, 3);
      if (g_irsi_200 > 80.0 && g_irsi_200 < 90.0) l_ticket_0 = Open_Order("SELL", TakeProfit * gi_160, StopLoss * gi_148, 4.0 * Lots, 3);
      if (g_irsi_200 <= 10.0) l_ticket_0 = Open_Order("BUY", TakeProfit * gi_164, StopLoss * gi_152, 6.0 * Lots, 4);
      if (g_irsi_200 >= 90.0) l_ticket_0 = Open_Order("SELL", TakeProfit * gi_164, StopLoss * gi_152, 6.0 * Lots, 4);
   }
   if (l_count_12 == 1 && !(l_ticket_0 == 2)) {
      if (g_irsi_200 < 30.0 && g_irsi_200 > 20.0) l_ticket_0 = Open_Order("BUY", TakeProfit, StopLoss * gi_144, 2.0 * Lots, 2);
      if (g_irsi_200 > 70.0 && g_irsi_200 < 80.0) l_ticket_0 = Open_Order("SELL", TakeProfit, StopLoss * gi_144, 2.0 * Lots, 2);
   }
   if (l_count_12 == 2 && !(l_ticket_0 == 3)) {
      if (g_irsi_200 < 20.0 && g_irsi_200 > 10.0) l_ticket_0 = Open_Order("BUY", TakeProfit * gi_160, StopLoss * gi_148, 4.0 * Lots, 3);
      if (g_irsi_200 > 80.0 && g_irsi_200 < 90.0) l_ticket_0 = Open_Order("SELL", TakeProfit * gi_160, StopLoss * gi_148, 4.0 * Lots, 3);
   }
   if (l_count_12 == 3 && !(l_ticket_0 == 4)) {
      if (g_irsi_200 <= 10.0) l_ticket_0 = Open_Order("BUY", TakeProfit * gi_164, StopLoss * gi_152, 6.0 * Lots, 4);
      if (g_irsi_200 >= 90.0) l_ticket_0 = Open_Order("SELL", TakeProfit * gi_164, StopLoss * gi_152, 6.0 * Lots, 4);
   }
   gs_unused_212 = " ";
   gs_unused_228 = " ";
   gs_unused_220 = " NO ORDERS ";
   if (g_irsi_200 > 60.0) gs_unused_212 = "  _  Entering Sell Zone";
   else {
      if (g_irsi_200 < 40.0) gs_unused_212 = "  _  Entering Buy Zone";
      else gs_unused_212 = "  _  No Trades Zone";
   }
   string l_symbol_40 = " ";
   string l_symbol_48 = " ";
   if (TimeControl)
      if (FromTime1 > 0) l_symbol_40 = StringConcatenate("E.A. to be inactive from: ", FromTime1, "hr to ", ToTime1, "hr");
   if (FromTime2 > 0) l_symbol_48 = StringConcatenate("E.A. to be inactive from: ", FromTime2, "hr to ", ToTime2, "hr");
   if (AccountProfit() / AccountBalance() > ProfitMultiplier / 100.0) CloseAll();
   Comment("___________________________________________________", 
      "\nCopyright © 2006  - ProfitHunter  ", 
      "\nTrial Version 1.3", 
      "\n\nby tonybarlo@mail.com", 
      "\n___________________________________________________", 
      "\n\nBalance: ", AccountBalance(), "   /   Equiry: ", AccountEquity(), " = ", NormalizeDouble(AccountEquity() / AccountBalance(), 2), "%", 
      "\nCurrent Orders for ", Symbol(), ": ", l_count_12, 
      "\n", l_symbol_40, 
      "\n", l_symbol_48, 
   "\n");
   return (0);
}

int Open_Order(string as_0, int ai_8, int ai_12, double a_lots_16, int a_magic_24) {
   gi_208 = 100 * Hour() + Minute();
   if (TimeControl)
      if ((gi_208 >= FromTime1 && gi_208 <= ToTime1) || (gi_208 >= FromTime2 && gi_208 <= ToTime2)) return (0);
   if (a_lots_16 > MaxLots) a_lots_16 = MaxLots;
   if (a_lots_16 < 0.1) a_lots_16 = 0.1;
   if (as_0 == "BUY") {
      if (UseShadowTargets) OrderSend(Symbol(), OP_BUY, a_lots_16, Ask, Slippage, Ask - ai_12 << 1 * Point, Ask + ai_8 << 1 * Point, "Buying ...", a_magic_24, 0, DodgerBlue);
      if (!UseShadowTargets) OrderSend(Symbol(), OP_BUY, a_lots_16, Ask, Slippage, Ask - ai_12 * Point, Ask + ai_8 * Point, "Buying ...", a_magic_24, 0, DodgerBlue);
      return (a_magic_24);
   }
   if (as_0 == "SELL") {
      if (UseShadowTargets) OrderSend(Symbol(), OP_SELL, a_lots_16, Bid, Slippage, Bid + ai_12 << 1 * Point, Bid - ai_8 << 1 * Point, "Selling ...", a_magic_24, 0, Red);
      if (!UseShadowTargets) OrderSend(Symbol(), OP_SELL, a_lots_16, Bid, Slippage, Bid + ai_12 * Point, Bid - ai_8 * Point, "Selling ...", a_magic_24, 0, Red);
      return (a_magic_24);
   }
   return (0);
}

int CloseAll() {
   int l_cmd_8;
   int l_ord_total_0 = OrdersTotal();
   Alert("COLLECTING PROFITS... CLOSING ALL POSITIONS");
   for (int l_pos_4 = 0; l_pos_4 < l_ord_total_0; l_pos_4++) {
      OrderSelect(l_pos_4, SELECT_BY_POS);
      l_cmd_8 = OrderType();
      switch (l_cmd_8) {
      case OP_BUY:
         OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), 5, Blue);
         break;
      case OP_SELL:
         OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), 5, Red);
      }
   }
   return (0);
}