#property copyright "Copyright © 2005, MetaQuotes Software Corp."
#property link      "http://www.metaquotes.net"
#property show_inputs

#include <WinUser32.mqh>
#include <stdlib.mqh>

#import "user32.dll"
   int GetDlgItem(int a0, int a1);
   int GetAncestor(int a0, int a1);
   int SendMessageA(int a0, int a1, int a2, int a3);
   int PostMessageA(int a0, int a1, int a2, int a3);
   int FindWindowA(string a0, string a1);
   int SetWindowTextA(int a0, string a1);
   int GetWindow(int a0, int a1);
#import "newest.dll"
   string val_bid_ask(string a0);
   string inits(string a0);
#import

string gs_76 = "The Skyla Foundation ||  Best EA ||  Version 3.2";
extern bool read_pr_nastr = FALSE;
extern bool trade = TRUE;
extern double MinUr = 5.0;
extern double Slippage = 2.0;
extern double Lots = 0.1;
extern int LotsPercent = 40;
extern double max_lots = 2.9;
extern int TakeProfit = 0;
extern int StopLoss = 0;
extern double FixTP = 1.0;
extern double FixSL = 7.0;
extern int sdvig_bid = 0;
extern int luft = 0;
extern int Fixspred = 0;
extern bool whc = FALSE;
extern int NTrades = 3;
extern bool sound = TRUE;
extern bool spred_saxo = TRUE;
extern bool visual = TRUE;
extern bool visual_bid = TRUE;
extern bool visual_pr_kotir = FALSE;
extern bool new_kot = FALSE;
extern bool ruka = FALSE;
extern int Dig = 1;
extern bool setka = FALSE;
extern bool mt_setka_vykl = FALSE;
string gs_212 = "";
int gi_220 = 3;
double gd_224 = 0.0;
int gi_232 = 300;
double gd_236;
double gd_244;
double gd_252;
int gi_260;
int g_color_264 = Green;
string gs_268 = "expert.wav";
double g_point_276;
string gs_dummy_284;
string gs_dummy_292;
int g_fontsize_300;
int g_fontsize_304;
double gd_308;
double gd_316;
int g_magic_324;
int gi_328;
int gi_332;
double gd_340;
int g_ticket_352;
int g_pos_356;
int g_count_360;
string gs_dummy_364;
string gs_dummy_372;
string gs_380;
string gs_388;
string gs_396;
double gd_unused_404 = 0.0;
double gd_412;
double gd_420;
double gd_436;
double gd_444;
double gd_452;
double gd_460;
double gd_468;
string gs_dummy_492;
string gs_500;
double gd_508;
double gd_516;
int gi_524;
int gi_unused_528 = 0;
int gi_532;
int gi_536;
int gi_540;
int gi_548;
extern int Account = 99460;
string gs_556;
double gd_564;
double g_ask_572;
double g_marginrequired_580;
double g_lotstep_588;
double g_minlot_596;
double g_maxlot_604;
string gs_612 = "";
string gs_620;
string gs_628;
string g_symbol_636;
string gs_644;
string gs_652;
string gs_dummy_660;
bool gi_668 = FALSE;
int gi_unused_672;

