Navigation:Home > Content >

lockandpipsing-edu.mq4

Time: 2011-07-18 | Download file:lockandpipsing-edu.mq4

/*
   2013-05-10 by Capella at http://worldwide-invest.org/
	- Added external Magic Numbers
	- Fixed bug in function f0_14 as parameters where nullified
*/
#property copyright "#Copyright © 2008, XrustSolution.#"
#property link      "#http://www.xrust.ucoz.net#"

//#include 
#import "stdlib.ex4"
   string ErrorDescription(int a0); // DA69CBAFF4D38B87377667EEC549DE5A
#import

extern string a = "KEY PARAMETERS OF THE ADVISER";
extern string b = "Maximum orders recommended amount =20";
extern int TotalOrders = 50;
extern string c = "Stoploss, for a scalping mode =0";
extern int StopLoss = 0;
extern string d = "TakeProfit, for a scalping mode=0";
extern int TakeProfit = 0;
extern string e = "StartLots of EA =0,01";
extern double StartLots = 0.01;
extern string x = "Permission to use the dynamic changes in the lot";
extern bool Martin = FALSE;
extern string gb = "dynamic change lot factor. if <1 it increases lot , if > 1 it is lot decreases ";
extern double MartinKoff = 1.0;
extern string g = "The permission to lot auto detection";
extern bool AutoLot = TRUE;
extern string ha = "the percentage of risk as% of deposit amount";
extern double Risk = 1.0;
extern string k = "oaa o?aeeeiaa ii yeaeoe a % io aaiiceoa";
extern double EqvTralStep = 0.03;
extern string i = "minimum break between the opening of orders in minutes";
extern int MinTradePause = 50;
extern string l = "authorization and flags";
extern string m = "Permission to restrict trade in time";
extern bool TradeOfTime = FALSE;
extern string n = "Hour start of trading";
extern int StartTradeHour = 22;
extern string o = "Hour late trade";
extern int EndTradeHour = 8;
extern string p = "Permission to display information in the main window";
extern bool ShowComment = TRUE;
extern string r = "switch alarm systems and security";
extern bool MargineVarning = FALSE;
extern string s = "permission for drawing graphic elements";
extern bool SetArrow = TRUE;
extern string t = "Key closing level position without loss";
extern bool Bu = FALSE;
extern string u = "Magic Numbers for Buy and Sell orders";
extern int Magic_Buy = 2891;
extern int Magic_Sell = 73351;

bool gi_312 = 3;
bool gi_316 = FALSE;
bool gi_320 = FALSE;
string gs_324 = "expert.wav";
int g_color_332 = Blue;
int g_color_336 = Red;
bool gi_340 = FALSE;
bool gi_unused_344 = FALSE;
int gi_unused_356 = 0;
int gi_unused_404 = 0;
int g_slippage_408 = 3;
double gd_420;
double gd_428;
bool gi_unused_468 = FALSE;
int gi_472 = 0;
int gi_unused_476 = 0;
int gi_unused_480 = 0;
int gi_484 = 1;
int gi_488 = 1;
double gd_492;
string g_str_concat_500;
bool gi_508 = FALSE;
int gi_512;
double gd_516;
int g_time_524 = 0;

void init() {
   double ld_0;
   gi_512 = TotalOrders;
   gd_420 = AccountBalance();
   if (StartLots < MarketInfo(Symbol(), MODE_MINLOT)) StartLots = MarketInfo(Symbol(), MODE_MINLOT);
   if (GlobalVariableCheck("stop")) GlobalVariableDel("stop");
   if (!GlobalVariableCheck("multi")) GlobalVariableSet("multi", 1);
   else {
      ld_0 = GlobalVariableGet("multi");
      ld_0++;
      GlobalVariableSet("multi", ld_0);
   }
   GlobalVariableSet("Risc", Risk);
   GlobalVariableSet("disable", 0);
   gd_492 = StartLots;
   if (GlobalVariableGet("multi") > 1.0) SetArrow = FALSE;
   if (!GlobalVariableCheck("step")) {
      GlobalVariableSet("step", EqvTralStep);
      return;
   }
   if (GlobalVariableGet("step") != EqvTralStep) GlobalVariableSet("step", EqvTralStep);
}
			    	    		   	 			     		 				 	   	    				 				     		 		 	  	  	    	  		  			 	  	 			 	   			 		 	    					 		  		  			 		  	   	 						
