

extern string _d0 = "Pipsmania 1.0";
extern double Lots = 0.1;
int gi_92 = 5;
extern int TakeProfit = 17;
extern int StopLoss = 60;
int gi_104 = 20; 
bool N0S = FALSE;
extern bool MoneyManager = FALSE;
int gi_124 = 10; 
extern int MagicNumber = 302201;
int g_pos_132;
int g_error_136;
int g_spread_140;
int gi_144;
int g_leverage_148;
int g_hour_152;
int gi_156;
int gi_160;
bool gi_164 = FALSE;
bool gi_168 = FALSE;
bool gi_172 = FALSE;
double g_high_176;
double g_low_184;
double gd_192;
double gd_200;
double gd_208;
double g_lots_216;
int g_datetime_224;
string g_comment_228 = "Pipsmania";
string gs_dummy_236;
string gs_dummy_244;
string g_text_252;
string gs_unused_260;
int gia_268[300];
string gsa_272[4207];

int init() {
   g_leverage_148 = AccountLeverage();
   InitErrorArray();
   g_spread_140 = MarketInfo(Symbol(), MODE_SPREAD);
   gd_192 = NormalizeDouble(MarketInfo(Symbol(), MODE_LOTSTEP), 2);
   gd_200 = NormalizeDouble(MarketInfo(Symbol(), MODE_MINLOT), 2);
   gd_208 = NormalizeDouble(MarketInfo(Symbol(), MODE_MAXLOT), 2);
   if (gd_192 == 0.01) gi_144 = 2;
   else gi_144 = 1;
   return (0);
}

int deinit() {
   ObjectDelete("Comment");
   ObjectDelete("Comment2");
   return (0);
}