int start() {
   int li_0;
   double l_price_24;
   double l_price_32;
   string ls_unused_48;
   if (AccountNumber() != Account) {
      Print("Неправильный номер счёта");
      return (0);
   }
   g_symbol_636 = "";
   gi_unused_672 = 0;
   int li_40 = GetTickCount();
   MathSrand(TimeLocal());
   g_magic_324 = MathRand();
   if (ruka) g_magic_324 = 0;
   double ld_56 = TakeProfit;
   double ld_64 = StopLoss;
   g_marginrequired_580 = MarketInfo(Symbol(), MODE_MARGINREQUIRED);
   g_lotstep_588 = MarketInfo(Symbol(), MODE_LOTSTEP);
   g_minlot_596 = MarketInfo(Symbol(), MODE_MINLOT);
   g_maxlot_604 = MarketInfo(Symbol(), MODE_MAXLOT);
   bool li_72 = TRUE;
   while (IsStopped() == FALSE) {
      if (AccountEquity() != 0.0 && li_72 == TRUE) {
         mr();
         getsizelot();
         li_72 = FALSE;
      }
      gs_500 = gs_76 
      + "\n";
      gs_500 = gs_500 + " " 
      + "\n";
      gs_500 = gs_500 + "Last inquiry about the warrant worked" + DoubleToStr((GetTickCount() - gi_260) / 1000, 0) + " Seconds back. currency " + gs_212 
      + "\n";
      gs_500 = gs_500 + " " 
      + "\n";
      if (ruka) {
         gs_500 = gs_500 + "The manual mode is included" 
         + "\n";
      }
      if (new_kot) {
         gs_500 = gs_500 + "The new mode of quotations is included" 
         + "\n";
      }
      gs_500 = gs_500 + "Operation minimum level=" + DoubleToStr(MinUr, 1) 
      + "\n";
      gs_500 = gs_500 + "Rigid stop=" + DoubleToStr(StopLoss, 0) + "  Rigid teik profit=" + DoubleToStr(TakeProfit, 0) 
      + "\n";
      gs_620 = inits("a");
      if (gi_668) Print(gs_620);
      li_0 = StrToDouble(P_1(gs_620, -1));
      gs_500 = gs_500 + " " 
      + "\n";
      gs_500 = gs_500 + "Quantity of currencies in handling=" + li_0 
      + "\n";
      if (gi_668) Print(li_0);
      gd_420 = 0;
      gs_628 = "";
      gs_644 = "";
      gs_652 = "";
      for (int l_count_4 = 0; l_count_4 < li_0; l_count_4++) {
         if (gi_668) Print(gd_420);
         rash(l_count_4);
         if (gi_328 == 0 && g_point_276 == 0.0) continue;
         proverki();
         TakeProfit = ld_56;
         StopLoss = ld_64;
         if (trade && gd_444 > 0.0) {
            g_count_360 = 0;
            if (OrdersTotal() > 0) {
               for (g_pos_356 = 0; g_pos_356 < OrdersTotal(); g_pos_356++) {
                  OrderSelect(g_pos_356, SELECT_BY_POS, MODE_TRADES);
                  if (OrderSymbol() == g_symbol_636 && OrderMagicNumber() == g_magic_324) g_count_360++;
               }
            }
            if (g_count_360 < NTrades && MathAbs(gd_420) >= gd_308 + gd_316 && GetTickCount() - gi_260 >= 5000) {
               gi_260 = GetTickCount();
               gs_212 = g_symbol_636;
               l_price_24 = 0;
               l_price_32 = 0;
               getsizelot();
               if (gd_420 >= gd_308) {
                  if (whc != TRUE && TakeProfit > 0) l_price_24 = g_ask_572 + TakeProfit * g_point_276;
                  if (whc != TRUE && StopLoss > 0) l_price_32 = gd_564 - StopLoss * g_point_276;
                  if (ruka) {
                     okno();
                     g_ticket_352 = 1;
                  } else {
                     if (!(AccountFreeMarginCheck(g_symbol_636, OP_BUY, Lots) <= 0.0 || GetLastError() == 134/* NOT_ENOUGH_MONEY */)) g_ticket_352 = OrderSend(g_symbol_636, OP_BUY, Lots, g_ask_572 - luft * g_point_276, Slippage, l_price_32, l_price_24, 0, g_magic_324, 0, MediumBlue);
                     Print(g_symbol_636 + " buy at the price=" + g_ask_572 + " price Saxo bank=" + gd_412 + " i=" + gd_420 + " lot=" + NormalizeDouble(Lots, 2) + " spread Saxo bank=" +
                        NormalizeDouble(gd_224, 1) + " спред мт=" + NormalizeDouble(gd_316, 2) + " стоп=" + l_price_32 + " тейком=" + l_price_24);
                  }
                  if (g_ticket_352 > 0) {
                     if (OrderSelect(g_ticket_352, SELECT_BY_TICKET, MODE_TRADES)) Print("BUY order opened : ", ErrorDescription(OrderOpenPrice()));
                     PlaySound(gs_268);
                  } else Print("Error opening BUY order : ", ErrorDescription(GetLastError()));
               }
               if (gd_420 <= -gd_308) {
                  if (whc != TRUE && TakeProfit > 0) l_price_24 = gd_564 - TakeProfit * g_point_276;
                  if (whc != TRUE && StopLoss > 0) l_price_32 = g_ask_572 + StopLoss * g_point_276;
                  if (ruka) {
                     okno();
                     g_ticket_352 = 1;
                  } else {
                     if (!(AccountFreeMarginCheck(g_symbol_636, OP_SELL, Lots) <= 0.0 || GetLastError() == 134/* NOT_ENOUGH_MONEY */)) g_ticket_352 = OrderSend(g_symbol_636, OP_SELL, Lots, gd_564 + luft * g_point_276, Slippage, l_price_32, l_price_24, 0, g_magic_324, 0, Red);
                     Print(g_symbol_636 + " sell at the price=" + gd_564 + " price Saxo bank=" + gd_412 + " i=" + gd_420 + " лотом=" + NormalizeDouble(Lots, 2) + " spread Saxo bank=" +
                        NormalizeDouble(gd_224, 1) + " спред мт=" + NormalizeDouble(gd_316, 2) + " стоп=" + l_price_32 + " тейком=" + l_price_24);
                  }
                  if (g_ticket_352 > 0) {
                     if (OrderSelect(g_ticket_352, SELECT_BY_TICKET, MODE_TRADES)) Print("SELL order opened : ", OrderOpenPrice());
                     PlaySound(gs_268);
                  } else Print("Error opening SELL order : ", ErrorDescription(GetLastError()));
               }
               if (whc == TRUE && TakeProfit > 0) {
                  tppModifyBuy();
                  tppModifySell();
               }
               if (whc == TRUE && StopLoss > 0) {
                  slModifyBuy();
                  slModifySell();
               }
            }
         }
         if (gi_668) Print(MathAbs(gd_420), " ", (g_ask_572 - gd_564) / g_point_276);
         if (FixTP != 0.0)
            if (MathAbs(gd_420) <= (g_ask_572 - gd_564) / g_point_276) TrailingTPs();
         if (FixSL != 0.0)
            if (MathAbs(gd_420) < gd_316) TrailingSLs();
         gi_332++;
         if (visual && Symbol() == g_symbol_636) {
            g_fontsize_300 = 14;
            g_fontsize_304 = 8;
            g_color_264 = Red;
            if (MathAbs(gd_420) >= gd_308 + gd_316) {
               g_fontsize_300 = 26;
               g_fontsize_304 = 16;
               g_color_264 = Lime;
            }
            OBJ2();
         }
      }
      gs_500 = gs_500 + "The list of currencies " + gs_628 
      + "\n";
      gs_500 = gs_500 + gs_644;
      gs_500 = gs_500 + " " 
      + "\n";
      gs_500 = gs_500 + gs_652;
      gs_500 = gs_500 + " " 
      + "\n";
      if (trade) gs_556 = "Trade is permitted";
      else gs_556 = "Trade is prohibited";
      gs_500 = gs_500 + "program teik=" + DoubleToStr(gd_516, 1) 
      + "\n";
      gs_500 = gs_500 + "program stop=" + DoubleToStr(FixSL, 1) 
      + "\n";
      gs_500 = gs_500 + "Deposit percent=" + DoubleToStr(LotsPercent, 1) 
      + "\n";
      gs_500 = gs_500 + "Working lot=" + DoubleToStr(Lots, 2) 
      + "\n";
      gs_500 = gs_500 
         + "\n" 
         + gs_556 
      + "\n";
      if (sound) {
         gs_500 = gs_500 + "The sound alarm system is included" 
         + "\n";
      }
      Comment(gs_500);
      gs_500 = "";
      Sleep(100);
   }
   return (0);
}