void deinit() {
   double ld_0;
   double ld_8;
   if (GlobalVariableCheck("stop")) GlobalVariableDel("stop");
   Comment("  ");
   if (GlobalVariableCheck("multi")) {
      ld_0 = GlobalVariableGet("multi");
      if (ld_0 > 1.0) {
         ld_0--;
         GlobalVariableSet("multi", ld_0);
      } else {
         GlobalVariableDel("multi");
         GlobalVariableDel("disable");
         GlobalVariableDel("step");
         if (GlobalVariableCheck("Risc")) GlobalVariableDel("Risc");
      }
   }
   if (gi_508) {
      ld_8 = GlobalVariableGet("disable");
      ld_8--;
      GlobalVariableSet("disable", ld_8);
      gi_508 = FALSE;
   }
}
					  	   	 	   	   	        				  	  	   	 			 		       	 			 	   	 	     	 		  	   	  	   	 	     	 		 			  				 			  							 					   	   				
int start() {
   double ld_0;
   double ld_8;
   if (GlobalVariableGet("multi") > 1.0) SetArrow = FALSE;
   if (GlobalVariableGet("multi") - GlobalVariableGet("disable") > 2.0) TradeOfTime = FALSE;
   if (MargineVarning) {
      if (f0_15()) {
         Sleep(10000);
         return (0);
      }
   }
   if ((!IsDemo()) && !IsOptimization() && (!IsTesting())) {
      Comment("Bad Account!!!");
      Sleep(500);
      Comment("  ");
      return (0);
   }
   if (AutoLot) {
      gi_512 = TotalOrders;
      if (gi_512 > gd_420 / (2.0 * (MarketInfo(Symbol(), MODE_MARGINREQUIRED) * f0_18()) * (GlobalVariableGet("multi") - GlobalVariableGet("disable")))) gi_512 = gd_420 / (2.0 * (MarketInfo(Symbol(), MODE_MARGINREQUIRED) * f0_18()) * (GlobalVariableGet("multi") - GlobalVariableGet("disable")));
   }
   if (gd_428 == 0.0) gd_428 = AccountBalance();
   if (OrdersTotal() < 1) {
      if (GlobalVariableCheck("stop")) GlobalVariableDel("stop");
      gd_428 = AccountBalance();
   }
   if (f0_22() < 0.0)
      if (GlobalVariableCheck("stop")) GlobalVariableDel("stop");
   if (OrdersTotal() >= gi_512)
      if (AccountBalance() == gd_420) f0_1();
   if (f0_8(EqvTralStep)) return (0);
   if (GlobalVariableCheck("stop")) return (0);
   if (GlobalVariableGet("multi") > 1.0) {
      if (gi_512 < 15) {
         if (!GlobalVariableCheck("disable")) GlobalVariableSet("disable", 1);
         else {
            if (!gi_508) {
               ld_0 = GlobalVariableGet("disable");
               ld_0++;
               GlobalVariableSet("disable", ld_0);
               gi_508 = TRUE;
            }
         }
         Comment("\nMulti Chart Mode \n", "STOPPED\n", "Because AccountFreeMargin is few");
         return (0);
      }
      if (gi_512 > 18) {
         if (gi_508) {
            ld_8 = GlobalVariableGet("disable");
            ld_8--;
            if (ld_8 <= 0.0) ld_8 = 0;
            GlobalVariableSet("disable", ld_8);
            gi_508 = FALSE;
         }
      }
   }
   gi_472 = 0;
   gi_unused_476 = 0;
   gi_unused_480 = 0;
   f0_2();
   if (GlobalVariableGet("multi") < 2.0)
      if (Bu) f0_5();
   if (f0_13()) {
      if (SetArrow)
         if (f0_17("0") > 0) f0_11("NullProfitDot", 4, 1, 0, f0_10(), White);
      gd_492 = StartLots;
      if (f0_19()) {
         f0_0();
         if (gi_472 < 0) {
            if (f0_17("0") < gi_512 && f0_3()) {
               gd_492 = StartLots * gi_484;
               if (AutoLot) {
                  gd_492 = f0_18();
                  if (OrdersTotal() > 2)
                     if (Martin) gd_492 = f0_7();
               }
               if (f0_9(1) >= f0_9(0)) f0_14(Symbol(), OP_BUY, gd_492, StopLoss, TakeProfit, Magic_Buy);
               if (f0_9(1) < f0_9(0)) f0_14(Symbol(), OP_SELL, gd_492, StopLoss, TakeProfit, Magic_Sell);
            }
         }
         if (gi_472 > 0) {
            if (f0_17("0") < gi_512 && f0_3()) {
               gd_492 = StartLots * gi_488;
               if (AutoLot) {
                  gd_492 = f0_18();
                  if (OrdersTotal() > 2)
                     if (Martin) gd_492 = f0_7();
               }
               if (f0_9(0) >= f0_9(1)) f0_14(Symbol(), OP_SELL, gd_492, StopLoss, TakeProfit, Magic_Sell);
               if (f0_9(0) < f0_9(1)) f0_14(Symbol(), OP_BUY, gd_492, StopLoss, TakeProfit, Magic_Buy);
            }
         }
      }
   }
   return (0);
}
	    		 			 	 			 			 								    		 		 			 	   	  							 	   	 			 	 					 	  		 			 		 			 	 					 	  	   		    	   		       	     			 			    
