#property copyright "Yuriy Tokman (YTG)"
#property link      "http://ytg.com.ua"

//#include <stdlib.mqh>
#import "stdlib.ex4"
   string ErrorDescription(int a0); // DA69CBAFF4D38B87377667EEC549DE5A
#import "chmd.dll"
   void SetApplicationPath(string a0);
   bool a1(double a0, double a1, double a2, double a3);
   bool a2(double a0, double a1, double a2, double a3, double a4);
   double a3(double a0, double a1, double a2, double a3, double a4, double a5, double a6, double a7);
   bool a4(int a0);
   bool a5(int a0, int a1, double a2, double a3, int a4, double a5, bool a6);
   bool a6(int a0, double a1, double a2, int a3, int a4, double a5);
#import

extern int period = 55;
extern double FilterNumber = 2.0;
extern int ma_method = 3;
extern int applied_price = 0;
extern int shift = 1;
extern int TF = 0;
extern string PAIRS = "EURUSD,GBPUSD,USDCHF,USDJPY";
extern int MagicNumber = 6;
extern double TrailingStart = 9.5;
extern double TrailingStop = 0.5;
extern double TrailingStep = 0.5;
extern double LossClose = 2500000.0;
extern double Lots = 0.0;
extern double Risk = 0.3;
extern int PIP_LOCK = 13;
extern double koef_LOT_LOCK = 2.0;
extern int PIP_AV = 13;
extern int Level_Order = 13;
extern double koef_LOT_AV = 2.0;
extern bool Revers = FALSE;
double Gd_196 = -999999999.0;
double Gd_204 = 0.0;
double Gd_212 = 0.0;
int Gi_220 = 0;
string Gsa_224[];
double Gda_228[];
double Gda_232[4];
double Gd_236;
extern int Slippage = 30;
extern bool MarketWatch = FALSE;
extern bool ALERT = TRUE;
bool Gi_unused_256 = FALSE;

// 7439F21E440F650B67FCE3BC9F3C24F5
double f0_10(string As_0) {
   int Li_8 = StringFind(As_0, "JPY");
   if (Li_8 == -1) return (0.0001);
   return (0.01);
}
	 			 	  	 	 			 	  	  			 			 		 			 		  	 	 			        				   	 	  	   	  				 	   	  		 	 		 			  	 	   		  	  	 					 	 		    			   	 	   	  