string P_1(string as_0, int ai_8) {
   string ls_ret_16;
   if (ai_8 == -1) ls_ret_16 = StringSubstr(as_0, 0, 2);
   else ls_ret_16 = StringSubstr(as_0, 7 * ai_8 + 3, 6);
   return (ls_ret_16);
}

double P_2(string as_0, int ai_8) {
   double l_str2dbl_20;
   int li_16 = StringFind(as_0, "!", 0);
   if (ai_8 == 0) l_str2dbl_20 = StrToDouble(StringSubstr(as_0, 0, li_16));
   else l_str2dbl_20 = StrToDouble(StringSubstr(as_0, li_16 + 1, 7));
   return (l_str2dbl_20);
}

int getsizelot() {
   double ld_0;
   double ld_8;
   double ld_16;
   int li_24;
   if (LotsPercent > 0) {
      ld_0 = NormalizeDouble(NormalizeDouble(AccountEquity() / g_marginrequired_580, 2) * LotsPercent / 100.0, 2);
      ld_8 = ld_0;
      li_24 = ld_8 / g_lotstep_588;
      ld_16 = li_24 * g_lotstep_588;
      gd_340 = ld_16;
      if (gd_340 < g_minlot_596) gd_340 = g_minlot_596;
      if (gd_340 > g_maxlot_604) gd_340 = g_maxlot_604;
      Lots = gd_340;
   }
   if (Lots > max_lots) Lots = max_lots;
   return (0);
}

int tppModifyBuy() {
   double l_price_4;
   if (OrdersTotal() > 0) {
      for (int l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++) {
         OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES);
         if (OrderType() == OP_BUY) {
            if (OrderMagicNumber() == g_magic_324) {
               l_price_4 = NormalizeDouble(OrderOpenPrice(), gi_328) + TakeProfit * g_point_276;
               if (NormalizeDouble(OrderTakeProfit(), gi_328) != l_price_4) OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), l_price_4, 0, Red);
            }
         }
      }
   }
   return (0);
}

int tppModifySell() {
   double l_price_4;
   if (OrdersTotal() > 0) {
      for (int l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++) {
         OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES);
         if (OrderType() == OP_SELL) {
            if (OrderMagicNumber() == g_magic_324) {
               l_price_4 = NormalizeDouble(OrderOpenPrice(), gi_328) - TakeProfit * g_point_276;
               if (NormalizeDouble(OrderTakeProfit(), gi_328) != l_price_4) OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), l_price_4, 0, Red);
            }
         }
      }
   }
   return (0);
}

int slModifyBuy() {
   double l_price_4;
   if (OrdersTotal() > 0) {
      for (int l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++) {
         OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES);
         if (OrderType() == OP_BUY) {
            if (OrderMagicNumber() == g_magic_324) {
               l_price_4 = NormalizeDouble(OrderOpenPrice(), gi_328) - StopLoss * g_point_276;
               if (NormalizeDouble(OrderStopLoss(), gi_328) != l_price_4) OrderModify(OrderTicket(), OrderOpenPrice(), l_price_4, OrderTakeProfit(), 0, Red);
            }
         }
      }
   }
   return (0);
}