void f0_5() {
   bool li_0 = FALSE;
   if (OrdersTotal() == 1) {
      if (!li_0) {
         for (int pos_4 = 0; pos_4 < OrdersTotal(); pos_4++) {
            if (OrderSelect(pos_4, SELECT_BY_POS, MODE_TRADES)) {
               if (OrderSymbol() == Symbol()) {
                  if (OrderProfit() >= 0.0) {
                     li_0 = TRUE;
                     break;
                  }
               }
            }
         }
      }
      if (li_0) {
         for (pos_4 = 0; pos_4 < OrdersTotal(); pos_4++) {
            if (OrderSelect(pos_4, SELECT_BY_POS, MODE_TRADES)) {
               if (OrderSymbol() == Symbol()) {
                  if (OrderProfit() <= 1.0) {
                     f0_21(OrderTicket());
                     li_0 = FALSE;
                  }
               }
            }
         }
      }
   }
}
	 	 	  	 	   	     	 	   	 	  			  		  	 	   			  		     						 		 		 	  	 		 		 			  	    	 	 	 	 	 	 				 	  		 					   	 				  	 		     	 				
double f0_10() {
   double ld_ret_0 = 0;
   int li_8 = 0;
   int li_12 = 0;
   if (OrdersTotal() < 1) return (Bid);
   double minlot_16 = MarketInfo(Symbol(), MODE_MINLOT);
   for (int pos_24 = 0; pos_24 < OrdersTotal(); pos_24++) {
      if (OrderSelect(pos_24, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol() == Symbol()) {
            li_12 = OrderLots() / minlot_16;
            li_8 += li_12;
            ld_ret_0 += OrderOpenPrice() * li_12;
         }
      }
   }
   ld_ret_0 /= li_8;
   return (ld_ret_0);
}
	     	 			 					 											     		  	 			 		  	  		 				 	 	 	 			   					    		 		  		 					 							  	    	    	 	 		    	  	    				 				   
double f0_22() {
   double ld_ret_0 = 0;
   for (int pos_8 = 0; pos_8 < OrdersTotal(); pos_8++) {
      if (OrderSelect(pos_8, SELECT_BY_POS, MODE_TRADES))
         if (OrderSymbol() == Symbol()) ld_ret_0 = ld_ret_0 + OrderProfit() + OrderSwap() + OrderCommission();
   }
   return (ld_ret_0);
}
	   	   			  	 		 		 	 					  	   			   			  		 	  	   			 					 				 							 	 		 	  			 		 	  				 	   	  	      						   			 	   		 		 		 		  
double f0_7() {
   int count_0 = 0;
   double ld_4 = 0;
   for (int pos_12 = 0; pos_12 < OrdersTotal(); pos_12++) {
      if (OrderSelect(pos_12, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol() == Symbol()) {
            if (OrderCloseTime() == 0) {
               ld_4 += OrderLots();
               count_0++;
            }
         }
      }
   }
   return (NormalizeDouble(ld_4 / (count_0 * MartinKoff), 2));
}
				 			   		 	  	  	 	     		 			   			   		  	 		 			   	     	    	       	 	  	 		   	  	 		    	 			 		 						      			   	 			  	  	  	  		
double f0_18() {
   int li_84;
   if (OrdersTotal() < 1) gd_516 = AccountBalance();
   RefreshRates();
   double ld_24 = GlobalVariableGet("multi") - GlobalVariableGet("disable");
   double free_magrin_32 = AccountFreeMargin();
   double ld_40 = AccountBalance();
   double ld_48 = MarketInfo(Symbol(), MODE_MINLOT);
   double ld_56 = MarketInfo(Symbol(), MODE_MAXLOT);
   double lotstep_64 = MarketInfo(Symbol(), MODE_LOTSTEP);
   double ld_unused_72 = AccountStopoutLevel();
   int li_unused_80 = 1000.0 * ld_48;
   if (GlobalVariableGet("multi") > 1.0) Risk = GlobalVariableGet("Risc");
   if (Risk < 0.0) Risk = 0;
   if (Risk > 100.0) Risk = 100;
   if (lotstep_64 == 0.01) li_84 = 2;
   else li_84 = 1;
   if (ld_24 < 1.0) ld_24 = 1;
   double ld_16 = ld_40 * (Risk / 100.0) / ld_24;
   double ld_ret_0 = NormalizeDouble(ld_16 / 1000.0, li_84);
   if (ld_ret_0 > ld_56) ld_ret_0 = ld_56;
   if (ld_ret_0 < ld_48) ld_ret_0 = ld_48;
   return (ld_ret_0);
}
		 		 			 		 		 			  		 	 	    	 		 	 			 		 	 			    	 	   		    	 	   	 	 	  		       			  				 	  			   		 		 	  		  		 			 			 				 			  	 	 