// 9FDEBEDD6557A3BB9931DD4354992A42
void f0_13(string Asymbol0, int Acmd8, double A_lots_12, double A_price_20, double A_price_28 = 0.0, double A_price_36 = 0.0, int Amagic44 = 0, string A_comment_48 = "", int A_datetime_56 = 0) {
   color color_60;
   int datetime_64;
   double ask_68;
   double bid_76;
   double point_84;
   int error_92;
   int ticket_100;
   string comment_108 = A_comment_48;
   if (Asymbol0 == "" || Asymbol0 == "0") Asymbol0 = Symbol();
   int stoplevel_104 = MarketInfo(Asymbol0, MODE_STOPLEVEL);
   if (Acmd8 == OP_BUYLIMIT || Acmd8 == OP_BUYSTOP) color_60 = Lime;
   else color_60 = Red;
   if (A_datetime_56 > 0 && A_datetime_56 < TimeCurrent()) A_datetime_56 = 0;
   for (int Li_96 = 1; Li_96 <= 5; Li_96++) {
      if (!IsTesting() && (!IsExpertEnabled()) || IsStopped()) {
         Print("SetOrder(): Остановка работы функции");
         return;
      }
      while (!IsTradeAllowed()) Sleep(5000);
      RefreshRates();
      datetime_64 = TimeCurrent();
      ticket_100 = OrderSend(Asymbol0, Acmd8, A_lots_12, A_price_20, 30, A_price_28, A_price_36, comment_108, Amagic44, A_datetime_56, color_60);
      if (ticket_100 > 0) {
         PlaySound("expert.wav");
         return;
      }
      PlaySound("wait.wav");
      error_92 = GetLastError();
      if (error_92 == 128/* TRADE_TIMEOUT */ || error_92 == 142 || error_92 == 143) {
         Sleep(66000);
         if (f0_1(Asymbol0, Acmd8, Amagic44, datetime_64)==1) {
            PlaySound("expert.wav");
            return;
         }
         Print("Error(", error_92, ") set order: ", ErrorDescription(error_92), ", try ", Li_96);
      } else {
         point_84 = MarketInfo(Asymbol0, MODE_POINT);
         ask_68 = MarketInfo(Asymbol0, MODE_ASK);
         bid_76 = MarketInfo(Asymbol0, MODE_BID);
         if (error_92 == 130/* INVALID_STOPS */) {
            switch (Acmd8) {
            case OP_BUYLIMIT:
               if (A_price_20 > ask_68 - stoplevel_104 * point_84) A_price_20 = ask_68 - stoplevel_104 * point_84;
               if (A_price_28 > A_price_20 - (stoplevel_104 + 1) * point_84) A_price_28 = A_price_20 - (stoplevel_104 + 1) * point_84;
               if (!(A_price_36 > 0.0 && A_price_36 < A_price_20 + (stoplevel_104 + 1) * point_84)) break;
               A_price_36 = A_price_20 + (stoplevel_104 + 1) * point_84;
               break;
            case OP_BUYSTOP:
               if (A_price_20 < ask_68 + (stoplevel_104 + 1) * point_84) A_price_20 = ask_68 + (stoplevel_104 + 1) * point_84;
               if (A_price_28 > A_price_20 - (stoplevel_104 + 1) * point_84) A_price_28 = A_price_20 - (stoplevel_104 + 1) * point_84;
               if (!(A_price_36 > 0.0 && A_price_36 < A_price_20 + (stoplevel_104 + 1) * point_84)) break;
               A_price_36 = A_price_20 + (stoplevel_104 + 1) * point_84;
               break;
            case OP_SELLLIMIT:
               if (A_price_20 < bid_76 + stoplevel_104 * point_84) A_price_20 = bid_76 + stoplevel_104 * point_84;
               if (A_price_28 > 0.0 && A_price_28 < A_price_20 + (stoplevel_104 + 1) * point_84) A_price_28 = A_price_20 + (stoplevel_104 + 1) * point_84;
               if (A_price_36 <= A_price_20 - (stoplevel_104 + 1) * point_84) break;
               A_price_36 = A_price_20 - (stoplevel_104 + 1) * point_84;
               break;
            case OP_SELLSTOP:
               if (A_price_20 > bid_76 - stoplevel_104 * point_84) A_price_20 = bid_76 - stoplevel_104 * point_84;
               if (A_price_28 > 0.0 && A_price_28 < A_price_20 + (stoplevel_104 + 1) * point_84) A_price_28 = A_price_20 + (stoplevel_104 + 1) * point_84;
               if (A_price_36 <= A_price_20 - (stoplevel_104 + 1) * point_84) break;
               A_price_36 = A_price_20 - (stoplevel_104 + 1) * point_84;
            }
            Print("SetOrder(): Скорректированы ценовые уровни");
         }
         Print("Error(", error_92, ") set order: ", ErrorDescription(error_92), ", try ", Li_96);
         Print("Ask=", ask_68, "  Bid=", bid_76, "  sy=", Asymbol0, "  ll=", A_lots_12, "  op=", f0_16(Acmd8), "  pp=", A_price_20, "  sl=", A_price_28, "  tp=", A_price_36,
            "  mn=", Amagic44);
         if (ask_68 == 0.0 && bid_76 == 0.0) f0_6("SetOrder(): Проверьте в обзоре рынка наличие символа " + Asymbol0);
         if (error_92 == 2/* COMMON_ERROR */ || error_92 == 64/* ACCOUNT_DISABLED */ || error_92 == 65/* INVALID_ACCOUNT */ || error_92 == 133/* TRADE_DISABLED */) {
            Gi_unused_256 = TRUE;
            return;
         }
         if (error_92 == 4/* SERVER_BUSY */ || error_92 == 131/* INVALID_TRADE_VOLUME */ || error_92 == 132/* MARKET_CLOSED */) {
            Sleep(300000);
            return;
         }
         if (error_92 == 8/* TOO_FREQUENT_REQUESTS */ || error_92 == 141/* TOO_MANY_REQUESTS */) Sleep(100000);
         if (error_92 == 139/* ORDER_LOCKED */ || error_92 == 140/* LONG_POSITIONS_ONLY_ALLOWED */ || error_92 == 148/* TRADE_TOO_MANY_ORDERS */) break;
         if (error_92 == 146/* TRADE_CONTEXT_BUSY */) while (IsTradeContextBusy()) Sleep(11000);
         if (error_92 == 147/* TRADE_EXPIRATION_DENIED */) A_datetime_56 = 0;
         else
            if (error_92 != 135/* PRICE_CHANGED */ && error_92 != 138/* REQUOTE */) Sleep(7700.0);
      }
   }
}
	 	   				  			 		 	     	   	    	   	 	 		  	    		  				    	  				 			 	 		 		 			 	 	  				 					  	       	 		 		   		 	 		 	    	  			 			
// 195F7A8C3579B807C96412E1BAFAE599
int f0_1(string As_0 = "", int Acmd8 = -1, int Amagic12 = -1, int Ai_16 = 0) {
   int cmd_28;
   int ordertotal24 = OrdersTotal();
   if (As_0 == "0") As_0 = Symbol();
   for (int pos_20 = 0; pos_20 < ordertotal24; pos_20++) {
      if (OrderSelect(pos_20, SELECT_BY_POS, MODE_TRADES)) {
         cmd_28 = OrderType();
         if (cmd_28 > OP_SELL && cmd_28 < 6) {
            if (OrderSymbol() == As_0 || As_0 == "" && Acmd8 < OP_BUY || cmd_28 == Acmd8) {
               if (Amagic12 < 0 || OrderMagicNumber() == Amagic12)
                  if (Ai_16 <= OrderOpenTime()) return (1);
            }
         }
      }
   }
   return (0);
}
		        	 		 	  		  			 	  					     	 	 	   						 	       	 		 				   		 	 	  					 	 	 		  	  					 		   		 	 	 	 			 	 		  	    	 		 		    
