Navigation´╝ÜHome > Content >

Forex_Noki_Short_.mq4

Time: 2017-12-23 | Download file:Forex_Noki_Short_.mq4

/*
  2014-08-08 by Capella
  - Fixed bugs that prevented compilation
*/
#property copyright "http://www.forexnoki.com"
#property link      "http://www.forexnoki.com"

extern string comment1 = "FOREX NOKI Short Setup";
extern string comment2 = "Use on M5";
extern string comment3 = "Symbol: NOKSEK";
extern string comment4 = "----------------------------";
int Gi_76 = 2;
bool Gi_80 = TRUE;
int Gi_84 = 20;
double Gd_88 = 1.12;
int Gi_96 = 250;
int G_magic_100 = 9876551;
int Gi_104 = 10;
double Gd_108 = 0.01;
string Gs_116 = "";
int Gi_124 = 100;
bool Gi_128 = FALSE;
int Gi_132 = 16;
double Gd_136 = 1.115;
int Gi_144 = 250;
int G_magic_148 = 9876552;
extern string comment5 = "Stopout level";
extern int TradeClose_2 = 10;
extern string comment6 = "Trade lot size";
extern double LotsSize_2 = 0.01;
string Gs_164 = "";
int Gi_172 = 100;
bool Gi_176 = TRUE;
int Gi_180 = 10;
double Gd_184 = 4.2;
int Gi_192 = 1000;
int G_magic_196 = 9876545;
int Gi_200 = 200;
double Gd_204 = 0.01;
string Gs_212 = "";
int Gi_220 = 1000;
bool Gi_224 = TRUE;
int Gi_228 = 10;
double Gd_232 = 7.8;
int Gi_240 = 300;
int G_magic_244 = 9876547;
int Gi_248 = 200;
double Gd_252 = 0.01;
string Gs_260 = "";
int Gi_268 = 300;
bool Gi_272 = TRUE;
int Gi_276 = 10;
double Gd_280 = 8.6;
int Gi_288 = 300;
int G_magic_292 = 9876549;
int Gi_296 = 200;
double Gd_300 = 0.01;
string Gs_308 = "";
int Gi_316 = 300;
bool Gi_320 = TRUE;
int Gi_324 = 14;
double Gd_328 = 1.16;
int Gi_336 = 100;
int G_magic_340 = 9876551;
int Gi_344 = 10;
double Gd_348 = 0.01;
string Gs_356 = "";
int Gi_364 = 200;
bool Gi_368 = TRUE;
int Gi_372 = 6;
double Gd_376 = 1.62;
int Gi_384 = 100;
int G_magic_388 = 1234;
int Gi_392 = 200;
double Gd_396 = 0.1;
string Gs_404 = "";
int Gi_412 = 200;
bool Gi_416;
int G_stoplevel_420;
double Gd_424;
int G_file_432;
bool Gi_436;
extern string comment7 = "Account number";
extern int G_acc_number_440 = 100000000; // Put in your account number here
extern string comment8 = "EA comment";
extern string A_comment_40 = "Noki";
extern string comment9 = "Used magic numbers";
extern string comment10 = "9876551,9876552,9876545,9876547";
extern string comment11 = "9876549,9876551,1234";

// 9A49A11C048922B1031B3CEAC9F666EA
int f0_3() {
   return (MarketInfo(Symbol(), MODE_SPREAD));
}

// CE0BE71E33226E4C1DB2BCEA5959F16B
void f0_4(string As_0) {
   if (G_file_432 >= 0) FileWrite(G_file_432, TimeToStr(TimeCurrent(), TIME_DATE|TIME_SECONDS) + ": " + As_0);
}