int slModifySell() {
   double l_price_4;
   if (OrdersTotal() > 0) {
      for (int l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++) {
         OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES);
         if (OrderType() == OP_SELL) {
            if (OrderMagicNumber() == g_magic_324) {
               l_price_4 = NormalizeDouble(OrderOpenPrice(), gi_328) + StopLoss * g_point_276;
               if (NormalizeDouble(OrderStopLoss(), gi_328) != l_price_4) OrderModify(OrderTicket(), OrderOpenPrice(), l_price_4, OrderTakeProfit(), 0, Red);
            }
         }
      }
   }
   return (0);
}

void TrailingTPs() {
   for (int l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++) {
      if (OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol() == g_symbol_636 && OrderMagicNumber() == g_magic_324) {
            if (OrderType() == OP_BUY) {
               gd_452 = MarketInfo(OrderSymbol(), MODE_BID) - OrderOpenPrice();
               gd_468 = gd_516 * g_point_276;
               gd_468 = NormalizeDouble(gd_468, gi_328);
               if (gd_452 >= gd_468) {
                  OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID) + luft * g_point_276, Slippage);
                  return;
               }
            }
            if (OrderType() == OP_SELL) {
               gd_460 = OrderOpenPrice() - MarketInfo(OrderSymbol(), MODE_ASK);
               gd_468 = gd_516 * g_point_276;
               gd_468 = NormalizeDouble(gd_468, gi_328);
               if (gd_460 >= gd_468) {
                  OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK) - luft * g_point_276, Slippage);
                  return;
               }
            }
         }
      }
   }
}

void TrailingSLs() {
   for (int l_pos_16 = 0; l_pos_16 < OrdersTotal(); l_pos_16++) {
      if (OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol() == g_symbol_636 && OrderMagicNumber() == g_magic_324) {
            if (OrderType() == OP_BUY) {
               gd_452 = OrderOpenPrice() - MarketInfo(OrderSymbol(), MODE_BID);
               gd_452 = NormalizeDouble(gd_452, gi_328);
               gd_468 = FixSL * g_point_276;
               gd_468 = NormalizeDouble(gd_468, gi_328);
               if (gd_452 >= gd_468) {
                  OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID) + luft * g_point_276, Slippage);
                  return;
               }
            }
            if (OrderType() == OP_SELL) {
               gd_460 = MarketInfo(OrderSymbol(), MODE_ASK) - OrderOpenPrice();
               gd_460 = NormalizeDouble(gd_460, gi_328);
               gd_468 = FixSL * g_point_276;
               gd_468 = NormalizeDouble(gd_468, gi_328);
               if (gd_460 >= gd_468) {
                  OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK) - luft * g_point_276, Slippage);
                  return;
               }
            }
         }
      }
   }
}

int deinit() {
   ObjectDelete("BidMT");
   ObjectDelete("BidGL");
   ObjectDelete("RMTGL");
   ObjectDelete("RMTGLsig");
   ObjectDelete("bid_saxo");
   ObjectDelete("bid_mt");
   ObjectDelete("bid label");
   ObjectDelete("ask label");
   ObjectDelete("ask_saxo");
   Comment("");
   return (0);
}