// 9D83CE1B6EB850A087D4F3A7322D07C9
void f0_12(string As_0 = "", int Acmd8 = -1, int Amagic12 = -1) {
   bool is_deleted_16;
   int error_20;
   int cmd_36;
   int order_total_32 = OrdersTotal();
   if (As_0 == "0") As_0 = Symbol();
   for (int pos_24 = order_total_32 - 1; pos_24 >= 0; pos_24--) {
      if (OrderSelect(pos_24, SELECT_BY_POS, MODE_TRADES)) {
         cmd_36 = OrderType();
         if (cmd_36 > OP_SELL && cmd_36 < 6) {
            if (OrderSymbol() == As_0 || As_0 == "" && Acmd8 < OP_BUY || cmd_36 == Acmd8) {
               if (Amagic12 < 0 || OrderMagicNumber() == Amagic12) {
                  for (int Li_28 = 1; Li_28 <= 5; Li_28++) {
                     if (!IsTesting() && (!IsExpertEnabled()) || IsStopped()) break;
                     while (!IsTradeAllowed()) Sleep(5000);
                     is_deleted_16 = OrderDelete(OrderTicket(), Lime);
                     if (is_deleted_16) {
                        PlaySound("ok.wav");
                        break;
                     }
                     PlaySound("wait.wav");
                     error_20 = GetLastError();
                     Print("Error(", error_20, ") delete order ", f0_16(cmd_36), ": ", ErrorDescription(error_20), ", try ", Li_28);
                     Sleep(5000);
                  }
               }
            }
         }
      }
   }
}
		 			 	  		      	 			 	 			 	 		 			   	  		  			  			   							    		  	 	     	   			 		   		     	  						  	  	   		  	 		 	 							   	 	 
// B6838164ED869516345D96B32AA351B5
string f0_16(int Ai_0) {
   switch (Ai_0) {
   case 0:
      return ("Buy");
   case 1:
      return ("Sell");
   case 2:
      return ("Buy Limit");
   case 3:
      return ("Sell Limit");
   case 4:
      return ("Buy Stop");
   case 5:
      return ("Sell Stop");
   }
   return ("Unknown Operation");
}
	 			 	 		 	 					  	  	 	 			 	  			 			 	 	 		        					     	  	  		  						   	   	 	 		  		  	 		  		  		 	 				  	 		  	 			     	   	 	
// 4C2A8FE7EAF24721CC7A9F0175115BD4
void f0_6(string As_0) {
   Comment(As_0);
   if (StringLen(As_0) > 0) Print(As_0);
}
		 	 	 		 			   	 	  		   		  	  	 	 	  		   	   		 					  	 			 	  	 			 	     	 	 	 		  			  	    	 	 				 		 		       	    				 	 			 	  		 		
// 29EFDD0933871A47BAC839D6E9ADA7F7
string f0_2(bool Ai_0, string As_4, string As_12) {
   if (Ai_0) return (As_4);
   return (As_12);
}
						 	   	        			 	  		 	 						   		 		  		   			  									   		    	         			  	   		 	   	  	 				  		 	   			 	 		 										  	 	 
// 436F5A19B3A03B7E56C5A3C6E5948369
int f0_4(string As_0 = "", int Acmd8 = -1, int Amagic12 = -1, int Ai_16 = 0) {
   int ordertotal24 = OrdersTotal();
   if (As_0 == "0") As_0 = Symbol();
   for (int pos_20 = 0; pos_20 < ordertotal24; pos_20++) {
      if (OrderSelect(pos_20, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol() == As_0 || As_0 == "") {
            if (OrderType() == OP_BUY || OrderType() == OP_SELL) {
               if (Acmd8 < OP_BUY || OrderType() == Acmd8) {
                  if (Amagic12 < 0 || OrderMagicNumber() == Amagic12)
                     if (Ai_16 <= OrderOpenTime()) return (1);
               }
            }
         }
      }
   }
   return (0);
}
				 			   		 	      	  	  	    				 		  		  		 		  		 	  		 	 				 	  	      	     	  		  		 			 	 	    	 	 	   		   	 			    	 			 	 				 				 
// 5AEEEB0339BF3B809576C8AEEC9E9A92
void f0_8() {
   bool is_closed_0;
   color color_4;
   double order_lots_8;
   double price_16;
   double price_24;
   double price_32;
   int error_40;
   if (OrderType() == OP_BUY || OrderType() == OP_SELL) {
      for (int Li_44 = 1; Li_44 <= 5; Li_44++) {
         if (!IsTesting() && (!IsExpertEnabled()) || IsStopped()) break;
         while (!IsTradeAllowed()) Sleep(5000);
         RefreshRates();
         price_16 = MarketInfo(OrderSymbol(), MODE_ASK);
         price_24 = MarketInfo(OrderSymbol(), MODE_BID);
         if (OrderType() == OP_BUY) {
            price_32 = price_24;
            color_4 = Lime;
         } else {
            price_32 = price_16;
            color_4 = Red;
         }
         order_lots_8 = OrderLots();
         is_closed_0 = OrderClose(OrderTicket(), order_lots_8, price_32, 30, color_4);
         if (is_closed_0) {
            PlaySound("ok.wav");
            return;
         }
         error_40 = GetLastError();
         PlaySound("wait.wav");
         if (error_40 == 146/* TRADE_CONTEXT_BUSY */) while (IsTradeContextBusy()) Sleep(11000);
         Print("Error(", error_40, ") Close ", f0_16(OrderType()), " ", ErrorDescription(error_40), ", try ", Li_44);
         Print(OrderTicket(), "  Ask=", price_16, "  Bid=", price_24, "  pp=", price_32);
         Print("sy=", OrderSymbol(), "  ll=", order_lots_8, "  sl=", OrderStopLoss(), "  tp=", OrderTakeProfit(), "  mn=", OrderMagicNumber());
         Sleep(5000);
      }
   } else Print("Некорректная торговая операция. Close ", f0_16(OrderType()));
}
	 		   			 			  		    	  	 	 		   		    	 	         	 						  		  	 						   	  		  				 	 			 	 		 			 	  	  	 	 	  	    	  				 		  		  	 	  		