int start() {
   gi_164 = FALSE;
   gi_168 = FALSE;
   gi_172 = FALSE;
   int l_stoplevel_0 = MarketInfo(Symbol(), MODE_STOPLEVEL);
   if (TakeProfit < l_stoplevel_0) TakeProfit = l_stoplevel_0;
   g_hour_152 = Hour();
   if (StopLoss < l_stoplevel_0) StopLoss = l_stoplevel_0;
   int l_spread_4 = MarketInfo(Symbol(), MODE_SPREAD);
   if (!N0S) {
      gi_156 = gia_268[250] + 1;
      gi_160 = gia_268[120] - 4;
   } else {
      gi_156 = gia_268[250] - 1;
      gi_160 = gia_268[120] - 2;
   }
   if (g_hour_152 >= gi_156 || g_hour_152 <= gi_160) gi_172 = TRUE;
   g_high_176 = High[iHighest(NULL, 0, MODE_HIGH, gi_92, 1)];
   g_low_184 = Low[iLowest(NULL, 0, MODE_LOW, gi_92, 1)];
   if (g_low_184 - Bid == 0.0) gi_164 = TRUE;
   if (Bid - g_high_176 == 0.0) gi_168 = TRUE;
   if (!MoneyManager) g_lots_216 = Lots;
   else g_lots_216 = NormalizeDouble(AccountFreeMargin() * gi_124 / 100000.0 / (g_leverage_148 / 100), gi_144);
   if (IsConnected()) {
      if (IsDemo()) gs_unused_260 = "Demo";
      else gs_unused_260 = "Real";
      ObjectCreate("Comment", OBJ_LABEL, 0, 0, 1.0);
      ObjectSet("Comment", OBJPROP_CORNER, 0);
      ObjectSet("Comment", OBJPROP_XDISTANCE, 3);
      ObjectSet("Comment", OBJPROP_YDISTANCE, 15);
      g_text_252 = "Copyright Pipsmania.com (Pipsmania 1.0";
      ObjectSetText("Comment", g_text_252, 9, "Arial", Red);
      ObjectSet("Comment", OBJPROP_TIMEFRAMES, NULL);
      ObjectSet("Comment", OBJPROP_BACK, FALSE);
   } else ObjectDelete("Comment");
   for (g_pos_132 = 0; g_pos_132 < OrdersTotal(); g_pos_132++) {
      if (OrderSelect(g_pos_132, SELECT_BY_POS)) {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
            if (OrderType() == OP_BUY)
               if ((gi_104 > 0 && Close[0] - OrderOpenPrice() >= (gi_104 + l_spread_4) * Point) || TimeCurrent() - OrderOpenTime() >= 60 * (Period() * StopLoss)) OrderClose(OrderTicket(), OrderLots(), Bid, g_spread_140, Blue);
            if (OrderType() == OP_SELL)
               if ((gi_104 > 0 && OrderOpenPrice() - Close[0] >= (gi_104 + l_spread_4) * Point) || TimeCurrent() - OrderOpenTime() >= 60 * (Period() * StopLoss)) OrderClose(OrderTicket(), OrderLots(), Ask, g_spread_140, Red);
         }
      }
   }
   if (gi_164 && gi_172 && IsTradeAllowed() && AccountFreeMarginCheck(Symbol(), OP_BUY, g_lots_216) > 0.0 && SymbolOrders() < 1 && TimeCurrent() - g_datetime_224 >= 60 * Period()) {
      for (g_pos_132 = 0; g_pos_132 <= 1; g_pos_132++) {
         RefreshRates();
         OrderSend(Symbol(), OP_BUY, g_lots_216, Ask, g_spread_140, Bid - StopLoss * Point, Ask + TakeProfit * Point, g_comment_228, MagicNumber, 0, Blue);
         g_error_136 = GetLastError();
         if (g_error_136 == 0/* NO_ERROR */) {
            g_datetime_224 = TimeCurrent();
            break;
         }
         Print("Trial ¹", g_pos_132 + 1, "- Error Opening: ", PrintError(g_error_136));
      }
   }
   if (gi_168 && gi_172 && IsTradeAllowed() && AccountFreeMarginCheck(Symbol(), OP_BUY, g_lots_216) > 0.0 && SymbolOrders() < 1 && TimeCurrent() - g_datetime_224 >= 60 * Period()) {
      for (g_pos_132 = 0; g_pos_132 <= 1; g_pos_132++) {
         RefreshRates();
         OrderSend(Symbol(), OP_SELL, g_lots_216, Bid, g_spread_140, Ask + StopLoss * Point, Bid - TakeProfit * Point, g_comment_228, MagicNumber, 0, Red);
         g_error_136 = GetLastError();
         if (g_error_136 == 0/* NO_ERROR */) {
            g_datetime_224 = TimeCurrent();
            break;
         }
         Print("Trial ¹", g_pos_132 + 1, "- Error opening: ", PrintError(g_error_136));
      }
   }
   return (0);
}

int SymbolOrders() {
   int li_ret_0;
   for (int l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++) {
      if (OrderSelect(l_pos_4, SELECT_BY_POS)) {
         if (OrderSymbol() == Symbol())
            if (OrderMagicNumber() == MagicNumber) li_ret_0++;
      }
   }
   return (li_ret_0);
}

string PrintError(int ai_0) {
   return (gsa_272[ai_0]);
}