int rash(int ai_0) {
   g_symbol_636 = P_1(gs_620, ai_0);
   string ls_4 = g_symbol_636;
   if (gi_668) Print("symb " + g_symbol_636);
   int li_12 = StringFind(Symbol(), g_symbol_636, 0);
   if (li_12 != 1) {
      if (li_12 > 0) gs_612 = StringSubstr(Symbol(), 0, li_12 - 1);
      if (li_12 == 0) {
         li_12 += 6;
         if (li_12 >= 6) gs_612 = StringSubstr(Symbol(), li_12, StringLen(Symbol()) - 1);
      }
   }
   g_symbol_636 = g_symbol_636 + gs_612;
   RefreshRates();
   gd_564 = MarketInfo(g_symbol_636, MODE_BID);
   g_ask_572 = MarketInfo(g_symbol_636, MODE_ASK);
   gs_628 = gs_628 + g_symbol_636 + " ";
   gi_328 = MarketInfo(g_symbol_636, MODE_DIGITS);
   if (gi_328 == 3) {
      gi_328 = 2;
      Slippage = 10.0 * Slippage;
   }
   if (gi_328 == 5) {
      gi_328 = 4;
      Slippage = 10.0 * Slippage;
   }
   if (gi_668) Print("symb " + g_symbol_636 + " dig=" + gi_328);
   g_point_276 = MarketInfo(g_symbol_636, MODE_POINT);
   if (g_point_276 == 0.001) g_point_276 = 0.01;
   if (g_point_276 == 0.00001) g_point_276 = 0.0001;
   if (gi_668) Print("symb " + g_symbol_636 + " pp=" + g_point_276);
   if (ruka && g_symbol_636 != Symbol()) {
      gi_328 = 0;
      g_point_276 = 0;
      gs_644 = gs_644 + g_symbol_636 + " not present" 
      + "\n";
      return (0);
   }
   if (gi_328 == 0 && g_point_276 == 0.0) {
      gs_644 = gs_644 + g_symbol_636 + " not present" 
      + "\n";
      return (0);
   }
   string ls_16 = val_bid_ask(ls_4);
   gs_380 = P_2(ls_16, 0);
   if (gi_668) Print("symb Valuta " + gs_380);
   gd_412 = StrToDouble(gs_380) + sdvig_bid * g_point_276;
   gd_412 = NormalizeDouble(gd_412, MarketInfo(g_symbol_636, MODE_DIGITS));
   gd_444 = gd_412;
   gs_396 = P_2(ls_16, 1);
   gd_436 = StrToDouble(gs_396) + sdvig_bid * g_point_276;
   gd_436 = NormalizeDouble(gd_436, MarketInfo(g_symbol_636, MODE_DIGITS));
   GlobalVariableSet(g_symbol_636 + "_bid", gd_412);
   GlobalVariableSet(g_symbol_636 + "_ask", gd_436);
   if (!new_kot) {
      gd_316 = (NormalizeDouble(g_ask_572, MarketInfo(g_symbol_636, MODE_DIGITS)) - NormalizeDouble(gd_564, MarketInfo(g_symbol_636, MODE_DIGITS))) / g_point_276;
      if (Fixspred > 0) gd_316 = Fixspred;
      gd_420 = (gd_412 - NormalizeDouble(gd_564, MarketInfo(g_symbol_636, MODE_DIGITS))) / g_point_276;
      gd_224 = (gd_436 - gd_412) / g_point_276;
   }
   if (new_kot) {
      gd_316 = 0;
      gd_224 = 0;
      gd_244 = gd_412 + (gd_436 - gd_412) / 2.0;
      gd_236 = Bid + (Ask - Bid) / 2.0;
      gd_252 = (gd_244 - gd_236) / g_point_276;
      gd_420 = gd_252;
      gd_564 = gd_236;
      gd_412 = gd_244;
      gd_436 = gd_236;
   }
   proverka_sv();
   if (MathAbs(gd_420) >= gi_232) gd_420 = 0;
   if (gi_668) Print("symb spred_mt " + g_symbol_636 + " " + gd_316);
   return (0);
}

int proverki() {
   gd_308 = MinUr;
   if (spred_saxo) {
      if (gd_224 > 4.0) {
         if (gd_224 > gd_316) gd_308 = MinUr + (gd_224 - gd_316) / 2.0;
         if (2.0 * MathAbs(gd_316) < MathAbs(gd_224)) gd_308 = MinUr + (gd_224 - gd_316);
      }
   }
   gd_516 = FixTP;
   if (gd_316 < MathAbs(gd_420)) gd_516 = TakeProfit;
   if (gd_308 < MinUr) gd_308 = MinUr;
   if (MathAbs(gd_420) >= gd_308 + gd_316) {
      if (gd_420 >= gd_308) gs_388 = "BUY " + DoubleToStr(g_ask_572, gi_328);
      else gs_388 = "SELL " + DoubleToStr(gd_564, gi_328);
      if (gi_668) Print("i=", gd_420, " MinUr=", MinUr, " MinUrt=", gd_308, "  Global=", gd_412, "  Bid=", NormalizeDouble(gd_564, gi_328), "  Ask=", NormalizeDouble(g_ask_572, gi_328), "  ", gs_388, "  спред саксы=", gd_224, "  спред мт=", gd_316);
      if (sound == TRUE && gd_508 != iBars(g_symbol_636, PERIOD_M1)) gd_508 = iBars(g_symbol_636, PERIOD_M1);
   }
   if (!new_kot) {
      gs_644 = gs_644 + g_symbol_636 + " bid=" + DoubleToStr(gd_412, 5) + "(" + DoubleToStr(gd_420, 1) + ") " + DoubleToStr(gd_308 + gd_316, 1) + " spred=" + DoubleToStr(gd_224, 1) + "(" + DoubleToStr(gd_316, 1) + ")" 
      + "\n";
   }
   if (new_kot) {
      gs_644 = gs_644 + g_symbol_636 + " bidGL=" + DoubleToStr(gd_412, 5) + "(" + DoubleToStr(gd_420, 1) + ") " + DoubleToStr(gd_308 + gd_316, 1) + " bidMT=" + DoubleToStr(gd_564, 5) 
      + "\n";
   }
   return (0);
}