// 059B0D4DA2C19C05E682F73846603B50
void f0_0(string As_0 = "", int Acmd8 = -1, int Amagic12 = -1) {
   int order_total_20 = OrdersTotal();
   if (As_0 == "0") As_0 = Symbol();
   for (int pos_16 = order_total_20 - 1; pos_16 >= 0; pos_16--) {
      if (OrderSelect(pos_16, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol() == As_0 || As_0 == "" && Acmd8 < OP_BUY || OrderType() == Acmd8) {
            if (OrderType() == OP_BUY || OrderType() == OP_SELL) {
               if (Amagic12 < 0 || OrderMagicNumber() == Amagic12)
                  if (OrderProfit() + OrderSwap() > 0.0) f0_8();
            }
         }
      }
   }
   order_total_20 = OrdersTotal();
   for (pos_16 = order_total_20 - 1; pos_16 >= 0; pos_16--) {
      if (OrderSelect(pos_16, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol() == As_0 || As_0 == "" && Acmd8 < OP_BUY || OrderType() == Acmd8) {
            if (OrderType() == OP_BUY || OrderType() == OP_SELL)
               if (Amagic12 < 0 || OrderMagicNumber() == Amagic12) f0_8();
         }
      }
   }
}
		 	  	 	 							 	    	  		 	 	 	 	  				    		 		 	   	  	     	  		  	 	  				 	 		    					     		 					   			   			 	   	  		 	     	  	 	 	
// 73CE652B24CD59D9CAB58474A8407399
double f0_9(string Asymbol0) {
   double lotstep_8 = MarketInfo(Asymbol0, MODE_LOTSTEP);
   int Li_ret_16 = MathCeil(MathAbs(MathLog(lotstep_8) / MathLog(10)));
   return (Li_ret_16);
}
		  			   	   		  				 		 	 	  			  				 	 									 	      		  		 	      			 		  		    	 	   	 	  	   	 		 		 	 	 		 				 		    	  		  		 	 		  
