Navigation:Home > Content >

ea_magic.mq4

Time: 2015-10-23 | Download file:ea_magic.mq4

#property copyright "Copyright  2007, cocoracas"
#property link      "http://www.forex-tsd.com"

extern double Lots = 0.01;
extern int TakeProfit = 28;
extern int StopLoss = 0;
extern bool ConstantStop = FALSE;
extern int Step1 = 28;
extern int TP1 = 31;
extern int Step2 = 28;
extern int TP2 = 31;
extern int Step3 = 28;
extern int TP3 = 31;
extern int Step4 = 28;
extern int TP4 = 31;
extern int Step5 = 28;
extern int TP5 = 31;
extern int Step6 = 28;
extern int TP6 = 31;
extern int Step7 = 28;
extern int TP7 = 31;
extern int Step8 = 28;
extern int TP8 = 31;
extern int Step9 = 28;
extern int TP9 = 31;
extern int Step10 = 28;
extern int TP10 = 31;
extern int StartHour = 0;
extern int EndHour = 24;
extern int Magic = 111;
extern bool CloseAllNow = FALSE;
extern bool UseMACD = FALSE;
extern int BrokerMode = 1;  // Не стал убирать, BrokerMode = 3 - любой символ по замыслу автора
extern bool MM_advisor = FALSE;
extern int FridayCloseTime = 10;
int G_slippage_208 = 3;
int Gi_212 = 2;

// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   int Li_0;
   int Li_4;
   int ticket_8;
   double price_12;
   double price_20;
   double price_28;
   double lots_36;
   double pips_44;
   double pips_52;
   bool bool_60;
   bool cl,del,mod;
   int tic;
 //  string Ls_64 = "2020.18.10";
 //  int str2time_72 = StrToTime(Ls_64);
 //  if (TimeCurrent() >= str2time_72) {
 //     Alert("Trial version has been expired!");
 //     return (0);
 //  }
   if (CloseAllNow == TRUE) {
      for (int order_total_76 = OrdersTotal(); order_total_76 >= 0; order_total_76--) {
         if(OrderSelect(order_total_76, SELECT_BY_POS, MODE_TRADES)){
         if ((OrderSymbol() == Symbol() || BrokerMode == 3) && OrderMagicNumber() == Magic) {
            if (OrderType() == OP_BUY || OrderType() == OP_SELL) cl=OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), 5, CLR_NONE);
            if (OrderType() != OP_BUY && OrderType() != OP_SELL) del=OrderDelete(OrderTicket());
         }
      }}
      return (0);
   }
   int ticket_80 = 0;
   int ticket_84 = 0;
   int ticket_88 = 0;
   int ticket_92 = 0;
   int Li_unused_96 = 0;
   int Li_unused_100 = 0;
   double order_lots_104 = 0;
   double order_lots_112 = 0;
   double order_open_price_120 = 0;
   double order_open_price_128 = 0;
   double Ld_136 = 0;
   double Ld_144 = 0;
   double Ld_unused_152 = 0;
   double Ld_unused_160 = 0;
   double order_lots_168 = 0;
   double order_lots_176 = 0;
   double Ld_184 = 0;
   double Ld_192 = 0;
   double order_lots_200 = 0;
   double order_lots_208 = 0;
   string Ls_216 = "";
   string Ls_224 = "";
   string Ls_232 = "";
   string Ls_240 = "";
   string Ls_248 = "";
   string Ls_256 = "";
   string Ls_264 = "";
   string Ls_272 = "";
   string Ls_280 = "";
   if (MM_advisor == TRUE) Li_4 = 100;
   else Li_4 = 1;
   if (iMACD(NULL, 0, 14, 26, 9, PRICE_CLOSE, MODE_MAIN, 0) > iMACD(NULL, 0, 14, 26, 9, PRICE_CLOSE, MODE_MAIN, 1)) Li_0 = 2;
   if (iMACD(NULL, 0, 14, 26, 9, PRICE_CLOSE, MODE_MAIN, 0) < iMACD(NULL, 0, 14, 26, 9, PRICE_CLOSE, MODE_MAIN, 1)) Li_0 = 1;
   for (int pos_288 = 0; pos_288 < OrdersTotal(); pos_288++) {
      if(OrderSelect(pos_288, SELECT_BY_POS, MODE_TRADES)){
      if ((OrderSymbol() == Symbol() || BrokerMode == 3) && OrderMagicNumber() == Magic) {
         if (OrderType() == OP_BUY && ticket_80 < OrderTicket()) {
            order_lots_104 = OrderLots();
            order_open_price_120 = OrderOpenPrice();
            ticket_80 = OrderTicket();
            Ld_144 = OrderTakeProfit();
         }
         if (OrderType() == OP_BUY) {
            if (OrderLots() < order_lots_200 || order_lots_200 == 0.0) {
               order_lots_200 = OrderLots();
               Ld_184 = OrderOpenPrice() - StopLoss * Point;
            }
         }
         if (OrderType() == OP_SELL && ticket_84 < OrderTicket()) {
            order_lots_112 = OrderLots();
            order_open_price_128 = OrderOpenPrice();
            ticket_84 = OrderTicket();
            Ld_136 = OrderTakeProfit();
         }
         if (OrderType() == OP_SELL) {
            if (OrderLots() < order_lots_208 || order_lots_208 == 0.0) {
               order_lots_208 = OrderLots();
               Ld_192 = OrderOpenPrice() + StopLoss * Point;
            }
         }
         if (OrderType() == OP_BUYLIMIT) {
            ticket_88 = OrderTicket();
            order_lots_168 = OrderLots();
         }
         if (OrderType() == OP_SELLLIMIT) {
            ticket_92 = OrderTicket();
            order_lots_176 = OrderLots();
         }
      }
   }}
   if (ticket_80 == 0 && ticket_88 != 0) del=OrderDelete(ticket_88);
   if (ticket_80 == 0 && ticket_88 == 0) {
      price_20 = Ask - StopLoss * Point;
      if (StopLoss <= 0) price_20 = 0;
      price_28 = Ask + TakeProfit * Point;
      if ((StartHour < EndHour && TimeHour(TimeCurrent()) >= StartHour && TimeHour(TimeCurrent()) < EndHour) || (StartHour > EndHour && (TimeHour(TimeCurrent()) >= StartHour ||
         TimeHour(TimeCurrent()) < EndHour))) {
         if (DayOfWeek() != 5 || Hour() < FridayCloseTime) {
            if ((Li_0 == 2 && ticket_84 == 0) || UseMACD == FALSE) {
               if (AccountFreeMarginCheck(Symbol(), OP_BUY, Lots * Li_4) >= 0.0) {
                  if (BrokerMode != 2 && BrokerMode != 3) tic=OrderSend(Symbol(), OP_BUY, Lots, Ask, G_slippage_208, price_20, price_28, "Magic = " + Magic, Magic, 0, CLR_NONE);
                  else {
                     ticket_8 = OrderSend(Symbol(), OP_BUY, Lots, Ask, G_slippage_208, 0, 0, "Magic = " + Magic, Magic, 0, CLR_NONE);
                     bool_60 = OrderModify(ticket_8, OrderOpenPrice(), price_20, price_28, 0, CLR_NONE);
                     if (bool_60 == FALSE) Print("Error modifying BUY order : ", GetLastError());
                  }
               } else {
                  if (AccountFreeMarginCheck(Symbol(), OP_BUY, Lots) >= 0.0) Ls_280 = "Recommended to Decrease Lots used or Increase the Balance!";
                  else Ls_232 = "BUY, " + DoubleToStr(Lots, 2) + " lots. ";
               }
            }
         }
      }
   }
   if (ticket_84 == 0 && ticket_92 != 0) del=OrderDelete(ticket_92);
   if (ticket_84 == 0 && ticket_92 == 0) {
      price_20 = Bid + StopLoss * Point;
      if (StopLoss <= 0) price_20 = 0;
      price_28 = Bid - TakeProfit * Point;
      if ((StartHour < EndHour && TimeHour(TimeCurrent()) >= StartHour && TimeHour(TimeCurrent()) < EndHour) || (StartHour > EndHour && (TimeHour(TimeCurrent()) >= StartHour ||
         TimeHour(TimeCurrent()) < EndHour))) {
         if (DayOfWeek() != 5 || Hour() < FridayCloseTime) {
            if ((Li_0 == 1 && ticket_80 == 0) || UseMACD == FALSE) {
               if (AccountFreeMarginCheck(Symbol(), OP_SELL, Lots * Li_4) >= 0.0) {
                  if (BrokerMode != 2 && BrokerMode != 3) tic=OrderSend(Symbol(), OP_SELL, Lots, Bid, G_slippage_208, price_20, price_28, "Magic = " + Magic, Magic, 0, CLR_NONE);
                  else {
                     ticket_8 = OrderSend(Symbol(), OP_SELL, Lots, Bid, G_slippage_208, 0, 0, "Magic = " + Magic, Magic, 0, CLR_NONE);
                     bool_60 = OrderModify(ticket_8, OrderOpenPrice(), price_20, price_28, 0, CLR_NONE);
                     if (bool_60 == FALSE) Print("Error modifying SELL order : ", GetLastError());
                  }
               } else {
                  if (AccountFreeMarginCheck(Symbol(), OP_SELL, Lots) >= 0.0) Ls_280 = "Recommended to Decrease Lots used or Increase the Balance!";
                  else Ls_240 = "SELL, " + DoubleToStr(Lots, 2) + " lots. ";
               }
            }
         }
      }
   }
   if (ticket_80 != 0 && ticket_88 != 0) {
      if (AccountFreeMarginCheck(Symbol(), OP_BUY, order_lots_168) < 0.0) {
         Ls_264 = "BUYLIMIT, " + DoubleToStr(order_lots_168, 2) + " lots. ";
         del=OrderDelete(ticket_88);
      }
   }
   if (ticket_80 != 0 && ticket_88 == 0) {
      if (AccountFreeMarginCheck(Symbol(), OP_BUY, 2.0 * order_lots_104) >= 0.0) {
         pips_52 = f0_1(NormalizeDouble(order_lots_104 / order_lots_200, 0));
         pips_44 = f0_0(NormalizeDouble(order_lots_104 / order_lots_200, 0));
         price_12 = order_open_price_120 - pips_52 * Point;
         if (ConstantStop == FALSE) price_20 = price_12 - StopLoss * Point;
         else price_20 = Ld_184;
         if (StopLoss <= 0) price_20 = 0;
         price_28 = price_12 + pips_44 * Point;
         lots_36 = NormalizeDouble(2.0 * order_lots_104, Gi_212);
         tic=OrderSend(Symbol(), OP_BUYLIMIT, lots_36, price_12, G_slippage_208, price_20, price_28, "Magic = " + Magic, Magic, 0, CLR_NONE);
      } else Ls_248 = "BUYLIMIT, " + DoubleToStr(2.0 * order_lots_104, 2) + " lots. ";
   }
   if (ticket_84 != 0 && ticket_92 != 0) {
      if (AccountFreeMarginCheck(Symbol(), OP_SELL, order_lots_176) < 0.0) {
         Ls_272 = "SELLLIMIT, " + DoubleToStr(order_lots_176, 2) + " lots. ";
         del=OrderDelete(ticket_92);
      }
   }
   if (ticket_84 != 0 && ticket_92 == 0) {
      if (AccountFreeMarginCheck(Symbol(), OP_SELL, 2.0 * order_lots_112) >= 0.0) {
         pips_52 = f0_1(NormalizeDouble(order_lots_112 / order_lots_208, 0));
         pips_44 = f0_0(NormalizeDouble(order_lots_112 / order_lots_208, 0));
         price_12 = order_open_price_128 + pips_52 * Point;
         if (ConstantStop == FALSE) price_20 = price_12 + StopLoss * Point;
         else price_20 = Ld_192;
         if (StopLoss <= 0) price_20 = 0;
         price_28 = price_12 - pips_44 * Point;
         lots_36 = NormalizeDouble(2.0 * order_lots_112, Gi_212);
         tic=OrderSend(Symbol(), OP_SELLLIMIT, lots_36, price_12, G_slippage_208, price_20, price_28, "Magic = " + Magic, Magic, 0, CLR_NONE);
      } else Ls_256 = "SELLLIMIT, " + DoubleToStr(2.0 * order_lots_112, 2) + " lots. ";
   }
   for (pos_288 = 0; pos_288 < OrdersTotal(); pos_288++) {
      if(OrderSelect(pos_288, SELECT_BY_POS, MODE_TRADES)){
      if ((OrderSymbol() == Symbol() || BrokerMode == 3) && OrderType() == OP_BUY && ticket_80 != 0 && OrderMagicNumber() == Magic) {
         if (ConstantStop == FALSE) price_20 = order_open_price_120 - StopLoss * Point;
         else price_20 = Ld_184;
         if (StopLoss <= 0) price_20 = 0;
         if (ticket_80 > OrderTicket()) price_28 = Ld_144;
         else price_28 = OrderTakeProfit();
         if (price_28 != OrderTakeProfit() || price_20 != OrderStopLoss()) mod=OrderModify(OrderTicket(), OrderOpenPrice(), price_20, price_28, 0, CLR_NONE);
      }
      if ((OrderSymbol() == Symbol() || BrokerMode == 3) && OrderType() == OP_SELL && ticket_84 != 0 && OrderMagicNumber() == Magic) {
         if (ConstantStop == FALSE) price_20 = order_open_price_128 + StopLoss * Point;
         else price_20 = Ld_192;
         if (StopLoss <= 0) price_20 = 0;
         if (ticket_84 > OrderTicket()) price_28 = Ld_136;
         else price_28 = OrderTakeProfit();
         if (price_28 != OrderTakeProfit() || price_20 != OrderStopLoss()) mod=OrderModify(OrderTicket(), OrderOpenPrice(), price_20, price_28, 0, CLR_NONE);
      }
   }}
   if (Ls_232 != "" || Ls_240 != "" || Ls_248 != "" || Ls_256 != "" || Ls_264 != "" || Ls_272 != "") Ls_216 = "Not enough balance to Open Position!";
   Comment(Ls_224, 
      "\n", Ls_216, Ls_232, Ls_240, Ls_248, Ls_256, Ls_264, Ls_272, 
   "\n", Ls_280);
   return (0);
}

// 20A91EADFB1ED541FAB72DD08652A9C7
int f0_1(int Ad_0) {
   switch (Ad_0) {
   case 1:
      return (Step1);
   case 2:
      return (Step2);
   case 4:
      return (Step3);
   case 8:
      return (Step4);
   case 16:
      return (Step5);
   case 32:
      return (Step6);
   case 64:
      return (Step7);
   case 128:
      return (Step8);
   case 256:
      return (Step9);
   case 512:
      return (Step10);
   }
   return (Step10);
}

// 20252D8ADC9A5D3B861864B8367D5D89
int f0_0(int Ad_0) {
   switch (Ad_0) {
   case 1:
      return (TP1);
   case 2:
      return (TP2);
   case 4:
      return (TP3);
   case 8:
      return (TP4);
   case 16:
      return (TP5);
   case 32:
      return (TP6);
   case 64:
      return (TP7);
   case 128:
      return (TP8);
   case 256:
      return (TP9);
   case 512:
      return (TP10);
   }
   return (TP10);
}

Recommend