

string Gs_unused_76 = "---------------- Money Management";
double Gd_84 = 0.0;
extern double Gd_92 = 1.2;
extern double LotsBuy = 0.01;
extern double LotsSell = 0.01;
extern bool RiskMM = FALSE;
extern double Risk = 0.0;
string Gs_unused_128 = "---------------- Order Management";
double G_pips_136 = 0.0;
bool Gi_144 = TRUE;
double Gd_148 = 13.0;
double G_pips_156 = 0.0;
double G_pips_164 = 0.0;
double Gd_172 = 1.0;
bool Gi_180 = FALSE;
extern int Gi_184 = 1;
int Gi_unused_188 = 3;
bool Gi_192 = TRUE;
int Gi_196 = 100;
int Gi_200 = 100;
bool Gi_204 = FALSE;
int Gi_208 = 15000;
bool Gi_212 = FALSE;
int Gi_216 = 8000;
string Gs_unused_220 = "---------------- Distance between orders";
double G_pips_228 = 17.0;
int Gi_236 = 0;
string Gs_unused_240 = "---------------- Stochastic Settings";
double G_period_248 = 20.0;
double G_period_256 = 13.0;
double G_slowing_264 = 13.0;
double Gd_272 = 25.0;
double Gd_280 = 0.0;
bool Gi_288 = TRUE;
double Gd_292 = 26.0;
double Gd_300 = 25.0;
double Gd_308 = 0.0;
double Gd_316 = 0.0;
double Gd_324 = 100.0;
double Gd_332 = 100.0;
double Gd_340 = 0.0;
double Gd_348 = 0.0;
string Gs_unused_356 = "---------------- MA Filter Settings";
bool Gi_364 = TRUE;
double G_period_368 = 11.0;
double G_ma_method_376 = 3.0;
double G_applied_price_384 = 0.0;
string Gs_unused_392 = "---------------- Time Filter Settings";
extern bool TimeFilter = FALSE;
extern double StartHour = 0.0;
extern double EndHour = 0.0;
extern bool CloseFriday = FALSE;
extern double CloseFridayHour = 0.0;
double G_magic_432 = 555.0;
double G_magic_440 = 556.0;
double G_order_open_price_448;
double G_order_open_price_456;
double G_order_lots_464;
double G_order_lots_472;
double G_order_lots_480;
double G_order_lots_488;
double G_price_496;
double G_price_504;
double G_price_512;
double G_price_520;
double G_price_528;
double G_price_536;
double G_pos_544;
double G_order_stoploss_552;
double G_order_stoploss_560;
double Gd_592;
double G_free_magrin_600;
double Gd_608;
double Gd_632;
double Gd_672 = 0.0;
int Gi_unused_680 = 0;
int G_ticket_684;
int G_ticket_688;

int OrdersTotalMagicBuy(int A_magic_0) {
   int count_4 = 0;
   for (int pos_8 = 0; pos_8 < OrdersTotal(); pos_8++) {
      if (OrderSelect(pos_8, SELECT_BY_POS, MODE_TRADES))
         if (OrderMagicNumber() == A_magic_0) count_4++;
   }
   return (count_4);
}

int OrdersTotalMagicSell(int A_magic_0) {
   int count_4 = 0;
   for (int pos_8 = 0; pos_8 < OrdersTotal(); pos_8++) {
      if (OrderSelect(pos_8, SELECT_BY_POS, MODE_TRADES))
         if (OrderMagicNumber() == A_magic_0) count_4++;
   }
   return (count_4);
}

int orderclosebuy(int A_ticket_0) {
   double bid_24;
   string symbol_4 = Symbol();
   double digits_12 = MarketInfo(symbol_4, MODE_DIGITS);
   for (int order_total_20 = OrdersTotal(); order_total_20 >= 0; order_total_20--) {
      OrderSelect(order_total_20, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == symbol_4 && OrderMagicNumber() == G_magic_432) {
         A_ticket_0 = OrderTicket();
         OrderSelect(A_ticket_0, SELECT_BY_TICKET, MODE_TRADES);
         G_order_lots_464 = OrderLots();
         bid_24 = MarketInfo(symbol_4, MODE_BID);
         RefreshRates();
         OrderClose(A_ticket_0, G_order_lots_464, NormalizeDouble(bid_24, digits_12), 3, Fuchsia);
      }
   }
   G_order_lots_464 = LotsBuy;
   return (0);
}