// A076F38073ABEC669F1459B783418EA6
void f0_14(string Asymbol0, int Acmd8, double Ad_12, double A_price_20 = 0.0, double A_price_28 = 0.0, int A_magic_36 = 0, string A_comment_40 = "") {
   color color_48;
   int datetime_52;
   double price_56;
   double price_64;
   double price_72;
   int digits_80;
   int error_84;
   int ticket_92 = 0;
   string comment_96 = A_comment_40;
   if (Asymbol0 == "" || Asymbol0 == "0") Asymbol0 = Symbol();
   if (Acmd8 == OP_BUY) color_48 = Lime;
   else color_48 = Red;
   for (int Li_88 = 1; Li_88 <= 5; Li_88++) {
      if (!IsTesting() && (!IsExpertEnabled()) || IsStopped()) {
         Print("OpenPosition(): Stops");
         break;
      }
      while (!IsTradeAllowed()) Sleep(5000);
      RefreshRates();
      digits_80 = MarketInfo(Asymbol0, MODE_DIGITS);
      price_64 = MarketInfo(Asymbol0, MODE_ASK);
      price_72 = MarketInfo(Asymbol0, MODE_BID);
      if (Acmd8 == OP_BUY) price_56 = price_64;
      else price_56 = price_72;
      price_56 = NormalizeDouble(price_56, digits_80);
      datetime_52 = TimeCurrent();
      if (AccountFreeMarginCheck(Symbol(), Acmd8, Ad_12) <= 0.0 || GetLastError() == 134/* NOT_ENOUGH_MONEY */) {
         if (!(ALERT)) return;
         Alert(WindowExpertName() + " " + Symbol(), " ", f0_15(), " ", "For opening a position ", f0_16(Acmd8), ", Lots=", Ad_12, ", The free means do not suffice.");
         return;
      }
      if (MarketWatch) ticket_92 = OrderSend(Asymbol0, Acmd8, Ad_12, price_56, Slippage, 0, 0, comment_96, A_magic_36, 0, color_48);
      else ticket_92 = OrderSend(Asymbol0, Acmd8, Ad_12, price_56, Slippage, A_price_20, A_price_28, comment_96, A_magic_36, 0, color_48);
      if (ticket_92 > 0) {
         PlaySound("ok");
         break;
      }
      error_84 = GetLastError();
      if (price_64 == 0.0 && price_72 == 0.0) f0_6("Check up in the Review of the market presence of a symbol " + Asymbol0);
      Print("Error(", error_84, ") opening position: ", ErrorDescription(error_84), ", try ", Li_88);
      Print("Ask=", price_64, " Bid=", price_72, " sy=", Asymbol0, " ll=", Ad_12, " op=", f0_16(Acmd8), " pp=", price_56, " sl=", A_price_20, " tp=", A_price_28, " mn=",
         A_magic_36);
      if (error_84 == 2/* COMMON_ERROR */ || error_84 == 64/* ACCOUNT_DISABLED */ || error_84 == 65/* INVALID_ACCOUNT */ || error_84 == 133/* TRADE_DISABLED */) {
         Gi_unused_256 = TRUE;
         break;
      }
      if (error_84 == 4/* SERVER_BUSY */ || error_84 == 131/* INVALID_TRADE_VOLUME */ || error_84 == 132/* MARKET_CLOSED */) {
         Sleep(300000);
         break;
      }
      if (error_84 == 128/* TRADE_TIMEOUT */ || error_84 == 142 || error_84 == 143) {
         Sleep(66666.0);
         if (f0_4(Asymbol0, Acmd8, A_magic_36, datetime_52)==1) {
            PlaySound("alert2");
            break;
         }
      }
      if (error_84 == 140/* LONG_POSITIONS_ONLY_ALLOWED */ || error_84 == 148/* TRADE_TOO_MANY_ORDERS */ || error_84 == 4110/* LONGS__NOT_ALLOWED */ || error_84 == 4111/* SHORTS_NOT_ALLOWED */) break;
      if (error_84 == 141/* TOO_MANY_REQUESTS */) Sleep(100000);
      if (error_84 == 145/* TRADE_MODIFY_DENIED */) Sleep(17000);
      if (error_84 == 146/* TRADE_CONTEXT_BUSY */) while (IsTradeContextBusy()) Sleep(11000);
      if (error_84 != 135/* PRICE_CHANGED */) Sleep(7700.0);
   }
   if (MarketWatch && ticket_92 > 0 && A_price_20 > 0.0 || A_price_28 > 0.0)
      if (OrderSelect(ticket_92, SELECT_BY_TICKET)) f0_18(-1, A_price_20, A_price_28);
}
				 	 	   		        		 	  	  	 				 	   		  	  		  				  		 						 	 		            	 			  		  		 	 	 	  	 	 		  		     			   		 			 						 		 	 
// F235F73FF9E6C9B0402F9856A41D6B1B
void f0_18(double A_order_open_price_0 = -1.0, double A_order_stoploss_8 = 0.0, double A_order_takeprofit_16 = 0.0, int A_datetime_24 = 0) {
   bool bool_28;
   color color_32;
   double ask_44;
   double bid_52;
   int error_80;
   int digits_76 = MarketInfo(OrderSymbol(), MODE_DIGITS);
   if (A_order_open_price_0 <= 0.0) A_order_open_price_0 = OrderOpenPrice();
   if (A_order_stoploss_8 < 0.0) A_order_stoploss_8 = OrderStopLoss();
   if (A_order_takeprofit_16 < 0.0) A_order_takeprofit_16 = OrderTakeProfit();
   A_order_open_price_0 = NormalizeDouble(A_order_open_price_0, digits_76);
   A_order_stoploss_8 = NormalizeDouble(A_order_stoploss_8, digits_76);
   A_order_takeprofit_16 = NormalizeDouble(A_order_takeprofit_16, digits_76);
   double Ld_36 = NormalizeDouble(OrderOpenPrice(), digits_76);
   double Ld_60 = NormalizeDouble(OrderStopLoss(), digits_76);
   double Ld_68 = NormalizeDouble(OrderTakeProfit(), digits_76);
   if (A_order_open_price_0 != Ld_36 || A_order_stoploss_8 != Ld_60 || A_order_takeprofit_16 != Ld_68) {
      for (int Li_84 = 1; Li_84 <= 5; Li_84++) {
         if (!IsTesting() && (!IsExpertEnabled()) || IsStopped()) break;
         while (!IsTradeAllowed()) Sleep(5000);
         RefreshRates();
         bool_28 = OrderModify(OrderTicket(), A_order_open_price_0, A_order_stoploss_8, A_order_takeprofit_16, A_datetime_24, color_32);
         if (bool_28) {
            PlaySound("alert");
            return;
         }
         error_80 = GetLastError();
         ask_44 = MarketInfo(OrderSymbol(), MODE_ASK);
         bid_52 = MarketInfo(OrderSymbol(), MODE_BID);
         Print("Error(", error_80, ") modifying order: ", ErrorDescription(error_80), ", try ", Li_84);
         Print("Ask=", ask_44, "  Bid=", bid_52, "  sy=", OrderSymbol(), "  op=" + f0_16(OrderType()), "  pp=", A_order_open_price_0, "  sl=", A_order_stoploss_8, "  tp=",
            A_order_takeprofit_16);
         Sleep(10000);
      }
   }
}
	 			 				 	 		 		  	    	 			    			 	 	 	 	 	        						  	  	  	 			  			 		   	 	 	 	 			 		  	  	  		   	 	 			   	 		 		 			  	  	   			