int proverka_sv() {
   double l_global_var_0 = GlobalVariableGet("proverka_bid_" + g_symbol_636);
   double l_global_var_8 = GlobalVariableGet("proverka_ask_" + g_symbol_636);
   double l_global_var_16 = GlobalVariableGet("proverka_tik_" + AccountNumber());
   if (gd_412 == l_global_var_0 && gd_436 == l_global_var_8) {
      if (GetTickCount() - l_global_var_16 > 1000 * gi_220) {
         gd_420 = 0;
         if (visual_pr_kotir) {
            gs_500 = gs_500 + g_symbol_636 + " Something with giving of quotations. Communication probably was gone in a current " + DoubleToStr((GetTickCount() - l_global_var_16) / 1000.0, 0) + " second" 
            + "\n";
         }
      }
   } else {
      GlobalVariableSet("proverka_bid_" + g_symbol_636, gd_412);
      GlobalVariableSet("proverka_ask_" + g_symbol_636, gd_436);
      GlobalVariableSet("proverka_tik_" + AccountNumber(), GetTickCount());
   }
   if (GetTickCount() - GlobalVariableGet("proverka_zapusk_") < 1000 * (gi_220 * 2)) {
      gd_420 = 0;
      gs_500 = "=========================================================================================================" 
      + "\n";
      gs_500 = gs_500 + " Before script start remains " + DoubleToStr((1000 * (gi_220 * 2) - (GetTickCount() - GlobalVariableGet("proverka_zapusk_"))) / 1000.0, 0) + " second" 
      + "\n";
      gs_500 = gs_500 + "=========================================================================================================" 
      + "\n";
   }
   return (0);
}

int init() {
   if (read_pr_nastr) {
      Print("We read options from the previous start");
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_trade") == 1.0) trade = TRUE;
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_" + "whc") == 1.0) whc = TRUE;
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_" + "sound") == 1.0) sound = TRUE;
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_" + "spred_saxo") == 1.0) spred_saxo = TRUE;
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_" + "visual") == 1.0) visual = TRUE;
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_" + "visual_bid") == 1.0) visual_bid = TRUE;
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_" + "visual_pr_kotir") == 1.0) visual_pr_kotir = TRUE;
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_" + "new_kot") == 1.0) new_kot = TRUE;
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_trade") == 2.0) trade = FALSE;
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_" + "whc") == 2.0) whc = FALSE;
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_" + "sound") == 2.0) sound = FALSE;
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_" + "spred_saxo") == 2.0) spred_saxo = FALSE;
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_" + "visual") == 2.0) visual = FALSE;
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_" + "visual_bid") == 2.0) visual_bid = FALSE;
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_" + "visual_pr_kotir") == 2.0) visual_pr_kotir = FALSE;
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_" + "new_kot") == 2.0) new_kot = FALSE;
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_MinUr") != 0.0) MinUr = GlobalVariableGet("nastr_" + AccountNumber() + "_MinUr");
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_Lots") != 0.0) Lots = GlobalVariableGet("nastr_" + AccountNumber() + "_Lots");
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_LotsPercent") != 0.0) LotsPercent = GlobalVariableGet("nastr_" + AccountNumber() + "_LotsPercent");
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_max_lots") != 0.0) max_lots = GlobalVariableGet("nastr_" + AccountNumber() + "_max_lots");
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_TakeProfit") != 0.0) TakeProfit = GlobalVariableGet("nastr_" + AccountNumber() + "_TakeProfit");
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_" + "StopLoss") != 0.0) StopLoss = GlobalVariableGet("nastr_" + AccountNumber() + "_" + "StopLoss");
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_" + "FixTP") != 0.0) FixTP = GlobalVariableGet("nastr_" + AccountNumber() + "_" + "FixTP");
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_" + "FixSL") != 0.0) FixSL = GlobalVariableGet("nastr_" + AccountNumber() + "_" + "FixSL");
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_" + "sdvig_bid") != 0.0) sdvig_bid = GlobalVariableGet("nastr_" + AccountNumber() + "_" + "sdvig_bid");
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_" + "Fixspred") != 0.0) Fixspred = GlobalVariableGet("nastr_" + AccountNumber() + "_" + "Fixspred");
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_" + "NTrades") != 0.0) NTrades = GlobalVariableGet("nastr_" + AccountNumber() + "_" + "NTrades");
      if (GlobalVariableGet("nastr_" + AccountNumber() + "_" + "Slippage") != 0.0) Slippage = GlobalVariableGet("nastr_" + AccountNumber() + "_" + "Slippage");
   }
   Print("We write down the data on the future");
   if (trade) GlobalVariableSet("nastr_" + AccountNumber() + "_trade", 1);
   else GlobalVariableSet("nastr_" + AccountNumber() + "_trade", 2);
   if (whc) GlobalVariableSet("nastr_" + AccountNumber() + "_" + "whc", 1);
   else GlobalVariableSet("nastr_" + AccountNumber() + "_" + "whc", 2);
   if (sound) GlobalVariableSet("nastr_" + AccountNumber() + "_" + "sound", 1);
   else GlobalVariableSet("nastr_" + AccountNumber() + "_" + "sound", 2);
   if (spred_saxo) GlobalVariableSet("nastr_" + AccountNumber() + "_" + "spred_saxo", 1);
   else GlobalVariableSet("nastr_" + AccountNumber() + "_" + "spred_saxo", 2);
   if (visual) GlobalVariableSet("nastr_" + AccountNumber() + "_" + "visual", 1);
   else GlobalVariableSet("nastr_" + AccountNumber() + "_" + "visual", 2);
   if (visual_bid) GlobalVariableSet("nastr_" + AccountNumber() + "_" + "visual_bid", 1);
   else GlobalVariableSet("nastr_" + AccountNumber() + "_" + "visual_bid", 2);
   if (visual_pr_kotir) GlobalVariableSet("nastr_" + AccountNumber() + "_" + "visual_pr_kotir", 1);
   else GlobalVariableSet("nastr_" + AccountNumber() + "_" + "visual_pr_kotir", 2);
   if (new_kot) GlobalVariableSet("nastr_" + AccountNumber() + "_" + "new_kot", 1);
   else GlobalVariableSet("nastr_" + AccountNumber() + "_" + "new_kot", 2);
   GlobalVariableSet("nastr_" + AccountNumber() + "_MinUr", MinUr);
   GlobalVariableSet("nastr_" + AccountNumber() + "_Lots", Lots);
   GlobalVariableSet("nastr_" + AccountNumber() + "_LotsPercent", LotsPercent);
   GlobalVariableSet("nastr_" + AccountNumber() + "_max_lots", max_lots);
   GlobalVariableSet("nastr_" + AccountNumber() + "_TakeProfit", TakeProfit);
   GlobalVariableSet("nastr_" + AccountNumber() + "_" + "StopLoss", StopLoss);
   GlobalVariableSet("nastr_" + AccountNumber() + "_" + "FixTP", FixTP);
   GlobalVariableSet("nastr_" + AccountNumber() + "_" + "FixSL", FixSL);
   GlobalVariableSet("nastr_" + AccountNumber() + "_" + "sdvig_bid", sdvig_bid);
   GlobalVariableSet("nastr_" + AccountNumber() + "_" + "Fixspred", Fixspred);
   GlobalVariableSet("nastr_" + AccountNumber() + "_" + "NTrades", NTrades);
   GlobalVariableSet("nastr_" + AccountNumber() + "_" + "Slippage", Slippage);
   gs_500 = "";
   GlobalVariableSet("proverka_zapusk_", GetTickCount());
   gi_260 = GetTickCount();
   double l_price_0 = NormalizeDouble(Bid, 2) - 0.02;
   if (mt_setka_vykl) {
      gi_524 = WindowHandle(Symbol(), Period());
      PostMessageA(gi_524, WM_COMMAND, 33021, 0);
   }
   if (setka) {
      for (int l_count_8 = 0; l_count_8 < 20; l_count_8++) {
         ObjectCreate("asd_" + l_price_0 + "_b", OBJ_HLINE, 0, TimeCurrent(), l_price_0);
         ObjectSet("asd_" + l_price_0 + "_b", OBJPROP_COLOR, LightSlateGray);
         ObjectSet("asd_" + l_price_0 + "_b", OBJPROP_STYLE, STYLE_DOT);
         ObjectSet("asd_" + l_price_0 + "_b", OBJPROP_WIDTH, 1);
         l_price_0 += 0.002;
      }
   }
   gs_212 = "none";
   return (0);
}