int orderclosesell(int A_ticket_0) {
   double ask_24;
   string symbol_4 = Symbol();
   double digits_12 = MarketInfo(symbol_4, MODE_DIGITS);
   for (int order_total_20 = OrdersTotal(); order_total_20 >= 0; order_total_20--) {
      OrderSelect(order_total_20, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == symbol_4 && OrderMagicNumber() == G_magic_440) {
         A_ticket_0 = OrderTicket();
         OrderSelect(A_ticket_0, SELECT_BY_TICKET, MODE_TRADES);
         G_order_lots_472 = OrderLots();
         ask_24 = MarketInfo(symbol_4, MODE_ASK);
         RefreshRates();
         OrderClose(A_ticket_0, G_order_lots_472, NormalizeDouble(ask_24, digits_12), 3, Lime);
      }
   }
   G_order_lots_472 = LotsSell;
   return (0);
}

int start() {
   double Ld_184;
   double Ld_192;
   if (RiskMM) {
      if (Risk < 0.1 || Risk > 100.0) {
         Comment("Invalid Risk Value.");
         return (0);
      }
      LotsBuy = MathFloor(100.0 * (AccountFreeMargin() * AccountLeverage() * Risk * Point) / (Ask * MarketInfo(Symbol(), MODE_LOTSIZE) * MarketInfo(Symbol(), MODE_MINLOT))) * MarketInfo(Symbol(),
         MODE_MINLOT);
      LotsSell = MathFloor(100.0 * (AccountFreeMargin() * AccountLeverage() * Risk * Point) / (Ask * MarketInfo(Symbol(), MODE_LOTSIZE) * MarketInfo(Symbol(), MODE_MINLOT))) * MarketInfo(Symbol(),
         MODE_MINLOT);
   }
   if (RiskMM == FALSE) {
   }
   if (Gd_672 != 0.0 && Gd_84 > 0.0) {
      if (Gd_672 <= AccountBalance() && AccountBalance() <= Gd_672 + Gd_84) Gd_92 = 1;
      else {
         if (AccountBalance() < Gd_672) {
         }
      }
   }
   Gd_672 = AccountBalance();
   double Ld_0 = 0;
   double Ld_8 = 0;
   string symbol_16 = OrderSymbol();
   double spread_24 = MarketInfo(symbol_16, MODE_SPREAD);
   double digits_32 = MarketInfo(symbol_16, MODE_DIGITS);
   double minlot_40 = MarketInfo(symbol_16, MODE_MINLOT);
   double ima_48 = iMA(Symbol(), 0, G_period_368, 0, G_ma_method_376, G_applied_price_384, 1);
   double istochastic_56 = iStochastic(NULL, 0, G_period_248, G_period_256, G_slowing_264, MODE_LWMA, 1, MODE_MAIN, 1);
   double istochastic_64 = iStochastic(NULL, 0, G_period_248, G_period_256, G_slowing_264, MODE_LWMA, 1, MODE_SIGNAL, 1);
   string Ls_72 = "false";
   string Ls_80 = "false";
   if (istochastic_56 > istochastic_64) Ls_72 = "true";
   if (istochastic_56 < istochastic_64) Ls_80 = "true";
   string Ls_88 = "false";
   string Ls_96 = "false";
   if (Gi_288 == FALSE && istochastic_64 < Gd_272) Ls_88 = "true";
   if (Gi_288 == FALSE && istochastic_64 > Gd_280) Ls_96 = "true";
   if (Gi_288 == TRUE && istochastic_64 > Gd_308 && istochastic_64 < Gd_300) Ls_88 = "true";
   if (Gi_288 == TRUE && istochastic_64 > Gd_340 && istochastic_64 < Gd_332) Ls_96 = "true";
   string Ls_104 = "false";
   string Ls_112 = "false";
   if (Gi_288 == TRUE && istochastic_64 <= Gd_348 || istochastic_64 >= Gd_324) Ls_104 = "true";
   if (Gi_288 == TRUE && istochastic_64 >= Gd_292 || istochastic_64 <= Gd_316) Ls_112 = "true";
   string Ls_120 = "false";
   string Ls_128 = "false";
   if (Ask > ima_48 || Gi_364 == FALSE) Ls_120 = "true";
   if (Bid < ima_48 || Gi_364 == FALSE) Ls_128 = "true";
   string Ls_136 = "false";
   if (Gi_184 == Gi_184 || Gi_180 == FALSE) Ls_136 = "true";
   string Ls_144 = "false";
   string Ls_152 = "false";
   if (OrdersTotalMagicBuy(G_magic_432) < Gi_196 || Gi_192 == FALSE) Ls_144 = "true";
   if (OrdersTotalMagicSell(G_magic_440) < Gi_200 || Gi_192 == FALSE) Ls_152 = "true";
   string Ls_160 = "false";
   if (AccountEquity() < Gi_208 || Gi_204 == FALSE) Ls_160 = "true";
   string Ls_168 = "false";
   if (AccountEquity() > Gi_216 || Gi_212 == FALSE) Ls_168 = "true";
   if (TimeFilter == TRUE && Hour() < StartHour || Hour() >= EndHour) return (0);
   string Ls_176 = "false";
   if (CloseFriday == TRUE && DayOfWeek() == 5 && TimeCurrent() >= StrToTime(CloseFridayHour + ":00")) Ls_176 = "true";
   if (minlot_40 == 0.01) {
      Gd_632 = 2;
      Gd_592 = MarketInfo(symbol_16, MODE_MAXLOT);
   }
   if (minlot_40 == 0.1) {
      Gd_632 = 1;
      Gd_592 = AccountBalance() / 2.0 / 1000.0;
   }
   if (OrdersTotalMagicBuy(G_magic_432) > 0) {
      for (G_pos_544 = 0; G_pos_544 < OrdersTotal(); G_pos_544++) {
         OrderSelect(G_pos_544, SELECT_BY_POS, MODE_TRADES);
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == G_magic_432) {
            G_ticket_684 = OrderTicket();
            OrderSelect(G_ticket_684, SELECT_BY_TICKET, MODE_TRADES);
            Ld_184 += OrderLots();
            G_order_open_price_448 = OrderOpenPrice();
            G_order_lots_480 = OrderLots();
         }
      }
      if (Ld_184 + NormalizeDouble(G_order_lots_480 * Gd_92, Gd_632) < Gd_592) {
         if (Gi_236 == 0) {
            if (Ask <= G_order_open_price_448 - G_pips_228 * Point && Ls_120 == "true" && Ls_136 == "true" && Ls_144 == "true" && Ls_160 == "true" && Ls_168 == "true" && Ls_176 == "false" &&
               Ls_72 == "true" && Ls_88 == "true") {
               G_order_lots_464 = Gd_92 * LotsBuy * OrdersTotalMagicBuy(G_magic_432);
               if (G_pips_136 > 0.0) G_price_512 = Ask + G_pips_136 * Point;
               else G_price_512 = 0;
               if (G_pips_156 > 0.0) G_price_528 = Ask - G_pips_156 * Point;
               else G_price_528 = 0;
               RefreshRates();
               G_ticket_684 = OrderSend(Symbol(), OP_BUY, NormalizeDouble(G_order_lots_464, Gd_632), Ask, 3, G_price_528, G_price_512, "MartingailExpert", G_magic_432, 0, Blue);
            }
         }
         if (Gi_236 == 1) {
            if (Ask <= G_order_open_price_448 - (G_pips_228 + OrdersTotalMagicBuy(G_magic_432) + OrdersTotalMagicBuy(G_magic_432) - 2.0) * Point && Ls_120 == "true" && Ls_136 == "true" &&
               Ls_144 == "true" && Ls_160 == "true" && Ls_168 == "true" && Ls_176 == "false" && Ls_72 == "true" && Ls_88 == "true") {
               G_order_lots_464 = Gd_92 * LotsBuy * OrdersTotalMagicBuy(G_magic_432);
               if (G_pips_136 > 0.0) G_price_512 = Ask + G_pips_136 * Point;
               else G_price_512 = 0;
               if (G_pips_156 > 0.0) G_price_528 = Ask - G_pips_156 * Point;
               else G_price_528 = 0;
               RefreshRates();
               G_ticket_684 = OrderSend(Symbol(), OP_BUY, NormalizeDouble(G_order_lots_464, Gd_632), Ask, 3, G_price_528, G_price_512, "MartingailExpert", G_magic_432, 0, Blue);
            }
         }
      }
   }
   if (OrdersTotalMagicSell(G_magic_440) > 0) {
      for (G_pos_544 = 0; G_pos_544 < OrdersTotal(); G_pos_544++) {
         OrderSelect(G_pos_544, SELECT_BY_POS, MODE_TRADES);
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == G_magic_440) {
            G_ticket_688 = OrderTicket();
            OrderSelect(G_ticket_688, SELECT_BY_TICKET, MODE_TRADES);
            Ld_192 += OrderLots();
            G_order_open_price_456 = OrderOpenPrice();
            G_order_lots_488 = OrderLots();
         }
      }
      if (Ld_192 + NormalizeDouble(G_order_lots_488 * Gd_92, Gd_632) < Gd_592) {
         if (Gi_236 == 0) {
            if (Bid >= G_order_open_price_456 + G_pips_228 * Point && Ls_128 == "true" && Ls_136 == "true" && Ls_152 == "true" && Ls_160 == "true" && Ls_168 == "true" && Ls_176 == "false" &&
               Ls_80 == "true" && Ls_96 == "true") {
               G_order_lots_472 = Gd_92 * LotsSell * OrdersTotalMagicSell(G_magic_440);
               if (G_pips_136 > 0.0) G_price_520 = Bid - G_pips_136 * Point;
               else G_price_520 = 0;
               if (G_pips_156 > 0.0) G_price_536 = Bid + G_pips_156 * Point;
               else G_price_536 = 0;
               RefreshRates();
               G_ticket_688 = OrderSend(Symbol(), OP_SELL, NormalizeDouble(G_order_lots_472, Gd_632), Bid, 3, G_price_536, G_price_520, "MartingailExpert", G_magic_440, 0, Red);
            }
         }
         if (Gi_236 == 1) {
            if (Bid >= G_order_open_price_456 + (G_pips_228 + OrdersTotalMagicSell(G_magic_440) + OrdersTotalMagicSell(G_magic_440) - 2.0) * Point && Ls_128 == "true" && Ls_136 == "true" &&
               Ls_152 == "true" && Ls_160 == "true" && Ls_168 == "true" && Ls_176 == "false" && Ls_80 == "true" && Ls_96 == "true") {
               G_order_lots_472 = Gd_92 * LotsSell * OrdersTotalMagicSell(G_magic_440);
               if (G_pips_136 > 0.0) G_price_520 = Bid - G_pips_136 * Point;
               else G_price_520 = 0;
               if (G_pips_156 > 0.0) G_price_536 = Bid + G_pips_156 * Point;
               else G_price_536 = 0;
               RefreshRates();
               G_ticket_688 = OrderSend(Symbol(), OP_SELL, NormalizeDouble(G_order_lots_472, Gd_632), Bid, 3, G_price_536, G_price_512, "MartingailExpert", G_magic_440, 0, Red);
            }
         }
      }
   }
   if (OrdersTotalMagicBuy(G_magic_432) < 1) {
      if (G_pips_136 > 0.0) G_price_512 = Ask + G_pips_136 * Point;
      else G_price_512 = 0;
      if (G_pips_156 > 0.0) G_price_528 = Ask - G_pips_156 * Point;
      else G_price_528 = 0;
      if (Ls_72 == "true" && Ls_88 == "true" && Ls_120 == "true" && Ls_136 == "true" && Ls_144 == "true" && Ls_160 == "true" && Ls_168 == "true" && Ls_176 == "false") G_ticket_684 = OrderSend(Symbol(), OP_BUY, LotsBuy, Ask, 3, G_price_528, G_price_512, "MartingailExpert", G_magic_432, 0, Blue);
   }
   if (OrdersTotalMagicSell(G_magic_440) < 1) {
      if (G_pips_136 > 0.0) G_price_520 = Bid - G_pips_136 * Point;
      else G_price_520 = 0;
      if (G_pips_156 > 0.0) G_price_536 = Bid + G_pips_156 * Point;
      else G_price_536 = 0;
      if (Ls_80 == "true" && Ls_96 == "true" && Ls_128 == "true" && Ls_136 == "true" && Ls_152 == "true" && Ls_160 == "true" && Ls_168 == "true" && Ls_176 == "false") G_ticket_688 = OrderSend(Symbol(), OP_SELL, LotsSell, Bid, 3, G_price_536, G_price_520, "MartingailExpert", G_magic_440, 0, Red);
   }
   for (G_pos_544 = 0; G_pos_544 < OrdersTotal(); G_pos_544++) {
      OrderSelect(G_pos_544, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == G_magic_432) {
         G_ticket_684 = OrderTicket();
         OrderSelect(G_ticket_684, SELECT_BY_TICKET, MODE_TRADES);
         Ld_0 += OrderProfit();
         G_order_open_price_448 = OrderOpenPrice();
      }
   }
   G_price_496 = OrdersTotalMagicBuy(G_magic_432) * Gd_148 * Point + G_order_open_price_448;
   double bid_200 = MarketInfo(Symbol(), MODE_BID);
   if (Gi_144 == TRUE && Ld_0 > 0.0)
      if (Bid >= G_price_496) orderclosebuy(G_ticket_684);
   for (G_pos_544 = 0; G_pos_544 < OrdersTotal(); G_pos_544++) {
      OrderSelect(G_pos_544, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == G_magic_440) {
         G_ticket_688 = OrderTicket();
         OrderSelect(G_ticket_688, SELECT_BY_TICKET, MODE_TRADES);
         Ld_8 += OrderProfit();
         G_order_open_price_456 = OrderOpenPrice();
      }
   }
   G_price_504 = G_order_open_price_456 - OrdersTotalMagicSell(G_magic_440) * Gd_148 * Point;
   double ask_208 = MarketInfo(Symbol(), MODE_ASK);
   if (Gi_144 == TRUE && Ld_8 > 0.0)
      if (Ask <= G_price_504) orderclosesell(G_ticket_688);
   G_free_magrin_600 = AccountFreeMargin();
   Gd_608 = AccountBalance();
   for (G_pos_544 = 0; G_pos_544 < OrdersTotal(); G_pos_544++) {
      OrderSelect(G_pos_544, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == G_magic_432) G_ticket_684 = OrderTicket();
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == G_magic_440) G_ticket_688 = OrderTicket();
   }
   if (Ls_160 == "false" || Ls_168 == "false" || Ls_176 == "true") {
      orderclosesell(G_ticket_688);
      orderclosebuy(G_ticket_684);
   }
   if (Ls_104 == "true") orderclosesell(G_ticket_688);
   if (Ls_112 == "true") orderclosebuy(G_ticket_684);
   if (OrdersTotalMagicBuy(G_magic_432) == 0 || G_pips_136 > 0.0) {
      Ld_0 = 0;
      G_ticket_684 = 0;
      G_price_496 = 0;
   }
   if (OrdersTotalMagicSell(G_magic_440) == 0 || G_pips_136 > 0.0) {
      Ld_8 = 0;
      G_ticket_688 = 0;
      G_price_504 = 0;
   }
   for (int Li_216 = 0; Li_216 < 2; Li_216 += 2) {
      ObjectDelete("rect" + Li_216);
      ObjectCreate("rect" + Li_216, OBJ_HLINE, 0, 0, G_price_504);
      ObjectSet("rect" + Li_216, OBJPROP_COLOR, Red);
      ObjectSet("rect" + Li_216, OBJPROP_WIDTH, 1);
      ObjectSet("rect" + Li_216, OBJPROP_RAY, FALSE);
   }
   for (int Li_220 = 0; Li_220 < 2; Li_220 += 2) {
      ObjectDelete("rect1" + Li_220);
      ObjectCreate("rect1" + Li_220, OBJ_HLINE, 0, 0, G_price_496);
      ObjectSet("rect1" + Li_220, OBJPROP_COLOR, Blue);
      ObjectSet("rect1" + Li_220, OBJPROP_WIDTH, 1);
      ObjectSet("rect1" + Li_220, OBJPROP_RAY, FALSE);
   }
   if (OrdersTotalMagicBuy(G_magic_432) > 1) {
      for (G_pos_544 = 0; G_pos_544 < OrdersTotal(); G_pos_544++) {
         OrderSelect(G_pos_544, SELECT_BY_POS, MODE_TRADES);
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == G_magic_432) {
            G_ticket_684 = OrderTicket();
            OrderSelect(G_ticket_684, SELECT_BY_TICKET, MODE_TRADES);
            G_order_open_price_448 = OrderOpenPrice();
            G_order_stoploss_552 = OrderStopLoss();
            G_ticket_684 = OrderTicket();
         }
      }
      if (Bid - G_order_open_price_448 > Point * G_pips_164) {
         if (G_order_stoploss_552 < Bid - Point * (G_pips_164 + Gd_172 - 1.0) || G_order_stoploss_552 == 0.0) {
            if (G_pips_164 > 0.0) {
               OrderModify(G_ticket_684, G_order_open_price_448, NormalizeDouble(Bid - Point * G_pips_164, digits_32), 0, 0, Gold);
               return (0);
            }
         }
      }
   }
   if (OrdersTotalMagicSell(G_magic_440) > 1) {
      for (G_pos_544 = 0; G_pos_544 < OrdersTotal(); G_pos_544++) {
         OrderSelect(G_pos_544, SELECT_BY_POS, MODE_TRADES);
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == G_magic_440) {
            G_ticket_688 = OrderTicket();
            OrderSelect(G_ticket_688, SELECT_BY_TICKET, MODE_TRADES);
            G_order_open_price_456 = OrderOpenPrice();
            G_order_stoploss_560 = OrderStopLoss();
         }
      }
      if (G_order_open_price_456 - Ask > Point * G_pips_164) {
         if (G_order_stoploss_560 > Ask + Point * (G_pips_164 + Gd_172 - 1.0) || G_order_stoploss_560 == 0.0) {
            if (G_pips_164 > 0.0) {
               OrderModify(G_ticket_688, G_order_open_price_456, NormalizeDouble(Ask + Point * G_pips_164, digits_32), 0, 0, Gold);
               return (0);
            }
         }
      }
   }
   Comment("FreeMargin = ", NormalizeDouble(G_free_magrin_600, 0), "  Balance = ", NormalizeDouble(Gd_608, 0), "  maxLot = ", NormalizeDouble(Gd_592, Gd_632), 
      "\n", "Totalbuy = ", OrdersTotalMagicBuy(G_magic_432), "  Lot = ", Ld_184, "  Totalsell = ", OrdersTotalMagicSell(G_magic_440), "  Lot = ", Ld_192, 
      "\n", "---------------------------------------------------------------", 
      "\n", "Profitbuy = ", Ld_0, 
   "\n", "Profitsell = ", Ld_8);
   if (G_ticket_684 < 0 || G_ticket_688 < 0) {
      if (GetLastError() != 134/* NOT_ENOUGH_MONEY */) return (-1);
      Gi_unused_680 = 1;
      Print("NOT ENOGUGHT MONEY!!");
      return (-1);
   }
   return (0);
}