void InitErrorArray() {
   gsa_272[0] = "No errors";
   gsa_272[1] = "No errors, but the result is unknown";
   gsa_272[2] = "total error";
   gsa_272[3] = "Invalid parameters";
   gsa_272[4] = "server busy shopping";
   gsa_272[5] = "The old version of the client terminal";
   gsa_272[6] = "No connection with commercial service";
   gsa_272[7] = "not enough rights";
   gsa_272[8] = "Too often requests";
   gsa_272[9] = "Invalid operation disrupt the server";
   gsa_272[64] = "blocked account";
   gsa_272[65] = "Invalid account number";
   gsa_272[128] = "Expired expectations of the transaction";
   gsa_272[129] = "Invalid value";
   gsa_272[130] = "Wrong Foot";
   gia_268[120] = 5;
   gsa_272[131] = "Invalid volume";
   gsa_272[132] = "The market is closed";
   gsa_272[133] = "Trade is prohibited";
   gsa_272[134] = "Not enough money for the transaction";
   gsa_272[135] = "Price changed";
   gsa_272[136] = "No price";
   gsa_272[137] = "The broker is busy";
   gsa_272[138] = "New prices";
   gia_268[250] = 19;
   gsa_272[139] = "Order has been blocked and processed";
   gsa_272[140] = "Only buy";
   gsa_272[141] = "Too many bugs";
   gsa_272[145] = "Modification is prohibited, as well as the warrant is too close to the market";
   gsa_272[146] = "subsystem busy trade";
   gsa_272[147] = "Use of the expiry of the warrant is prohibited broker";
   gsa_272[148] = "The number of open and pending orders had reached the limit set by the broker";
   gsa_272[4000] = "No errors";
   gsa_272[4001] = "Invalid pointer function";
   gsa_272[4002] = "index of the array - is out of range";
   gsa_272[4003] = "No memory for the stack functions";
   gsa_272[4004] = "Stack after recursive call";
   gsa_272[4005] = "The stack has no memory for settings";
   gsa_272[4006] = "No memory for the string value";
   gsa_272[4007] = "No memory for a temporary line";
   gsa_272[4008] = "Neinitsializirovannaya line";
   gsa_272[4009] = "Neinitsializirovannaya line in the array";
   gsa_272[4010] = "No memory for the string array";
   gsa_272[4011] = "Too long line";
   gsa_272[4012] = "The balance of dividing by zero";
   gsa_272[4013] = "division by zero ";
   gsa_272[4014] = "Neizvestnaya team";
   gsa_272[4015] = "Bad move";
   gsa_272[4016] = "uninitialized array";
   gsa_272[4017] = "Call DLL is not permitted";
   gsa_272[4018] = "Can not load library";
   gsa_272[4019] = "You can not call";
   gsa_272[4020] = "Challenge external library functions are not allowed";
   gsa_272[4021] = "Not enough memory to the line, recovery of function";
   gsa_272[4022] = "System busy";
   gsa_272[4050] = "Wrong number of parameters of the function";
   gsa_272[4051] = "Invalid value of the function";
   gsa_272[4052] = "Internal error string function";
   gsa_272[4053] = "Error Array";
   gsa_272[4054] = "Misuse of solid-taymserii";
   gsa_272[4055] = "Error custom indicator";
   gsa_272[4056] = "Arrays are incompatible";
   gsa_272[4057] = "Error processing globalnyeh variables";
   gsa_272[4058] = "A global variable is not detected";
   gsa_272[4059] = "function is not permitted in test mode";
   gsa_272[4060] = "function is not permitted";
   gsa_272[4061] = "Error sending";
   gsa_272[4062] = "expected value of type string";
   gsa_272[4063] = "expected value of type integer";
   gsa_272[4064] = "parameter type is expected to double";
   gsa_272[4065] = "An option is expected to range";
   gsa_272[4066] = "The requested historical data in a position to update";
   gsa_272[4067] = "Error executing trading transactions";
   gsa_272[4099] = "End of File";
   gsa_272[4100] = "Error in a file";
   gsa_272[4101] = "Invalid filename";
   gsa_272[4102] = "Too many open files";
   gsa_272[4103] = "Can not open file";
   gsa_272[4104] = "Incompatible mode of access to the file";
   gsa_272[4105] = "No warrant is not selected";
   gsa_272[4106] = "unknown character";
   gsa_272[4107] = "Invalid setting prices for commercial functions";
   gsa_272[4108] = "Wrong number Ticket";
   gsa_272[4109] = "Trade is not allowed. It is necessary to enable the option Allow an adviser to trade in the properties of an expert";
   gsa_272[4110] = "Long positions are not allowed. You should check the properties of an expert";
   gsa_272[4111] = "Short positions are not allowed. You should check the properties of an expert";
   gsa_272[4200] = "Object already there";
   gsa_272[4201] = "Requested an unknown object properties";
   gsa_272[4202] = "Object does not exist ";
   gsa_272[4203] = "Unknown type of object";
   gsa_272[4204] = "None of the facility";
   gsa_272[4205] = "Error coordinates";
   gsa_272[4206] = "Not Found specified subwindow";
   gsa_272[4207] = "Error with the object";
}