void f0_11(string as_0, int ai_8, int a_width_12, int ai_16, double ad_20, color a_color_28) {
   string str_concat_32 = StringConcatenate(as_0, TimeToStr(TimeLocal(), TIME_DATE|TIME_SECONDS));
   ObjectCreate(str_concat_32, OBJ_ARROW, 0, 0, 0, 0, 0, 0, 0);
   ObjectSet(str_concat_32, OBJPROP_ARROWCODE, ai_8);
   ObjectSet(str_concat_32, OBJPROP_STYLE, STYLE_DASHDOT);
   ObjectSet(str_concat_32, OBJPROP_TIME1, Time[ai_16]);
   ObjectSet(str_concat_32, OBJPROP_PRICE1, ad_20);
   ObjectSet(str_concat_32, OBJPROP_WIDTH, a_width_12);
   ObjectSet(str_concat_32, OBJPROP_COLOR, a_color_28);
}
		   	 		 	 	   					   	 						 			 	 		 	 	 				 			  	  	  	   		 		 	 		 				  				 					  		 			  	     	 	 	 	  	 		    				      					 		 
string f0_12() {
   double ld_0 = GlobalVariableGet("multi") - GlobalVariableGet("disable");
   string str_concat_8 = StringConcatenate("MULTI CHART MODE \n", DoubleToStr(ld_0, 0), " EXPERT ENABLES");
   string ls_ret_16 = "SINGLE CHART MODE";
   if (GlobalVariableGet("multi") < 2.0) return (ls_ret_16);
   if (GlobalVariableGet("multi") > 1.0) return (str_concat_8);
   return ("");
}
		     	  	 		   					    			 						   	  	 				 	 		      	 		 	 		  	   		  		   		 	  					 	  				 		      			 	 		  	   			 	   	   								
void f0_2() {
   Comment("ACCOUNT BALANSE                                 =" + DoubleToStr(AccountBalance() + f0_9(0) + f0_9(1), 1) + "$\n" + "ACCOUNT FREE MARGIN                         =" + DoubleToStr(AccountFreeMargin(), 1) + "$\n" + "CURRENT PROFIT                                    =" + DoubleToStr(f0_22(), 1) + "$\n" + "PROFIT FROM THE START OF TRADING  =" + DoubleToStr(AccountBalance() - gd_420, 1) + "$\n" + "ALOVED ORDERS FOR THE OPENING      =" + gi_512 + "Pc.\n" + "OPEN ORDERS                                         =" + f0_17("0") + "Pc.\n" + g_str_concat_500, 
      "\n", f0_12(), 
      "\n", "Risk = ", Risk, " %", 
   "\nEquityTralingStep = ", GlobalVariableGet("step"));
}
					      	 	 	 	   	 	      	 		  	      	 		  		    	  	 					   	 		    	 	   	   		 	   	       	  	 			   			 				 						  					 	 	   		 	
int f0_15() {
   int li_0;
   double ld_4;
   if (AutoLot) {
      if (2.0 * (MarketInfo(Symbol(), MODE_MARGINREQUIRED) * f0_18() * gi_512) > gd_420) {
         ld_4 = 2.0 * (MarketInfo(Symbol(), MODE_MARGINREQUIRED) * f0_18() * gi_512);
         li_0 = gd_420 / (2.0 * (MarketInfo(Symbol(), MODE_MARGINREQUIRED) * f0_18()));
         Alert("THERE IS NOT ENOUGH MEANS FOR THE ACCOUNT" 
            + "\n" 
            + "For such quantity of warrants it is necessary" 
            + "\n" 
            + "The starting Deposit =" + ld_4 + " $\n" + "On your means it is possible to open " + li_0 + " Orders" 
            + "\n" 
            + "Fill up your account please" 
            + "\n" 
            + "Or reduce quantity of warrants" 
            + "\n" 
            + "Or reduce a traded lot" 
            + "\n" 
         + "Or disconnect the alarm system");
         return (1);
      }
   }
   if (!AutoLot) {
      if (2.0 * (MarketInfo(Symbol(), MODE_MARGINREQUIRED) * StartLots * gi_512) > gd_420) {
         ld_4 = 2.0 * (MarketInfo(Symbol(), MODE_MARGINREQUIRED) * StartLots * gi_512);
         li_0 = gd_420 / (2.0 * (MarketInfo(Symbol(), MODE_MARGINREQUIRED) * StartLots));
         Alert("THERE IS NOT ENOUGH MEANS FOR THE ACCOUNT" 
            + "\n" 
            + "For such quantity of warrants it is necessary" 
            + "\n" 
            + "The starting Deposit =" + ld_4 + " $\n" + "On your means it is possible to open " + li_0 + " Orders" 
            + "\n" 
            + "Fill up your account please" 
            + "\n" 
            + "Or reduce quantity of warrants" 
            + "\n" 
            + "Or reduce a traded lot" 
            + "\n" 
         + "Or disconnect the alarm system");
         return (1);
      }
   }
   return (0);
}
		  	     	  	 	 			 	 	  		  	 					     	  		  	 	   	   						 			 		  			 	    	  		 			 	    		 	  	   	   		 					 	  			  	  		 	 			 		 	