// E37F0136AA3FFAF149B351F6A4C948E9
int init() {
   G_stoplevel_420 = MarketInfo(Symbol(), MODE_STOPLEVEL);
   Gi_416 = TRUE;
   Gd_424 = AccountEquity();
   G_file_432 = FileOpen(WindowExpertName() + TimeCurrent() + "_" + Period() + "_" + Symbol() + "_" + G_magic_388 + ".log", FILE_WRITE);
   Gi_436 = TRUE;
   if (Gi_76 == 1) {
      Gi_368 = Gi_80;
      Gi_372 = Gi_84;
      Gd_376 = Gd_88;
      Gi_384 = Gi_96;
      G_magic_388 = G_magic_100;
      Gi_392 = Gi_104;
      Gd_396 = Gd_108;
      Gs_404 = Gs_116;
      Gi_412 = Gi_124;
   } else {
      if (Gi_76 == 2) {
         Gi_368 = Gi_128;
         Gi_372 = Gi_132;
         Gd_376 = Gd_136;
         Gi_384 = Gi_144;
         G_magic_388 = G_magic_148;
         Gi_392 = TradeClose_2;
         Gd_396 = LotsSize_2;
         Gs_404 = Gs_164;
         Gi_412 = Gi_172;
      } else {
         if (Gi_76 == 3) {
            Gi_368 = Gi_176;
            Gi_372 = Gi_180;
            Gd_376 = Gd_184;
            Gi_384 = Gi_192;
            G_magic_388 = G_magic_196;
            Gi_392 = Gi_200;
            Gd_396 = Gd_204;
            Gs_404 = Gs_212;
            Gi_412 = Gi_220;
         } else {
            if (Gi_76 == 4) {
               Gi_368 = Gi_224;
               Gi_372 = Gi_228;
               Gd_376 = Gd_232;
               Gi_384 = Gi_240;
               G_magic_388 = G_magic_244;
               Gi_392 = Gi_248;
               Gd_396 = Gd_252;
               Gs_404 = Gs_260;
               Gi_412 = Gi_268;
            } else {
               if (Gi_76 == 5) {
                  Gi_368 = Gi_272;
                  Gi_372 = Gi_276;
                  Gd_376 = Gd_280;
                  Gi_384 = Gi_288;
                  G_magic_388 = G_magic_292;
                  Gi_392 = Gi_296;
                  Gd_396 = Gd_300;
                  Gs_404 = Gs_308;
                  Gi_412 = Gi_316;
               } else {
                  if (Gi_76 == 6) {
                     Gi_368 = Gi_320;
                     Gi_372 = Gi_324;
                     Gd_376 = Gd_328;
                     Gi_384 = Gi_336;
                     G_magic_388 = G_magic_340;
                     Gi_392 = Gi_344;
                     Gd_396 = Gd_348;
                     Gs_404 = Gs_356;
                     Gi_412 = Gi_364;
                  } else Gi_436 = FALSE;
               }
            }
         }
      }
   }
   return (0);
}

// 52D46093050F38C27267BCE42543EF60
int deinit() {
   FileClose(G_file_432);
   return (0);
}

// 49BD061ED6CDEF203B0586940FB84ED0
int f0_2(double A_price_0, double A_lots_8, double A_price_16, double A_price_24, int A_magic_32, int A_datetime_36) {
   double ask_56;
   int ticket_48 = -1;
   int cmd_52 = -1;
   double price_64 = 0;
   if (A_price_0 == Ask) {
      cmd_52 = 0;
      ask_56 = Ask;
   } else {
      if (A_price_0 <= Ask - G_stoplevel_420 * Point) {
         cmd_52 = 2;
         ask_56 = A_price_0;
      } else {
         if (A_price_0 >= Ask + G_stoplevel_420 * Point) {
            cmd_52 = 4;
            ask_56 = A_price_0;
         } else f0_4("CreateLongTrade tradePrice=" + A_price_0 + ",Ask=" + Ask + ". Cannot put trade");
      }
   }
   if (A_lots_8 == 0.0) f0_4("CreateLongTrade lots=0");
   else {
      if (cmd_52 != -1) {
         if (A_price_16 > 0.0) price_64 = A_price_16;
         ticket_48 = OrderSend(Symbol(), cmd_52, A_lots_8, ask_56, f0_3(), A_price_24, price_64, A_comment_40, A_magic_32, A_datetime_36, Blue);
         if (ticket_48 == -1) f0_4("Long Error= " + GetLastError() + ", price=" + ask_56 + ",sl=" + A_price_24 + ",tp=" + price_64 + ",cmd=" + cmd_52 + ",Bid=" + Bid + ",lots=" + A_lots_8);
         else f0_4("Long OK. rc=" + ticket_48);
      }
   }
   return (ticket_48);
}

// DE1EFE1AA792311BDEBD7BB5412ECF94
int f0_5(double A_price_0, double A_lots_8, double A_price_16, double A_price_24, int A_magic_32, int A_datetime_36) {
   double bid_56;
   int ticket_48 = -1;
   int cmd_52 = -1;
   double price_64 = 0;
   if (A_price_0 == Bid) {
      cmd_52 = 1;
      bid_56 = Bid;
   } else {
      if (A_price_0 >= Bid + G_stoplevel_420 * Point) {
         cmd_52 = 3;
         bid_56 = A_price_0;
      } else {
         if (A_price_0 <= Bid - G_stoplevel_420 * Point) {
            cmd_52 = 5;
            bid_56 = A_price_0;
         } else f0_4("CreateShortTrade tradePrice=" + A_price_0 + ",Bid=" + Bid + ". Cannot put trade");
      }
   }
   if (A_lots_8 == 0.0) f0_4("CreateShortTrade lots=0");
   else {
      if (cmd_52 != -1) {
         if (A_price_16 > 0.0) price_64 = A_price_16;
         ticket_48 = OrderSend(Symbol(), cmd_52, A_lots_8, bid_56, f0_3(), A_price_24, price_64, A_comment_40, A_magic_32, A_datetime_36, Red);
         if (ticket_48 == -1) f0_4("SHORT Error= " + GetLastError() + ", price=" + bid_56 + ",sl=" + A_price_24 + ",tp=" + price_64 + ",cmd=" + cmd_52 + ",lots=" + A_lots_8 + ",Bid=" + Bid);
         else f0_4("SHORT SUCCESS= " + ticket_48 + ", price=" + bid_56 + ",sl=" + A_price_24 + ",tp=" + price_64 + ",cmd=" + cmd_52 + ",lots=" + A_lots_8);
      }
   }
   return (ticket_48);
}