// AC13B0D7764C581227BB6C52D24050B2
string f0_15(int A_timeframe_0 = 0) {
   if (A_timeframe_0 == 0) A_timeframe_0 = Period();
   switch (A_timeframe_0) {
   case PERIOD_M1:
      return ("M1");
   case PERIOD_M5:
      return ("M5");
   case PERIOD_M15:
      return ("M15");
   case PERIOD_M30:
      return ("M30");
   case PERIOD_H1:
      return ("H1");
   case PERIOD_H4:
      return ("H4");
   case PERIOD_D1:
      return ("Daily");
   case PERIOD_W1:
      return ("Weekly");
   case PERIOD_MN1:
      return ("Monthly");
   }
   return ("UnknownPeriod");
}
	 					 		 	  				  		 	 	 		  	  							 	 				     	  						    	     		  	 				       	 	  	  		    		  			 		 	 	 		  	 	   	 				    	  		 	
// 810FA1277F5CF6481343A5EE21F2B5D1
void f0_11(string As_0 = "gdt_") {
   string name_8;
   for (int Li_16 = ObjectsTotal() - 1; Li_16 >= 0; Li_16--) {
      name_8 = ObjectName(Li_16);
      if (StringFind(name_8, As_0) != -1) ObjectDelete(name_8);
   }
}
		   			  	 	 	   		 	  	 	     		   		  	 	 		 						 	     	 			 		  	  		  	   			  		 	 	 			  		    		  	   	 	  	 		 	   	 	   	 			 					 
// E37F0136AA3FFAF149B351F6A4C948E9
int init() {
   SetApplicationPath(TerminalPath());
   Gi_220 = 0;
   f0_3(PAIRS);
   ArrayResize(Gda_228, period);
   ArraySetAsSeries(Gda_228, TRUE);
   ArraySetAsSeries(Gda_232, TRUE);
   return (0);
}
	 		    		 			 			    		 	 	 			  		   		 	    	    	 	 				  	   	 			 		   	 			  			  	 			   		 					  	  			 	  	 	  	  		 	 		  	   	 	   	
// 52D46093050F38C27267BCE42543EF60
int deinit() {
   f0_11();
   return (0);
}
			 		         	   						   	 					 		 	 					 			 	 		   	 			 				  	    		  	   	  	 	       	 		  		 	  				 				  						 	  		 			 				 	   
// EA2B2676C28C0DB26D39331A336C6B92
int start() {
   double Ld_8;
   double ask_16;
   double bid_24;
   double Ld_0 = f0_5();
   if (f0_4("", -1, MagicNumber)==1) {
      if (a1(Ld_0, TrailingStop, TrailingStart, AccountBalance())) {
         if (a2(Gd_196, Ld_0, TrailingStop, TrailingStep, AccountEquity())) {
            Gd_196 = Ld_0 - TrailingStop;
            Alert(AccountCompany(), " Достигнут новый уровень профита." + DoubleToStr(Gd_196, 0));
         }
      }
   } else Gd_196 = -999999999;
   if (Gd_196 >= Ld_0) {
      Gd_212 = 0;
      Gd_204 = 0;
      Ld_8 = AccountBalance();
      Alert(AccountCompany(), " Достигнут уровень профита, фиксируем прибыль " + DoubleToStr(Ld_0, 0), " AB= ", Ld_8);
      f0_0("", -1, MagicNumber);
      f0_12("", -1, MagicNumber);
      Alert(" AB= ", AccountBalance(), " PROFIT=", DoubleToStr(AccountBalance() - Ld_8, 3), AccountCurrency());
      Gd_196 = -999999999;
      return (0);
   }
   if (Ld_0 <= -LossClose) {
      Gd_212 = 0;
      Gd_204 = 0;
      Alert(AccountCompany(), " Достигнут уровень максимального убытка " + DoubleToStr(Ld_0, 2));
      f0_0("", -1, MagicNumber);
      f0_12("", -1, MagicNumber);
   }
   if (Ld_0 > Gd_212) Gd_212 = Ld_0;
   if (Ld_0 < Gd_204) Gd_204 = Ld_0;
   string Ls_32 = " ";
   for (int index_40 = 0; index_40 <= Gi_220; index_40++) {
      ask_16 = MarketInfo(Gsa_224[index_40], MODE_ASK);
      bid_24 = MarketInfo(Gsa_224[index_40], MODE_BID);
      if (ask_16 == 0.0 && bid_24 == 0.0) Alert("Symbol №" + ((index_40 + 1)) + " ERROR: Check up in the review of the market presence of a symbol: " + Gsa_224[index_40]);
      else {
         f0_17(Gsa_224[index_40]);
         Ls_32 = Ls_32 + ", " + Gsa_224[index_40];
      }
   }
   string Ls_44 = "NumberAccount=" + DoubleToStr(AccountNumber(), 0) + "  MagicNumber=" + f0_2(MagicNumber < 0, "All", DoubleToStr(MagicNumber, 0)) 
      + "\n" 
      + "TrailingStart=" + DoubleToStr(TrailingStart, 2) + " pip" + "TrailingStop=" + DoubleToStr(TrailingStop, 2) + " pip" + "  TrailingStep=" + DoubleToStr(TrailingStep, 2) + " pip" 
      + "\n" 
      + "Current Stop=" + f0_2(Gd_196 > -999999999.0, DoubleToStr(Gd_196, 2) + " pip", "None") 
      + "\n  Current Profit=" + DoubleToStr(Ld_0, 2) + " pip" 
      + "\n  MAX Profit=" + DoubleToStr(Gd_212, 2) + " pip" 
      + "\n  MIN Profit=" + DoubleToStr(Gd_204, 2) + " pip" 
      + "\n  Leverage=" + DoubleToStr(AccountLeverage(), 0) 
      + "\n  TICKVALUE = " + DoubleToStr(MarketInfo(Symbol(), MODE_TICKVALUE), 2) + " " + AccountCurrency() 
      + "\n  SYMBOLL = " + Ls_32 
      + "\n  SymbolSize = " + ((Gi_220 + 1)) 
   + "\n  START LOT = " + DoubleToStr(f0_7(), 2);
   Comment(Ls_44);
   return (0);
}
	     	 			 								   	 		  	 	      			  	  		  			   		         			  				 									   		 			  	 			 		 	    		  	 			   	 	  	          		 	 	