int f0_19() {
   if (!TradeOfTime) {
      g_str_concat_500 = StringConcatenate("the end of trading on Friday in ", DoubleToStr(EndTradeHour, 0), "hours");
      if (TimeDayOfWeek(TimeCurrent()) != 5) return (1);
      if (TimeHour(TimeCurrent()) > EndTradeHour) return (0);
      return (1);
   }
   if (TimeDayOfWeek(TimeCurrent()) == 5) StartTradeHour = 0;
   if (TimeDayOfWeek(TimeCurrent()) == 1 && TimeHour(TimeCurrent()) < 1) StartTradeHour = 1;
   if (StartTradeHour < EndTradeHour) {
      if (TimeHour(TimeCurrent()) >= StartTradeHour && TimeHour(TimeCurrent()) < EndTradeHour || f0_17("0") + f0_17("1")) {
         g_str_concat_500 = StringConcatenate("By the end of trading session :", DoubleToStr(EndTradeHour - TimeHour(TimeCurrent()), 0), " hours");
         return (1);
      }
   }
   if (StartTradeHour > EndTradeHour) {
      if (TimeHour(TimeCurrent()) >= StartTradeHour || TimeHour(TimeCurrent()) < EndTradeHour || f0_17("0") + f0_17("1")) {
         g_str_concat_500 = StringConcatenate("By the end of trading session :", DoubleToStr(EndTradeHour - TimeHour(TimeCurrent()), 0), " hours");
         return (1);
      }
   }
   g_str_concat_500 = StringConcatenate("resting to : ", StartTradeHour, ": 00");
   return (0);
}
	  	 	 	 				     	 	    		 					 	  	 	 				 		    		   	    	 			  		  		  			 	  			   	 	  	 		 	  			 	 	 		     	    	  		   	      	 	 			
int f0_0() {
   if (iClose(Symbol(), PERIOD_M30, 1) > iOpen(Symbol(), PERIOD_M30, 0)) {
      if (iClose(Symbol(), PERIOD_M15, 1) > iOpen(Symbol(), PERIOD_M15, 0)) {
         if (iClose(Symbol(), PERIOD_M5, 1) > iOpen(Symbol(), PERIOD_M5, 0)) {
            gi_472 = -1;
            gi_484++;
            gi_488 = 1;
            return (1);
         }
      }
   }
   if (iClose(Symbol(), PERIOD_M30, 1) < iOpen(Symbol(), PERIOD_M30, 0)) {
      if (iClose(Symbol(), PERIOD_M15, 1) < iOpen(Symbol(), PERIOD_M15, 0)) {
         if (iClose(Symbol(), PERIOD_M5, 1) < iOpen(Symbol(), PERIOD_M5, 0)) {
            gi_472 = 1;
            gi_484 = 1;
            gi_488++;
            return (-1);
         }
      }
   }
   gi_472 = 0;
   return (0);
}
		 		   	 		 	 				  	 		 	   	  		 	   	 		 		 		     		   				  	 	 			 	 	 	 	     					  	  	 	  	     		    	  						 				 		 			 				  		  