int okno() {
   int li_4;
   int li_8;
   int li_12;
   int li_unused_16;
   int li_20;
   int li_24;
   int li_28;
   int li_0 = 3000;
   gi_540 = FindWindowA("#32770", "Ордер");
   if (gi_540 != 0) {
      gi_548 = GetWindow(gi_540, 5);
      gi_548 = GetWindow(gi_548, 2);
      gi_548 = GetWindow(gi_548, 2);
      gi_548 = GetWindow(gi_548, 2);
      gi_548 = GetWindow(gi_548, 2);
      gi_548 = GetWindow(gi_548, 2);
      gi_548 = GetWindow(gi_548, 2);
      gi_548 = GetWindow(gi_548, 2);
      gi_548 = GetWindow(gi_548, 2);
      gi_548 = GetWindow(gi_548, 2);
      gi_548 = GetWindow(gi_548, 2);
      gi_548 = GetWindow(gi_548, 2);
      gi_548 = GetWindow(gi_548, 2);
      gi_548 = GetWindow(gi_548, 2);
      gi_548 = GetWindow(gi_548, 2);
      gi_548 = GetWindow(gi_548, 2);
      gi_548 = GetWindow(gi_548, 2);
      gi_548 = GetWindow(gi_548, 5);
      gi_536 = gi_548;
      gi_548 = GetWindow(gi_548, 2);
      gi_532 = gi_548;
      gi_540 = GetDlgItem(gi_540, 1384);
      gi_540 = GetDlgItem(gi_540, 1001);
      SetWindowTextA(gi_540, DoubleToStr(Lots, Dig));
      if (gd_252 > 0.0) SendMessageA(gi_532, 245, 0, 0);
      if (gd_252 < 0.0) SendMessageA(gi_536, 245, 0, 0);
   } else {
      gi_524 = WindowHandle(Symbol(), Period());
      li_8 = GetAncestor(gi_524, 2);
      PostMessageA(gi_524, WM_COMMAND, 35458, 0);
      gi_540 = 0;
      li_4 = GetTickCount();
      while (gi_540 == 0) {
         gi_540 = FindWindowA("#32770", "Ордер");
         if (GetTickCount() - li_4 > li_0) return (0);
      }
      li_12 = GetWindow(gi_540, 5);
      li_12 = GetWindow(li_12, 2);
      li_12 = GetWindow(li_12, 2);
      li_12 = GetWindow(li_12, 2);
      li_12 = GetWindow(li_12, 2);
      li_12 = GetWindow(li_12, 2);
      li_12 = GetWindow(li_12, 2);
      li_12 = GetWindow(li_12, 2);
      li_12 = GetWindow(li_12, 2);
      li_12 = GetWindow(li_12, 2);
      li_12 = GetWindow(li_12, 2);
      li_12 = GetWindow(li_12, 2);
      li_12 = GetWindow(li_12, 2);
      li_12 = GetWindow(li_12, 2);
      li_12 = GetWindow(li_12, 2);
      li_12 = GetWindow(li_12, 2);
      li_unused_16 = 0;
      li_20 = li_12;
      li_12 = 0;
      while (li_12 == 0) {
         li_12 = GetWindow(li_20, 2);
         li_12 = GetWindow(li_12, 5);
         if (GetTickCount() - li_4 > li_0) return (0);
      }
      li_24 = li_12;
      li_20 = li_12;
      li_12 = 0;
      while (li_12 == 0) {
         li_12 = GetWindow(li_20, 2);
         if (GetTickCount() - li_4 > li_0) return (0);
      }
      li_28 = li_12;
      SendMessageA(li_28, 245, 0, 0);
      gi_540 = GetDlgItem(gi_540, 1384);
      gi_540 = GetDlgItem(gi_540, 1001);
      SetWindowTextA(gi_540, DoubleToStr(0.1, 1));
      if (gd_252 > 0.0) SendMessageA(li_28, 245, 0, 0);
      if (gd_252 < 0.0) SendMessageA(li_24, 245, 0, 0);
   }
   return (0);
}