// 0961523B5FB17CA5D291B4CED151A639
int f0_0(double Ad_0) {
   bool Li_ret_8 = FALSE;
   for (int pos_12 = 0; pos_12 < OrdersTotal(); pos_12++) {
      if (OrderSelect(pos_12, SELECT_BY_POS)) {
         if (G_magic_388 == OrderMagicNumber()) {
            if ( ( OrderType() == OP_BUY || OrderType() == OP_BUYLIMIT || OrderType() == OP_BUYSTOP ) && Gi_368 ) 
            {
               if (MathAbs(OrderOpenPrice() - Ad_0) > Point * MarketInfo(Symbol(), MODE_SPREAD) / 2.0) continue;
               Li_ret_8 = TRUE;
               break;
            }
            if ( ( OrderType() == OP_SELL || OrderType() == OP_SELLLIMIT || OrderType() == OP_SELLSTOP ) && !Gi_368 ) 
            {
               if (MathAbs(OrderOpenPrice() - Ad_0) <= Point) {
                  Li_ret_8 = TRUE;
                  break;
               }
            }
         }
      }
   }
   return (Li_ret_8);
}

// 2208AB04CCD91A8303FE0D7679EA198F
int f0_1() {
   bool lots_0 = TRUE;
   for (int pos_4 = OrdersTotal() - 1; pos_4 >= 0; pos_4--) {
      if (OrderSelect(pos_4, SELECT_BY_POS)) {
         if (OrderMagicNumber() == G_magic_388) {
            if (OrderType() == OP_BUY || OrderType() == OP_SELL) {
               f0_4("Tring to close " + OrderTicket());
               lots_0 = lots_0 && OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), f0_3(), White);
               f0_4("rc=" + lots_0);
               continue;
            }
            f0_4("Tring to del " + OrderTicket());
            lots_0 = lots_0 && OrderDelete(OrderTicket());
            f0_4("rc=" + lots_0);
         }
      }
   }
   return (lots_0);
}

// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   double Ld_4;
   double Ld_unused_12 = 0;
   if (!Gi_436) {
      Comment("No set is active!");
      return (0);
   }
   if (TimeCurrent() >= StrToTime("2035.12.30")) {
      Comment("EA has expired.");
      f0_4("EA has expired.");
      return (0);
   }
   if (AccountNumber() != G_acc_number_440) {
      Comment("Wrong account! Working under account #" + G_acc_number_440 + " only.");
      f0_4("Wrong account! Working under account #" + G_acc_number_440 + " only.");
      return (0);
   }
   bool Li_20 = TRUE;
   if (Gs_404 != "") {
      if (TimeCurrent() >= StrToTime(Gs_404)) {
         Comment("Time expired!");
         f0_4("Time expired!");
         Li_20 = FALSE;
      }
   }
   if (Gi_416) {
      if (AccountEquity() <= Gi_392) {
         Gi_416 = FALSE;
         Comment("Trading is stopped due to TradeClose condition");
         f0_4("Trading is stopped due to TradeClose condition. TradeClose=" + Gi_392);
      }
   }
   if (Gi_416) {
      if (Li_20) {
         for (int count_0 = 0; count_0 < Gi_372; count_0++) {
            if (Gi_368) Ld_4 = Gd_376 - count_0 * Gi_384 * Point;
            else Ld_4 = Gd_376 + count_0 * Gi_384 * Point;
            if ((!f0_0(Ld_4)) && MathAbs(Ld_4 - Bid) <= Gi_412 * Point) {
               if (Gi_368) {
                  f0_2(Ld_4, Gd_396, Ld_4 + Gi_384 * Point, 0, G_magic_388, 0);
                  continue;
               }
               f0_5(Ld_4, Gd_396, Ld_4 - Gi_384 * Point, 0, G_magic_388, 0);
            }
         }
      }
   } else f0_1();
   return (0);
}

Recommend