int f0_8(double ad_0) {
   if (OrdersTotal() < 1) {
      gd_428 = AccountBalance();
      return (0);
   }
   if (GlobalVariableCheck("step")) ad_0 = GlobalVariableGet("step");
   ad_0 *= (GlobalVariableGet("multi") - GlobalVariableGet("disable"));
   if (AccountEquity() > AccountBalance()) {
      if (AccountEquity() - AccountBalance() > AccountBalance() / 100.0 * (2.0 * ad_0)) ad_0 = 2.0 * ad_0;
      if (AccountEquity() > gd_428 + gd_428 / 100.0 * ad_0) {
         gd_428 += gd_428 / 200.0 * ad_0;
         if (!GlobalVariableCheck("stop")) GlobalVariableSet("stop", 0);
      }
      if (AccountEquity() <= gd_428) {
         f0_1();
         Print("CloseAll");
         GlobalVariableDel("stop");
         return (0);
      }
      Comment("EQUITY TRALING MODE\n", "EQUITY TRALING STEP   =", ad_0, " %", 
         "\nACCOUNT BALANS         = ", AccountBalance(), 
         "\nCLOSE LEVEL                  = ", gd_428, 
         "\nACCOUNT EQUITY        = ", AccountEquity(), 
      "\nNEXT STEP                     = ", gd_428 + gd_428 / 100.0 * ad_0);
      return (1);
   }
   return (0);
}
	   		  			    		 		   					 		   				  			   	 	  	 	 			 		 		 														 		 	 				 		    				     	  		     		 			   	 	 	   	  		 		  	  
int f0_20(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1) {
   if (as_0 == "0") as_0 = Symbol();
   if (OrderSymbol() == as_0 || as_0 == "") {
      if (OrderType() == a_cmd_8 || a_cmd_8 == -1)
         if (OrderMagicNumber() == a_magic_12 || a_magic_12 == -1) return (1);
   }
   return (0);
}
	 			 	  	 	 			     			 	      	   	 	  	 	 	    	   		 		 		 			  	  	 	  	    		    	     		  	   		 					 	 	 	 		 	  				    						     	  	
int f0_17(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1) {
   int count_16 = 0;
   if (as_0 == "0") as_0 = Symbol();
   for (int pos_20 = 0; pos_20 < OrdersTotal(); pos_20++) {
      if (OrderSelect(pos_20, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol() == as_0 || as_0 == "") {
            if (OrderType() == a_cmd_8 || a_cmd_8 == -1)
               if (OrderMagicNumber() == a_magic_12 || a_magic_12 == -1) count_16++;
         }
      }
   }
   return (count_16);
}
		 		 			 		 		 			  		 	 	    	 		 	 			 		 	 			    	 	   		    	 	   	 	 	  		       			  				 	  			   		 		 	  		  		 			 			 				 			  	 	 
double f0_9(int ai_0) {
   double ld_ret_4 = 0;
   if (OrdersTotal() < 1) return (-1);
   for (int pos_12 = OrdersTotal() + 1; pos_12 >= 0; pos_12--) {
      if (OrderSelect(pos_12, SELECT_BY_POS, MODE_TRADES))
         if (f0_20("0", ai_0)) ld_ret_4 += OrderProfit();
   }
   return (ld_ret_4);
}
		 		  	  		 	   		  	    	   					 	  	  		 			 	          			 	 	 	 	   	 	 		      	  		  	 	  	  	 		  		  			  			  	 					 	 			   		  				
void f0_1() {
   while (OrdersTotal() > 0) {
      for (int pos_0 = OrdersTotal() + 1; pos_0 >= 0; pos_0--)
         if (OrderSelect(pos_0, SELECT_BY_POS, MODE_TRADES)) f0_21(OrderTicket());
   }
}
		 	  			 					 			 			 	 	 	  	 		   			 				 			  	 	 	    	    	     	 	    		   	   			 					 	 				   	  		 	   	  		 	 	 			 	 		 			 		 	 
int f0_3() {
   int datetime_0 = 0;
   int li_4 = 0;
   double order_open_price_8 = 0;
   if (OrdersTotal() < 1) return (1);
   for (int pos_16 = 0; pos_16 < OrdersTotal(); pos_16++) {
      if (OrderSelect(pos_16, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol() == Symbol()) {
            if (OrderOpenTime() > datetime_0) {
               datetime_0 = OrderOpenTime();
               order_open_price_8 = OrderOpenPrice();
            }
         }
      }
   }
   if (order_open_price_8 != 0.0) li_4 = MathAbs(order_open_price_8 - Bid) / Point / 20.0 * (Bid * Point);
   if (TimeCurrent() - datetime_0 > 60 * (MinTradePause * (li_4 + 1))) return (1);
   return (0);
}
		 	    	 				 				 		 		 	 	 	  		     	 					 		  	  		    			  	   			 	   	 	   	 					 		  	 	 		     	     	   					 	 		 		 	 	 				 			  
int f0_13() {
   if (g_time_524 == Time[0]) return (0);
   g_time_524 = Time[0];
   return (1);
}
		 	 				 			 	 			 	 	 	 	 		 	 		  				 			  			  			 	         	  	  	 	  	 		   		  			 	 			 	 	 		   	 			 	      		 	   			 	  	 			 	  	 
void f0_21(int a_ticket_0) {
   int error_4;
   string symbol_12;
   double bid_20;
   for (int count_8 = 0; count_8 < 1; count_8++) {
      GetLastError();
      OrderSelect(a_ticket_0, SELECT_BY_TICKET, MODE_TRADES);
      symbol_12 = OrderSymbol();
      if (OrderType() == OP_BUY) {
         RefreshRates();
         bid_20 = MarketInfo(symbol_12, MODE_BID);
         if (!OrderClose(a_ticket_0, OrderLots(), bid_20, 3, Green)) error_4 = GetLastError();
      }
      if (OrderType() == OP_SELL) {
         RefreshRates();
         bid_20 = MarketInfo(symbol_12, MODE_ASK);
         if (!OrderClose(a_ticket_0, OrderLots(), bid_20, 3, Green)) error_4 = GetLastError();
      }
      if (error_4 == 0/* NO_ERROR */) {
         PlaySound("expert.wav");
         return;
      }
      if (error_4 != 0/* NO_ERROR */) {
         PlaySound("timeout.wav");
         Print("Error for Close Funtion =", error_4);
      }
      while (!IsTradeAllowed()) Sleep(5000);
      if (error_4 == 146/* TRADE_CONTEXT_BUSY */) while (IsTradeContextBusy()) Sleep(11000);
   }
}
	  		 	 				 				 	  						       	 	 	 				 	  	     				  		 	 		 	  				 	   		     		 	  		 			  		  	 		 	     		 		  			  	  						 	  	   
void f0_6(string as_0) {
   if (StringLen(as_0) > 0) Print(as_0);
}
		  		 		 	     				    	 		 			 					 		 	   				 	 	  	  		 	   					 	 							  	 		 				   		 		   	    		 	 	 		 	 		  	 				  	   				  		 
void f0_23(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;
   double ask_44;
   double bid_52;
   int error_80;
   color color_32 = White;
   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) return;
   if (a_order_stoploss_8 == ld_60 && ld_60 != 0.0 || a_order_stoploss_8 != 0.0 && a_order_takeprofit_16 == ld_68 && ld_68 != 0.0 || a_order_takeprofit_16 != 0.0) return;
   for (int li_84 = 1; li_84 <= gi_312; li_84++) {
      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) {
         if (!(gi_316)) break;
         PlaySound(gs_324);
         return;
      }
      error_80 = GetLastError();
      ask_44 = MarketInfo(OrderSymbol(), MODE_ASK);
      bid_52 = MarketInfo(OrderSymbol(), MODE_BID);
      if (gi_320) {
         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);
   }
}
	 	 	 		 	   		    	 		  	 	   		  		 		 	   	 	  		  	  					  		 		    	 		  	 			       	 			 	 	 						 	 			 				    	 		 	  	 			    	 	 		
int f0_4(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1, int ai_16 = 0) {
   int order_total_24 = OrdersTotal();
   if (as_0 == "0") as_0 = Symbol();
   for (int pos_20 = 0; pos_20 < order_total_24; 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 (a_cmd_8 < OP_BUY || OrderType() == a_cmd_8) {
                  if (a_magic_12 < 0 || OrderMagicNumber() == a_magic_12)
                     if (ai_16 <= OrderOpenTime()) return (1);
               }
            }
         }
      }
   }
   return (0);
}
		  	 	 	 	  							 				 		     				 	 	 	  	  		 	  			  			 	  			  		 			   	  	   					 		 	 		 		     	 	  	 			 			  		  		  								 	   
string f0_16(int ai_0) {
   switch (ai_0) {
   case 0:
      return ("Buy");
   case 1:
      return ("Sell");
   case 2:
      return ("BuyLimit");
   case 3:
      return ("SellLimit");
   case 4:
      return ("BuyStop");
   case 5:
      return ("SellStop");
   }
   return ("Unknown Operation");
}
	  			  				   		 	    				  		   	 		  				  	 	    	 			  	 		 		 							 			 		   				 	     			      	 			      	 			  		 	 	  		  		 	   	  