// CD57DCDF33D4425B290CED15552343D3
void f0_17(string Asymbol0) {
   double order_open_price_40;
   double order_lots_48;
   double order_open_price_56;
   double order_lots_64;
   double order_open_price_72;
   double order_lots_80;
   double order_open_price_88;
   double order_lots_96;
   double price_132;
   Gd_236 = f0_7();
   int count_8 = 0;
   int count_12 = 0;
   int count_16 = 0;
   int count_20 = 0;
   int count_24 = 0;
   int ticket_28 = -1;
   int ticket_32 = -1;
   int count_36 = 0;
   for (int pos_104 = 0; pos_104 <= OrdersTotal() - 1; pos_104++) {
      if (OrderSelect(pos_104, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol() == Asymbol0 && OrderMagicNumber() == MagicNumber) {
            if (OrderComment() == "buy") {
               if (OrderType() == OP_BUY) {
                  count_8++;
                  order_open_price_40 = OrderOpenPrice();
                  order_lots_48 = OrderLots();
               }
               if (OrderType() == OP_SELL) {
                  count_16++;
                  order_open_price_56 = OrderOpenPrice();
                  order_lots_64 = OrderLots();
               }
               if (OrderType() == OP_SELLSTOP) {
                  count_24++;
                  ticket_28 = OrderTicket();
               }
            }
            if (OrderComment() == "sell") {
               if (OrderType() == OP_SELL) {
                  count_12++;
                  order_open_price_88 = OrderOpenPrice();
                  order_lots_96 = OrderLots();
               }
               if (OrderType() == OP_BUY) {
                  count_20++;
                  order_open_price_72 = OrderOpenPrice();
                  order_lots_80 = OrderLots();
               }
               if (OrderType() == OP_BUYSTOP) {
                  count_36++;
                  ticket_32 = OrderTicket();
               }
            }
         }
      }
   }
   double ask_108 = MarketInfo(Asymbol0, MODE_ASK);
   double bid_116 = MarketInfo(Asymbol0, MODE_BID);
   double Ld_124 = f0_10(Asymbol0);
   double icustom_140 = iCustom(Asymbol0, TF, "Slope_Direction_Line", period, FilterNumber, ma_method, applied_price, 0, shift);
   double icustom_148 = iCustom(Asymbol0, TF, "Slope_Direction_Line", period, FilterNumber, ma_method, applied_price, 0, shift + 1);
   double icustom_156 = iCustom(Asymbol0, TF, "Slope_Direction_Line", period, FilterNumber, ma_method, applied_price, 0, shift + 2);
   bool Li_164 = FALSE;
   bool Li_168 = FALSE;
   if (icustom_140 > icustom_148 && icustom_156 > icustom_148) {
      if (Revers) Li_168 = TRUE;
      else Li_164 = TRUE;
   }
   if (icustom_140 < icustom_148 && icustom_156 < icustom_148) {
      if (Revers) Li_164 = TRUE;
      Li_168 = TRUE;
   }
   if (count_16 > 0 && Li_168) {
      price_132 = bid_116 - Level_Order * Ld_124;
      if (a6(count_24, bid_116, order_open_price_56, PIP_AV, Level_Order, Ld_124)) f0_13(Asymbol0, OP_SELLSTOP, NormalizeDouble(order_lots_64 * koef_LOT_AV, f0_9(Asymbol0)), price_132, 0, 0, MagicNumber, "buy");
      if (OrderSelect(ticket_28, SELECT_BY_TICKET) && bid_116 - OrderOpenPrice() > (PIP_AV + Level_Order) * Ld_124) OrderModify(ticket_28, price_132, 0, 0, 0);
   }
   if (count_20 > 0 && Li_164) {
      price_132 = ask_108 + Level_Order * Ld_124;
      if (a6(count_36, order_open_price_72, ask_108, PIP_AV, Level_Order, Ld_124)) f0_13(Asymbol0, OP_BUYSTOP, NormalizeDouble(order_lots_80 * koef_LOT_AV, f0_9(Asymbol0)), price_132, 0, 0, MagicNumber, "sell");
      if (OrderSelect(ticket_32, SELECT_BY_TICKET) && OrderOpenPrice() - ask_108 > (PIP_AV + Level_Order) * Ld_124) OrderModify(ticket_32, price_132, 0, 0, 0);
   }
   if (a5(count_8, count_16, order_open_price_40, ask_108, PIP_LOCK, Ld_124, Li_168) && Li_168) f0_14(Asymbol0, OP_SELL, NormalizeDouble(order_lots_48 * koef_LOT_LOCK, f0_9(Asymbol0)), 0, 0, MagicNumber, "buy");
   if (a5(count_12, count_20, bid_116, order_open_price_88, PIP_LOCK, Ld_124, Li_164) && Li_164) f0_14(Asymbol0, OP_BUY, NormalizeDouble(order_lots_96 * koef_LOT_LOCK, f0_9(Asymbol0)), 0, 0, MagicNumber, "sell");
   double Ld_unused_172 = 0;
   double Ld_180 = Gd_236;
   if (a4(count_8))
      if (Li_164) f0_14(Asymbol0, OP_BUY, Ld_180, 0, 0, MagicNumber, "buy");
   if (a4(count_12))
      if (Li_168) f0_14(Asymbol0, OP_SELL, Ld_180, 0, 0, MagicNumber, "sell");
}
		  				  	   	   				  	 	 	   		  			  	 				 				 	 	    		 			 	   	  			 	   		   		 	   			  	     		 		   	 		 	 		 		  	 	  		 			 	 			 