int OBJ2() {
   string ls_unused_16;
   if (ObjectFind("bid_saxo") == -1) {
      ObjectCreate("bid_saxo", OBJ_HLINE, 0, TimeCurrent(), gd_412);
      ObjectSet("bid_saxo", OBJPROP_COLOR, Yellow);
      ObjectSet("bid_saxo", OBJPROP_STYLE, STYLE_SOLID);
   }
   ObjectMove("bid_saxo", 0, TimeCurrent(), gd_412);
   if (visual_bid)
      if (ObjectFind("bid label") == -1) ObjectCreate("bid label", OBJ_TEXT, 0, Time[0], Low[0] - 10.0 * g_point_276);
   if (gd_420 >= 0.0) ObjectSetText("bid label", DoubleToStr(gd_420, 1), g_fontsize_304, "Arial", Lime);
   else ObjectSetText("bid label", DoubleToStr(gd_420, 1), g_fontsize_304, "Arial", Red);
   ObjectMove("bid label", 0, Time[0], Low[0] - 10.0 * g_point_276);
   if (ObjectFind("ask label") == -1) ObjectCreate("ask label", OBJ_TEXT, 0, Time[0], High[0] + 10.0 * g_point_276);
   ObjectSetText("ask label", DoubleToStr((Ask - Bid) / g_point_276, 1), 8, "Arial", Red);
   ObjectMove("ask label", 0, Time[0], High[0] + 10.0 * g_point_276);
   if (ObjectFind("RMTGL") == -1) {
      ObjectCreate("RMTGL", OBJ_LABEL, 0, 0, 0);
      ObjectSet("RMTGL", OBJPROP_CORNER, 1);
      ObjectSet("RMTGL", OBJPROP_XDISTANCE, 15);
      ObjectSet("RMTGL", OBJPROP_YDISTANCE, 0);
   }
   ObjectSetText("RMTGL", DoubleToStr(gd_420, 1), g_fontsize_300, "Arial Black", g_color_264);
   if (ObjectFind("ask_saxo") == -1) {
      ObjectCreate("ask_saxo", OBJ_HLINE, 0, TimeCurrent(), gd_436);
      ObjectSet("ask_saxo", OBJPROP_COLOR, Red);
      ObjectSet("ask_saxo", OBJPROP_STYLE, STYLE_SOLID);
   }
   ObjectMove("ask_saxo", 0, TimeCurrent(), gd_436);
   ObjectsRedraw();
   return (0);
}

int mr() {
   g_marginrequired_580 = MarketInfo(Symbol(), MODE_MARGINREQUIRED);
   g_lotstep_588 = MarketInfo(Symbol(), MODE_LOTSTEP);
   g_minlot_596 = MarketInfo(Symbol(), MODE_MINLOT);
   g_maxlot_604 = MarketInfo(Symbol(), MODE_MAXLOT);
   if (g_marginrequired_580 == 0.0) {
      g_marginrequired_580 = 1000;
      Print("MODE_MARGINREQUIRED error");
   }
   if (g_lotstep_588 == 0.0) {
      g_lotstep_588 = 0.1;
      Print("MODE_LOTSTEP error");
   }
   if (g_minlot_596 == 0.0) {
      g_minlot_596 = 0.1;
      Print("MODE_MINLOT error");
   }
   if (g_maxlot_604 == 0.0) {
      g_maxlot_604 = 1000;
      Print("MODE_MAXLOT error");
   }
   return (0);
}