void f0_14(string a_symbol_0, int a_cmd_8, double a_lots_12, double a_pips_20, double ad_28, int a_magic_36) {
   color color_40;
   int datetime_44;
   double price_48;
   double price_56;
   double price_64;
   double price_72;
   double price_80;
   int digits_88;
   int error_92;
   int ticket_100 = 0;
   string comment_104 = "";
   if (a_symbol_0 == "" || a_symbol_0 == "0") a_symbol_0 = Symbol();
   int li_112 = MarketInfo(a_symbol_0, MODE_STOPLEVEL);
   int spread_116 = MarketInfo(a_symbol_0, MODE_SPREAD);
   if (ad_28 != 0.0 && ad_28 < li_112 + spread_116) ad_28 = li_112;
   if (a_cmd_8 < OP_SELL) {
      if (a_pips_20 > 0.0) price_80 = MarketInfo(Symbol(), MODE_ASK) - a_pips_20 * Point;
      else price_80 = 0;
      if (ad_28 > 0.0) price_72 = MarketInfo(Symbol(), MODE_ASK) + ad_28 * Point;
      else price_72 = 0;
   } else {
      if (a_pips_20 > 0.0) price_80 = MarketInfo(Symbol(), MODE_BID) + a_pips_20 * Point;
      else price_80 = 0;
      if (ad_28 > 0.0) price_72 = MarketInfo(Symbol(), MODE_BID) - ad_28 * Point;
      else price_72 = 0;
   }
   if (a_cmd_8 == OP_BUY) color_40 = g_color_332;
   else color_40 = g_color_336;
   for (int li_96 = 1; li_96 <= gi_312; li_96++) {
      if (IsStopped()) {
         Print("OpenPosition(): Inoaiiaea ?aaiou ooieoee");
         break;
      }
      while (!IsTradeAllowed()) Sleep(5000);
      RefreshRates();
      digits_88 = MarketInfo(a_symbol_0, MODE_DIGITS);
      price_56 = MarketInfo(a_symbol_0, MODE_ASK);
      price_64 = MarketInfo(a_symbol_0, MODE_BID);
      if (a_cmd_8 == OP_BUY) price_48 = price_56;
      else price_48 = price_64;
      price_48 = NormalizeDouble(price_48, digits_88);
      datetime_44 = TimeCurrent();
      if (gi_340) ticket_100 = OrderSend(a_symbol_0, a_cmd_8, a_lots_12, price_48, g_slippage_408, 0, 0, comment_104, a_magic_36, 0, color_40);
      else ticket_100 = OrderSend(a_symbol_0, a_cmd_8, a_lots_12, price_48, g_slippage_408, price_80, price_72, comment_104, a_magic_36, 0, color_40);
      if (ticket_100 > 0) {
         if (!(gi_316)) break;
         PlaySound(gs_324);
         break;
      }
      error_92 = GetLastError();
      if (price_56 == 0.0 && price_64 == 0.0) f0_6("I?iaa?uoa a Iaci?a ?uiea iaee?ea neiaiea " + a_symbol_0);
      if (gi_320) {
         Print("Error(", error_92, ") opening position: ", ErrorDescription(error_92), ", try ", li_96);
         Print("Ask=", price_56, " Bid=", price_64, " sy=", a_symbol_0, " ll=", a_lots_12, " op=", f0_16(a_cmd_8), " pp=", price_48, " sl=", price_80, " tp=", price_72, " mn=",
            a_magic_36);
      }
      if (error_92 == 2/* COMMON_ERROR */ || error_92 == 64/* ACCOUNT_DISABLED */ || error_92 == 65/* INVALID_ACCOUNT */ || error_92 == 133/* TRADE_DISABLED */) {
         gi_unused_344 = TRUE;
         break;
      }
      if (error_92 == 4/* SERVER_BUSY */ || error_92 == 131/* INVALID_TRADE_VOLUME */ || error_92 == 132/* MARKET_CLOSED */) {
         Sleep(300000);
         break;
      }
      if (error_92 == 128/* TRADE_TIMEOUT */ || error_92 == 142 || error_92 == 143) {
         Sleep(66666.0);
         if (f0_4(a_symbol_0, a_cmd_8, a_magic_36, datetime_44)) {
            if (!(gi_316)) break;
            PlaySound(gs_324);
            break;
         }
      }
      if (error_92 == 140/* LONG_POSITIONS_ONLY_ALLOWED */ || error_92 == 148/* TRADE_TOO_MANY_ORDERS */ || error_92 == 4110/* LONGS__NOT_ALLOWED */ || error_92 == 4111/* SHORTS_NOT_ALLOWED */) break;
      if (error_92 == 141/* TOO_MANY_REQUESTS */) Sleep(100000);
      if (error_92 == 145/* TRADE_MODIFY_DENIED */) Sleep(17000);
      if (error_92 == 146/* TRADE_CONTEXT_BUSY */) while (IsTradeContextBusy()) Sleep(11000);
      if (error_92 != 135/* PRICE_CHANGED */) Sleep(7700.0);
   }
   if (gi_340 && ticket_100 > 0 && price_80 > 0.0 || price_72 > 0.0)
      if (OrderSelect(ticket_100, SELECT_BY_TICKET)) f0_23(-1, price_80, price_72);
}

Recommend