// 499744B6B0F87A4F4E391BD474DC063D
double f0_5() {
   double point_0;
   double tickvalue_8;
   double Ld_24;
   double Ld_ret_16 = 0;
   double leverage_40 = AccountLeverage();
   for (int pos_48 = 0; pos_48 < OrdersTotal(); pos_48++) {
      if (OrderSelect(pos_48, SELECT_BY_POS, MODE_TRADES)) {
         if (MagicNumber <= 0 || OrderMagicNumber() == MagicNumber) {
            point_0 = MarketInfo(OrderSymbol(), MODE_POINT);
            tickvalue_8 = MarketInfo(OrderSymbol(), MODE_TICKVALUE);
            if (StringFind(OrderSymbol(), "JPY") < 0) Ld_24 = 0.0001;
            else Ld_24 = 0.01;
            if (OrderType() == OP_BUY) Ld_ret_16 += a3(OrderProfit(), OrderCommission(), OrderSwap(), point_0, tickvalue_8, f0_7(), Ld_24, leverage_40);
            if (OrderType() == OP_SELL) Ld_ret_16 += a3(OrderProfit(), OrderCommission(), OrderSwap(), point_0, tickvalue_8, f0_7(), Ld_24, leverage_40);
         }
      }
   }
   return (Ld_ret_16);
}
	 		 			 	 		 	  	   	  		 	    	 		 		   	  		 	   		 	 			 	 		 	 	  	 	    	  	  	  			 		 					 	      	 	    	   	 	 	    	  		 	 		 	 				 
// 3FE0DFFF438296BB525E0E8642586C2D
void f0_3(string As_0) {
   string Ls_8;
   int index_16 = -1;
   int Li_20 = 0;
   while (Li_20 >= 0) {
      Li_20 = StringFind(As_0, ",", index_16 + 1);
      if (Li_20 >= 0) {
         index_16 = Li_20;
         Gi_220++;
      } else {
         if (StringLen(As_0) - index_16 > 0) {
            if (StrToDouble(StringSubstr(As_0, index_16 + 1)) > 0.0) Gi_220++;
            ArrayResize(Gsa_224, Gi_220);
            Ls_8 = As_0;
            for (index_16 = 0; index_16 <= Gi_220; index_16++) {
               Li_20 = StringFind(Ls_8, ",", 0);
               Gsa_224[index_16] = StringTrimLeft(StringTrimRight(StringSubstr(Ls_8, 0, Li_20)));
               if (Li_20 >= 0) Ls_8 = StringSubstr(Ls_8, Li_20 + 1);
            }
            Li_20 = -1;
         }
      }
   }
}
	 			 	 		 	 					  	  	 	 			 	  			 			 	 	 		        					     	  	  		  						   	   	 	 		  		  	 		  		  		 	 				  	 		  	 			     	   	 	
// 4CA46AAB119D6115222154B9DE991BEE
double f0_7() {
   double Ld_0 = AccountBalance();
   double Ld_8 = MarketInfo(Symbol(), MODE_MINLOT);
   double Ld_16 = MarketInfo(Symbol(), MODE_MAXLOT);
   double Ld_24 = Risk / 100.0;
   double Ld_ret_32 = MathFloor(Ld_0 * Ld_24 / MarketInfo(Symbol(), MODE_MARGINREQUIRED) / MarketInfo(Symbol(), MODE_LOTSTEP)) * MarketInfo(Symbol(), MODE_LOTSTEP);
   if (Lots > 0.0) Ld_ret_32 = Lots;
   if (Ld_ret_32 < Ld_8) Ld_ret_32 = Ld_8;
   if (Ld_ret_32 > Ld_16) Ld_ret_32 = Ld_16;
   return (Ld_ret_32);
}