Advertisement
Guest User

FOREX 1000 pips Robot (expert advisor for MetaTrader) source code

a guest
Apr 18th, 2015
1,294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 12.15 KB | None | 0 0
  1. /*
  2.    G e n e r a t e d  by ex4-to-mq4 decompiler FREEWARE 4.0.509.5
  3.    Website: HTTP: //Www.M eta q u OT e s. n ET
  4.    E-mail : S UppO Rt @ mE tA qU O TES.NET
  5. */
  6. #property copyright "Copyright © 2013, Rita Lasker"
  7. #property link      "http://www.ritalasker.com"
  8.  
  9. #include <WinUser32.mqh>
  10. #import "kernel32.dll"
  11.    void GetSystemTime(int& a0[]);
  12. #import
  13.  
  14. extern double LotSize = 0.1;
  15. int Gi_84 = 60;
  16. int Gi_88 = 40;
  17. extern int Magic = 111000;
  18. string G_comment_96 = "Forex1000pips eurusd";
  19. extern bool Auto_UTC_OFFSET = TRUE;
  20. int Gi_108 = 0;
  21. int Gi_112 = 1;
  22. int Gi_116 = 3;
  23. int Gi_120 = 23;
  24. int G_period_124 = 6;
  25. int Gi_128 = 1;
  26. int Gi_132 = 2;
  27. int Gi_136 = 11;
  28. int Gi_140 = 20;
  29. double Gd_144 = 2.0;
  30. double Gd_152 = 35.0;
  31. double Gd_160 = 3.0;
  32. int G_slippage_168 = 2;
  33. int Gi_172;
  34. datetime G_time_176;
  35. int Gi_184;
  36. int Gi_188;
  37. bool Gi_192 = TRUE;
  38. int Gi_196;
  39. int G_slippage_200;
  40. double Gd_204;
  41. int G_stoplevel_212;
  42.  
  43. // E37F0136AA3FFAF149B351F6A4C948E9
  44. int init() {
  45.    G_slippage_200 = G_slippage_168;
  46.    Gi_172 = 1;
  47.    Gd_204 = Point;
  48.    if (MarketInfo(Symbol(), MODE_DIGITS) == 5.0 || MarketInfo(Symbol(), MODE_DIGITS) == 3.0) {
  49.       Gi_172 = 10 * Gi_172;
  50.       G_slippage_200 = 10 * G_slippage_200;
  51.       Gd_204 = 10.0 * Gd_204;
  52.    }
  53.    Gi_192 = TRUE;
  54.    return (0);
  55. }
  56.  
  57. // EA2B2676C28C0DB26D39331A336C6B92
  58. int start() {
  59.    double Ld_16;
  60.    double price_28;
  61.    if ((!IsTradeAllowed()) || IsTradeContextBusy() || (!IsConnected()) || (!Gi_192)) return (0);
  62.    G_stoplevel_212 = MarketInfo(Symbol(), MODE_STOPLEVEL);
  63.    int Li_8 = Gi_140;
  64.    if (Li_8 < G_stoplevel_212 / Gi_172 + 3) Li_8 = G_stoplevel_212 / Gi_172 + 3;
  65.    if (Gi_112 > 0 && Gi_116 != Gi_120) {
  66.       if (IsTesting()) {
  67.          if (Auto_UTC_OFFSET) {
  68.             Alert("Auto_UTC_OFFSET should be false at the test mode.");
  69.             Gi_192 = FALSE;
  70.             return (0);
  71.          }
  72.          Gi_196 = Gi_108;
  73.       }
  74.       Gi_196 = Gi_108;
  75.       if (Auto_UTC_OFFSET) Gi_196 = f0_8();
  76.    }
  77.    for (int pos_12 = 0; pos_12 < OrdersTotal(); pos_12++) {
  78.       if (OrderSelect(pos_12, SELECT_BY_POS, MODE_TRADES)) {
  79.          if (OrderMagicNumber() == Magic + Period() && Symbol() == OrderSymbol()) {
  80.             if (OrderType() == OP_BUY) {
  81.                if (OrderOpenPrice() + Li_8 * Gi_172 * Point < Bid && OrderStopLoss() < OrderOpenPrice()) {
  82.                   if (OrderModify(OrderTicket(), OrderOpenPrice(), f0_5(OrderOpenPrice() + 3.0 * Gd_204), OrderTakeProfit(), 0, Blue))
  83.                      if (!IsOptimization()) Print("Order Modify Error ", GetLastError());
  84.                }
  85.             }
  86.             if (OrderType() == OP_SELL) {
  87.                if (OrderOpenPrice() - Li_8 * Gi_172 * Point > Ask && OrderStopLoss() > OrderOpenPrice() || OrderStopLoss() == 0.0) {
  88.                   if (OrderModify(OrderTicket(), OrderOpenPrice(), f0_5(OrderOpenPrice() - 3.0 * Gd_204), OrderTakeProfit(), 0, Blue))
  89.                      if (!IsOptimization()) Print("Order Modify Error ", GetLastError());
  90.                }
  91.             }
  92.          }
  93.       }
  94.    }
  95.    if (Gd_152 > 0.0) {
  96.       Ld_16 = MathMax(Gd_152, G_stoplevel_212 * Point / Gd_204);
  97.       for (int pos_24 = 0; pos_24 < OrdersTotal(); pos_24++) {
  98.          OrderSelect(pos_24, SELECT_BY_POS, MODE_TRADES);
  99.          if (OrderMagicNumber() == Magic + Period()) {
  100.             if (OrderType() <= OP_SELL && OrderSymbol() == Symbol()) {
  101.                if (OrderType() == OP_BUY) {
  102.                   if (!IsTesting()) RefreshRates();
  103.                   if (Bid - OrderOpenPrice() <= Gd_204 * (Ld_16 + Gd_144)) continue;
  104.                   price_28 = f0_5(Bid - Gd_204 * Ld_16);
  105.                   if (f0_5(OrderStopLoss()) >= price_28) continue;
  106.                   if (!(!OrderModify(OrderTicket(), OrderOpenPrice(), price_28, OrderTakeProfit(), 0, Blue))) continue;
  107.                   if (!(!IsOptimization())) continue;
  108.                   Print("TrailingStop Order Modify Error ", GetLastError());
  109.                   continue;
  110.                }
  111.                if (!IsTesting()) RefreshRates();
  112.                if (OrderOpenPrice() - Ask > Gd_204 * (Ld_16 + Gd_144)) {
  113.                   price_28 = f0_5(Ask + Gd_204 * Ld_16);
  114.                   if (f0_5(OrderStopLoss()) > price_28 || OrderStopLoss() == 0.0) {
  115.                      if (!OrderModify(OrderTicket(), OrderOpenPrice(), price_28, OrderTakeProfit(), 0, Red))
  116.                         if (!IsOptimization()) Print("TrailingStop Order Modify Error ", GetLastError());
  117.                   }
  118.                }
  119.             }
  120.          }
  121.       }
  122.    }
  123.    double ima_0 = iMA(Symbol(), 0, G_period_124, 0, MODE_EMA, PRICE_CLOSE, 1);
  124.    for (Gi_184 = 1; iMA(Symbol(), 0, G_period_124, 0, MODE_EMA, PRICE_CLOSE, Gi_184) < Low[Gi_184] - Gi_128 * Gi_172 * Point; Gi_184++) {
  125.    }
  126.    for (Gi_188 = 1; iMA(Symbol(), 0, G_period_124, 0, MODE_EMA, PRICE_CLOSE, Gi_188) > High[Gi_188] + Gi_128 * Gi_172 * Point; Gi_188++) {
  127.    }
  128.    if (f0_7() && G_time_176 != Time[1] && f0_9() == 0) {
  129.       if (Gi_184 >= Gi_132 && Gi_184 < Gi_136 && Ask < ima_0 + Gi_128 * Gi_172 * Point) f0_1(OP_BUY);
  130.       if (Gi_188 >= Gi_132 && Gi_188 < Gi_136 && Bid > ima_0 - Gi_128 * Gi_172 * Point) f0_1(OP_SELL);
  131.    }
  132.    Comment("GMT_OFFSET = " + Gi_196);
  133.    return (0);
  134. }
  135.  
  136. // 76657B14F61FB22008F7F0A3ECD17B0B
  137. double f0_4(double Ad_0) {
  138.    double Ld_ret_8;
  139.    if (LotSize == 0.0) {
  140.       Ld_ret_8 = AccountBalance() * Gd_160 / (100.0 * (Ad_0 * Gi_172 * MarketInfo(Symbol(), MODE_LOTSIZE)));
  141.       Ld_ret_8 = MathRound(Ld_ret_8 / MarketInfo(Symbol(), MODE_LOTSTEP)) * MarketInfo(Symbol(), MODE_LOTSTEP);
  142.       Print(Ld_ret_8);
  143.       if (Ld_ret_8 > MarketInfo(Symbol(), MODE_MAXLOT)) Ld_ret_8 = MarketInfo(Symbol(), MODE_MAXLOT);
  144.       if (Ld_ret_8 < MarketInfo(Symbol(), MODE_MINLOT)) Ld_ret_8 = MarketInfo(Symbol(), MODE_MINLOT);
  145.    } else Ld_ret_8 = LotSize;
  146.    return (Ld_ret_8);
  147. }
  148.  
  149. // EECC5240709741B0055E5D4E5197C899
  150. int f0_9(int A_cmd_0 = -1) {
  151.    int Li_ret_4;
  152.    for (int pos_8 = OrdersTotal() - 1; pos_8 >= 0; pos_8--) {
  153.       OrderSelect(pos_8, SELECT_BY_POS, MODE_TRADES);
  154.       if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic + Period() && OrderType() <= OP_SELL && OrderType() == A_cmd_0 || A_cmd_0 == -1) Li_ret_4++;
  155.    }
  156.    return (Li_ret_4);
  157. }
  158.  
  159. // 32DD001F3588B056DFB819F074CBB255
  160. int f0_3() {
  161.    int Lia_0[4];
  162.    GetSystemTime(Lia_0);
  163.    string Ls_4 = (Lia_0[0] & 65535) + "." + (Lia_0[0] >> 16) + "." + (Lia_0[1] >> 16) + " " + (Lia_0[2] & 65535) + ":" + (Lia_0[2] >> 16) + ":" + (Lia_0[3] & 65535);
  164.    return (StrToTime(Ls_4));
  165. }
  166.  
  167. // DE8222960353C69960E4A4C410BBF5B5
  168. int f0_8() {
  169.    int Li_0 = f0_3();
  170.    double Ld_4 = TimeCurrent() - Li_0;
  171.    Ld_4 /= 3600.0;
  172.    Ld_4 = MathRound(Ld_4);
  173.    int Li_ret_12 = Ld_4;
  174.    return (Li_ret_12);
  175. }
  176.  
  177. // CB992171608A1E190EC5C8B8E8F0B0D5
  178. int f0_7() {
  179.    if (Gi_112 <= 0 || Gi_116 == Gi_120) return (1);
  180.    int Li_0 = Gi_116 + Gi_196;
  181.    int Li_4 = Gi_120 + Gi_196;
  182.    if (Li_0 > 23) Li_0 -= 24;
  183.    if (Li_4 > 23) Li_4 -= 24;
  184.    if (Li_0 < 0) Li_0 += 24;
  185.    if (Li_4 < 0) Li_4 += 24;
  186.    bool Li_ret_8 = FALSE;
  187.    if (Li_0 < Li_4) {
  188.       if (Li_0 <= Hour() && Hour() < Li_4) Li_ret_8 = TRUE;
  189.    } else
  190.       if (Li_0 <= Hour() || Hour() < Li_4) Li_ret_8 = TRUE;
  191.    return (Li_ret_8);
  192. }
  193.  
  194. // 0917FA48FB170A05280272D934078AA4
  195. void f0_1(int A_cmd_0) {
  196.    color color_16;
  197.    double price_20;
  198.    int ticket_28;
  199.    double price_32;
  200.    double price_40;
  201.    double lots_4 = f0_4(Gi_88 * Gi_172 * Point);
  202.    for (int count_12 = 0; count_12 <= 3; count_12++) {
  203.       while (!IsTradeAllowed()) Sleep(5000);
  204.       RefreshRates();
  205.       if (A_cmd_0 == OP_BUY) {
  206.          color_16 = Blue;
  207.          price_20 = f0_5(Ask);
  208.       }
  209.       if (A_cmd_0 == OP_SELL) {
  210.          color_16 = Red;
  211.          price_20 = f0_5(Bid);
  212.       }
  213.       ticket_28 = OrderSend(Symbol(), A_cmd_0, lots_4, price_20, G_slippage_200, 0, 0, G_comment_96, Magic + Period(), 0, color_16);
  214.       if (ticket_28 >= 0) {
  215.          G_time_176 = Time[1];
  216.          Print("Opened Order ", OrderType(), " ", ticket_28);
  217.          OrderSelect(ticket_28, SELECT_BY_TICKET, MODE_TRADES);
  218.          if (Gi_88 > 0) {
  219.             if (A_cmd_0 == OP_BUY) price_32 = f0_6(0, OrderOpenPrice());
  220.             if (A_cmd_0 == OP_SELL) price_32 = f0_6(1, OrderOpenPrice());
  221.             if (!OrderModify(OrderTicket(), OrderOpenPrice(), price_32, 0, 0, color_16))
  222.                if (!IsOptimization()) Print("StopLoss Modify Error ", GetLastError());
  223.          }
  224.          if (Gi_84 <= 0) break;
  225.          if (A_cmd_0 == OP_BUY) price_40 = f0_0(0, OrderOpenPrice());
  226.          if (A_cmd_0 == OP_SELL) price_40 = f0_0(1, OrderOpenPrice());
  227.          if (!(!OrderModify(OrderTicket(), OrderOpenPrice(), price_32, price_40, 0, color_16))) break;
  228.          if (!(!IsOptimization())) break;
  229.          Print("TakeProfit Modify Error ", GetLastError());
  230.          return;
  231.       }
  232.       if (f0_2(GetLastError(), A_cmd_0) != 1) break;
  233.    }
  234. }
  235.  
  236. // B0A149E811F2D51B441305E67D8076BE
  237. double f0_6(int Ai_0, double Ad_4) {
  238.    double Ld_ret_12;
  239.    if (Ai_0 == 0) {
  240.       if (Gi_88 > 0) Ld_ret_12 = f0_5(Ad_4 - Gi_88 * Gd_204);
  241.       else Ld_ret_12 = 0;
  242.       if (Ld_ret_12 > f0_5(Bid - G_stoplevel_212 * Point)) Ld_ret_12 = f0_5(Bid - G_stoplevel_212 * Point);
  243.    }
  244.    if (Ai_0 == 1) {
  245.       if (Gi_88 > 0) Ld_ret_12 = f0_5(Ad_4 + Gi_88 * Gd_204);
  246.       else Ld_ret_12 = 0;
  247.       if (Ld_ret_12 < f0_5(Ask + G_stoplevel_212 * Point) && Ld_ret_12 > 0.0) Ld_ret_12 = f0_5(Ask + G_stoplevel_212 * Point);
  248.    }
  249.    return (Ld_ret_12);
  250. }
  251.  
  252. // 05A64A7383193B4952B035B8116AC6AF
  253. double f0_0(int Ai_0, double Ad_4) {
  254.    double Ld_ret_12;
  255.    if (Ai_0 == 0) {
  256.       if (Gi_84 <= 0) Ld_ret_12 = 0;
  257.       else Ld_ret_12 = f0_5(Ad_4 + Gi_84 * Gd_204);
  258.       if (Ld_ret_12 < f0_5(Bid + G_stoplevel_212 * Point) && Ld_ret_12 > 0.0) Ld_ret_12 = f0_5(Bid + G_stoplevel_212 * Point);
  259.    }
  260.    if (Ai_0 == 1) {
  261.       if (Gi_84 <= 0) Ld_ret_12 = 0;
  262.       else Ld_ret_12 = f0_5(Ad_4 - Gi_84 * Gd_204);
  263.       if (Ld_ret_12 > f0_5(Ask - G_stoplevel_212 * Point)) Ld_ret_12 = f0_5(Ask - G_stoplevel_212 * Point);
  264.    }
  265.    return (Ld_ret_12);
  266. }
  267.  
  268. // 195677E88BAA51D8B3E188E8E36789FC
  269. int f0_2(int Ai_0, int Ai_4) {
  270.    switch (Ai_0) {
  271.    case 4:
  272.       Alert(Symbol(), ": Trade server is busy. Try repeat...");
  273.       Sleep(3000);
  274.       return (1);
  275.    case 6:
  276.       Alert(Symbol(), ": No connection with trade server. Try repeat...");
  277.       Sleep(5000);
  278.       return (1);
  279.    case 128:
  280.       Alert(Symbol(), ": Trade timeout. Try repeat...");
  281.       Sleep(66000);
  282.       if (Ai_4 > 1) return (1);
  283.       if (f0_9(Ai_4) > 0) return (0);
  284.       return (1);
  285.    case 142:
  286.       Alert(Symbol(), ": Trade timeout. Try repeat...");
  287.       Sleep(66000);
  288.       if (Ai_4 > 1) return (1);
  289.       if (f0_9(Ai_4) > 0) return (0);
  290.       return (1);
  291.    case 143:
  292.       Alert(Symbol(), ": Trade timeout. Try repeat...");
  293.       Sleep(66000);
  294.       if (Ai_4 > 1) return (1);
  295.       if (f0_9(Ai_4) > 0) return (0);
  296.       return (1);
  297.    case 129:
  298.       Alert(Symbol(), ": Invalid price. Try repeat...");
  299.       Sleep(3000);
  300.       return (1);
  301.    case 135:
  302.       Alert(Symbol(), ": Price changed. Try repeat...");
  303.       RefreshRates();
  304.       return (1);
  305.    case 136:
  306.       Alert(Symbol(), ": Off quotes. Wait new tick...");
  307.       while (!RefreshRates()) Sleep(1);
  308.       return (1);
  309.    case 137:
  310.       Alert(Symbol(), ": Broker is busy. Try repeat...");
  311.       Sleep(3000);
  312.       return (1);
  313.    case 138:
  314.       Alert(Symbol(), ": Requote. Try repeat...");
  315.       Sleep(5000);
  316.       return (1);
  317.    case 146:
  318.       Alert(Symbol(), ": Trade context is busy. Try repeat...");
  319.       Sleep(500);
  320.       return (1);
  321.    case 2:
  322.       Alert("Common error.");
  323.       return (0);
  324.    case 5:
  325.       Alert("Old version of the client terminal.");
  326.       Gi_192 = FALSE;
  327.       return (0);
  328.    case 64:
  329.       Alert("Account disabled.");
  330.       Gi_192 = FALSE;
  331.       return (0);
  332.    case 133:
  333.       Alert("Trade is disabled.");
  334.       return (0);
  335.    case 134:
  336.       Alert(Symbol(), ": Not enough money.");
  337.       return (0);
  338.    }
  339.    Alert(Symbol(), ": Is other error ", Ai_0);
  340.    return (0);
  341. }
  342.  
  343. // 9A116C50D133C8648404081885194300
  344. double f0_5(double Ad_0) {
  345.    return (NormalizeDouble(Ad_0, Digits));
  346. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement