

#property copyright "ForexOleg"
#property link      "olegforexprofit@gmail.com"

extern double TradeLot = 0.01;
extern double LotMultiply = 1.6;
extern double TakeProfit = 129.0;
extern double StepOpenNewOrder = 40.0;
extern bool UseTrailingStop = FALSE;
extern double TrailingValue = 10.0;
extern double TrailingStep = 2.0;
extern int MaxOpenOrders = 10;
extern bool StopSafeEquity = FALSE;
extern double EquityRiskPercent = 20.0;
extern double Slippage = 2.0;
extern int MagicNumber = 14579;
bool gi_156 = FALSE;
double gd_160 = 48.0;
double g_pips_168 = 500.0;
double gd_176 = 0.0;
bool gi_184 = TRUE;
bool gi_188 = FALSE;
int gi_192 = 1;
double g_price_196;
double g_price_204;
double g_bid_212;
double g_ask_220;
double gd_228;
double gd_236;
bool gi_244;
string gs_248 = "Nikodim";
int g_time_256 = 0;
int gi_260;
int gi_264 = 0;
double gd_268;
int g_pos_276 = 0;
int gi_280;
double gd_284 = 0.0;
bool gi_292 = FALSE;
bool gi_296 = FALSE;
bool gi_300 = FALSE;
int gi_304;
bool gi_308 = FALSE;
int g_datetime_312 = 0;
int g_datetime_316 = 0;
double gd_320;
double gd_328;
int g_acc_number_336 = 548585;

int init() {
   switch (MarketInfo(Symbol(), MODE_MINLOT)) {
   case 0.001:
      gd_176 = 3;
      break;
   case 0.01:
      gd_176 = 2;
      break;
   case 0.1:
      gd_176 = 1;
      break;
   case 1.0:
      gd_176 = 0;
   }
   return (0);
}
	 		 	 	 	 		    		    			    		  			 	 	 	   				 							 			  					  		   	    					     	     		   		 			 	 		 	 	   	  				    		 			 			 		 
int deinit() {
   return (0);
}
		  			 	 	   			  		 	   			   		     	 	 		     	  	    	  			      	  			  			    						 	 			  		   	   			  	 	  		 		  	 				      	      	
int start() {
   double order_lots_0;
   double order_lots_8;
   double iclose_16;
   double iclose_24;
 //if (!IsDemo() && AccountNumber() != g_acc_number_336) return (0);
   if (UseTrailingStop) f0_14(TrailingValue, TrailingStep, g_price_204);
   if (gi_156) {
      if (TimeCurrent() >= gi_260) {
         f0_3();
         Print(gs_248 + ": Closed All due to TimeOut");
      }
   }
   if (g_time_256 == Time[0]) return (0);
   g_time_256 = Time[0];
   double ld_32 = f0_5();
   if (StopSafeEquity) {
      if (ld_32 < 0.0 && MathAbs(ld_32) > EquityRiskPercent / 100.0 * f0_7()) {
         f0_3();
         Print(gs_248 + ": Closed All Stop Out!");
         gi_308 = FALSE;
      }
   }
   gi_280 = f0_12();
   if (gi_280 == 0) gi_244 = FALSE;
   for (g_pos_276 = OrdersTotal() - 1; g_pos_276 >= 0; g_pos_276--) {
      OrderSelect(g_pos_276, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
         if (OrderType() == OP_BUY) {
            gi_296 = TRUE;
            gi_300 = FALSE;
            order_lots_0 = OrderLots();
            break;
         }
      }
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
         if (OrderType() == OP_SELL) {
            gi_296 = FALSE;
            gi_300 = TRUE;
            order_lots_8 = OrderLots();
            break;
         }
      }
   }
   if (gi_280 > 0 && gi_280 <= MaxOpenOrders) {
      RefreshRates();
      gd_228 = f0_2();
      gd_236 = f0_6();
      if (gi_296 && gd_228 - Ask >= StepOpenNewOrder * Point) gi_292 = TRUE;
      if (gi_300 && Bid - gd_236 >= StepOpenNewOrder * Point) gi_292 = TRUE;
   }
   if (gi_280 < 1) {
      gi_300 = FALSE;
      gi_296 = FALSE;
      gi_292 = TRUE;
   }
   if (gi_292) {
      gd_228 = f0_2();
      gd_236 = f0_6();
      if (gi_300) {
         if (gi_188) {
            f0_1(0, 1);
            gd_268 = NormalizeDouble(LotMultiply * order_lots_8, gd_176);
         } else gd_268 = f0_10(OP_SELL);
         if (gi_184) {
            gi_264 = gi_280;
            if (gd_268 > 0.0) {
               RefreshRates();
               gi_304 = f0_11(1, gd_268, Bid, Slippage, Ask, 0, 0, gs_248 + "-" + gi_264, MagicNumber, 0, Red);
               if (gi_304 < 0) {
                  Print(gs_248 + ": Error: ", GetLastError());
                  return (0);
               }
               gd_236 = f0_6();
               gi_292 = FALSE;
               gi_308 = TRUE;
            }
         }
      } else {
         if (gi_296) {
            if (gi_188) {
               f0_1(1, 0);
               gd_268 = NormalizeDouble(LotMultiply * order_lots_0, gd_176);
            } else gd_268 = f0_10(OP_BUY);
            if (gi_184) {
               gi_264 = gi_280;
               if (gd_268 > 0.0) {
                  gi_304 = f0_11(0, gd_268, Ask, Slippage, Bid, 0, 0, gs_248 + "-" + gi_264, MagicNumber, 0, Blue);
                  if (gi_304 < 0) {
                     Print(gs_248 + ": Error: ", GetLastError());
                     return (0);
                  }
                  gd_228 = f0_2();
                  gi_292 = FALSE;
                  gi_308 = TRUE;
               }
            }
         }
      }
   }
   if (gi_292 && gi_280 < 1) {
      iclose_16 = iClose(Symbol(), 0, 2);
      iclose_24 = iClose(Symbol(), 0, 1);
      g_bid_212 = Bid;
      g_ask_220 = Ask;
      if ((!gi_300) && !gi_296) {
         gi_264 = gi_280;
         if (iclose_16 > iclose_24) {
            gd_268 = f0_10(OP_SELL);
            if (gd_268 > 0.0) {
               gi_304 = f0_11(1, gd_268, g_bid_212, Slippage, g_bid_212, 0, 0, gs_248 + " " + MagicNumber + "-" + gi_264, MagicNumber, 0, Red);
               if (gi_304 < 0) {
                  Print(gs_248 + " " + gd_268, "Error: ", GetLastError());
                  return (0);
               }
               gd_228 = f0_2();
               gi_308 = TRUE;
            }
         } else {
            gd_268 = f0_10(OP_BUY);
            if (gd_268 > 0.0) {
               gi_304 = f0_11(0, gd_268, g_ask_220, Slippage, g_ask_220, 0, 0, gs_248 + " " + MagicNumber + "-" + gi_264, MagicNumber, 0, Blue);
               if (gi_304 < 0) {
                  Print(gs_248 + " " + gd_268, "Error: ", GetLastError());
                  return (0);
               }
               gd_236 = f0_6();
               gi_308 = TRUE;
            }
         }
      }
      if (gi_304 > 0) gi_260 = TimeCurrent() + 60.0 * (60.0 * gd_160);
      gi_292 = FALSE;
   }
   gi_280 = f0_12();
   g_price_204 = 0;
   double ld_40 = 0;
   for (g_pos_276 = OrdersTotal() - 1; g_pos_276 >= 0; g_pos_276--) {
      OrderSelect(g_pos_276, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
         if (OrderType() == OP_BUY || OrderType() == OP_SELL) {
            g_price_204 += OrderOpenPrice() * OrderLots();
            ld_40 += OrderLots();
         }
      }
   }
   if (gi_280 > 0) g_price_204 = NormalizeDouble(g_price_204 / ld_40, Digits);
   if (gi_308) {
      for (g_pos_276 = OrdersTotal() - 1; g_pos_276 >= 0; g_pos_276--) {
         OrderSelect(g_pos_276, SELECT_BY_POS, MODE_TRADES);
         if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
            if (OrderType() == OP_BUY) {
               g_price_196 = g_price_204 + TakeProfit * Point;
               gd_284 = g_price_204 - g_pips_168 * Point;
               gi_244 = TRUE;
            }
         }
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
            if (OrderType() == OP_SELL) {
               g_price_196 = g_price_204 - TakeProfit * Point;
               gd_284 = g_price_204 + g_pips_168 * Point;
               gi_244 = TRUE;
            }
         }
      }
   }
   if (gi_308) {
      if (gi_244 == TRUE) {
         for (g_pos_276 = OrdersTotal() - 1; g_pos_276 >= 0; g_pos_276--) {
            OrderSelect(g_pos_276, SELECT_BY_POS, MODE_TRADES);
            if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
            if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) OrderModify(OrderTicket(), g_price_204, OrderStopLoss(), g_price_196, 0, Yellow);
            gi_308 = FALSE;
         }
      }
   }
   Comment("\n********************************" 
      + "\n                      RobotOleg" 
      + "\n********************************" 
      + "\nAcc.Balance: " + DoubleToStr(AccountBalance(), 2) + " / Acc.Equity: " + DoubleToStr(AccountEquity(), 2) 
      + "\nTrade Lot: " + DoubleToStr(TradeLot, 2) + " / Lot Multiply: " + DoubleToStr(LotMultiply, 2) 
      + "\nTake Profit: " + DoubleToStr(TakeProfit, 0) + " / Step New Order: " + DoubleToStr(StepOpenNewOrder, 0) 
      + "\n********************************" 
   + "\nContact e-mail: olegforexprofit@gmail.com");
   return (0);
}
	 		 	 			 		   			    	 	    			 			 	   	   		 	 					 	 			   				  	    	   						  	  	    			   						 	 	  	 	      				 	  		 		  			 			
double f0_8(double ad_0) {
   return (NormalizeDouble(ad_0, Digits));
}
	    	   		 	  	 	 	    				  	     	 			  	  	 			 			 			 		 			  	   	 			  	 	  		 	  	    	 	 	  	  	   	  	  		  		 	 				  	 	 	 	   	 	  
int f0_1(bool ai_0 = TRUE, bool ai_4 = TRUE) {
   int li_ret_8 = 0;
   for (int pos_12 = OrdersTotal() - 1; pos_12 >= 0; pos_12--) {
      if (OrderSelect(pos_12, SELECT_BY_POS, MODE_TRADES)) {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
            if (OrderType() == OP_BUY && ai_0) {
               RefreshRates();
               if (!IsTradeContextBusy()) {
                  if (!OrderClose(OrderTicket(), OrderLots(), f0_8(Bid), 5, CLR_NONE)) {
                     Print(gs_248 + ": Error Close BUY!");
                     li_ret_8 = -1;
                  }
               } else {
                  if (g_datetime_312 == iTime(NULL, 0, 0)) return (-2);
                  g_datetime_312 = iTime(NULL, 0, 0);
                  Print(gs_248 + ": Close BUY Trade Context Busy");
                  return (-2);
               }
            }
            if (OrderType() == OP_SELL && ai_4) {
               RefreshRates();
               if (!IsTradeContextBusy()) {
                  if (!(!OrderClose(OrderTicket(), OrderLots(), f0_8(Ask), 5, CLR_NONE))) continue;
                  Print(gs_248 + ": Error Close SELL!");
                  li_ret_8 = -1;
                  continue;
               }
               if (g_datetime_316 == iTime(NULL, 0, 0)) return (-2);
               g_datetime_316 = iTime(NULL, 0, 0);
               Print(gs_248 + ": Close SELL Trade Context Busy");
               return (-2);
            }
         }
      }
   }
   return (li_ret_8);
}
	 	 		 			      					  	 	 		 			 	   	   			 		 	   			 	   	   		    	   	    			  	  	   	   					 					 		 	  		         		 	     		  	   			
double f0_10(int a_cmd_0) {
   double ld_ret_4;
   int datetime_12;
   switch (gi_192) {
   case 0:
      ld_ret_4 = TradeLot;
      break;
   case 1:
      ld_ret_4 = NormalizeDouble(TradeLot * MathPow(LotMultiply, gi_264), gd_176);
      break;
   case 2:
      datetime_12 = 0;
      ld_ret_4 = TradeLot;
      for (int pos_20 = OrdersHistoryTotal() - 1; pos_20 >= 0; pos_20--) {
         if (!(OrderSelect(pos_20, SELECT_BY_POS, MODE_HISTORY))) return (-3);
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
            if (datetime_12 < OrderCloseTime()) {
               datetime_12 = OrderCloseTime();
               if (OrderProfit() < 0.0) {
                  ld_ret_4 = NormalizeDouble(OrderLots() * LotMultiply, gd_176);
                  continue;
               }
               ld_ret_4 = TradeLot;
               continue;
               return (-3);
            }
         }
      }
   }
   if (AccountFreeMarginCheck(Symbol(), a_cmd_0, ld_ret_4) <= 0.0) return (-1);
   if (GetLastError() == 134/* NOT_ENOUGH_MONEY */) return (-2);
   return (ld_ret_4);
}
		 	   	  				       	 		 	  			 	 				 		   				 			 			 			   	  			 				 		     		    			 	       			   	   			  		  					 	  									 					 
int f0_12() {
   int count_0 = 0;
   for (int pos_4 = OrdersTotal() - 1; pos_4 >= 0; pos_4--) {
      OrderSelect(pos_4, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
         if (OrderType() == OP_SELL || OrderType() == OP_BUY) count_0++;
   }
   return (count_0);
}
				   		  			  	 	  	 	     										  		  			   		 		   		     				 	 	  		  	 			   		 	 	  	 	  				 		   	 		 		   	 		 	 		 					 								
void f0_3() {
   for (int pos_0 = OrdersTotal() - 1; pos_0 >= 0; pos_0--) {
      OrderSelect(pos_0, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() == Symbol()) {
         if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) {
            if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Blue);
            if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, Red);
         }
         Sleep(1000);
      }
   }
}
			 		  	      		 			      		 	 			   		 				 	      		      	 	  	      	 	   		 	  	 			  	  		 			 	 	 	 		   			   	 	   					    	  		   	 	
int f0_11(int ai_0, double a_lots_4, double a_price_12, int a_slippage_20, double ad_24, int ai_32, int ai_36, string a_comment_40, int a_magic_48, int a_datetime_52, color a_color_56) {
   int ticket_60 = 0;
   int error_64 = 0;
   int count_68 = 0;
   int li_72 = 100;
   switch (ai_0) {
   case 2:
      for (count_68 = 0; count_68 < li_72; count_68++) {
         ticket_60 = OrderSend(Symbol(), OP_BUYLIMIT, a_lots_4, a_price_12, a_slippage_20, f0_9(ad_24, ai_32), f0_13(a_price_12, ai_36), a_comment_40, a_magic_48, a_datetime_52,
            a_color_56);
         error_64 = GetLastError();
         if (error_64 == 0/* NO_ERROR */) break;
         if (!((error_64 == 4/* SERVER_BUSY */ || error_64 == 137/* BROKER_BUSY */ || error_64 == 146/* TRADE_CONTEXT_BUSY */ || error_64 == 136/* OFF_QUOTES */))) break;
         Sleep(1000);
      }
      break;
   case 4:
      for (count_68 = 0; count_68 < li_72; count_68++) {
         ticket_60 = OrderSend(Symbol(), OP_BUYSTOP, a_lots_4, a_price_12, a_slippage_20, f0_9(ad_24, ai_32), f0_13(a_price_12, ai_36), a_comment_40, a_magic_48, a_datetime_52,
            a_color_56);
         error_64 = GetLastError();
         if (error_64 == 0/* NO_ERROR */) break;
         if (!((error_64 == 4/* SERVER_BUSY */ || error_64 == 137/* BROKER_BUSY */ || error_64 == 146/* TRADE_CONTEXT_BUSY */ || error_64 == 136/* OFF_QUOTES */))) break;
         Sleep(5000);
      }
      break;
   case 0:
      for (count_68 = 0; count_68 < li_72; count_68++) {
         RefreshRates();
         ticket_60 = OrderSend(Symbol(), OP_BUY, a_lots_4, Ask, a_slippage_20, f0_9(Bid, ai_32), f0_13(Ask, ai_36), a_comment_40, a_magic_48, a_datetime_52, a_color_56);
         error_64 = GetLastError();
         if (error_64 == 0/* NO_ERROR */) break;
         if (!((error_64 == 4/* SERVER_BUSY */ || error_64 == 137/* BROKER_BUSY */ || error_64 == 146/* TRADE_CONTEXT_BUSY */ || error_64 == 136/* OFF_QUOTES */))) break;
         Sleep(5000);
      }
      break;
   case 3:
      for (count_68 = 0; count_68 < li_72; count_68++) {
         ticket_60 = OrderSend(Symbol(), OP_SELLLIMIT, a_lots_4, a_price_12, a_slippage_20, f0_0(ad_24, ai_32), f0_4(a_price_12, ai_36), a_comment_40, a_magic_48, a_datetime_52,
            a_color_56);
         error_64 = GetLastError();
         if (error_64 == 0/* NO_ERROR */) break;
         if (!((error_64 == 4/* SERVER_BUSY */ || error_64 == 137/* BROKER_BUSY */ || error_64 == 146/* TRADE_CONTEXT_BUSY */ || error_64 == 136/* OFF_QUOTES */))) break;
         Sleep(5000);
      }
      break;
   case 5:
      for (count_68 = 0; count_68 < li_72; count_68++) {
         ticket_60 = OrderSend(Symbol(), OP_SELLSTOP, a_lots_4, a_price_12, a_slippage_20, f0_0(ad_24, ai_32), f0_4(a_price_12, ai_36), a_comment_40, a_magic_48, a_datetime_52,
            a_color_56);
         error_64 = GetLastError();
         if (error_64 == 0/* NO_ERROR */) break;
         if (!((error_64 == 4/* SERVER_BUSY */ || error_64 == 137/* BROKER_BUSY */ || error_64 == 146/* TRADE_CONTEXT_BUSY */ || error_64 == 136/* OFF_QUOTES */))) break;
         Sleep(5000);
      }
      break;
   case 1:
      for (count_68 = 0; count_68 < li_72; count_68++) {
         ticket_60 = OrderSend(Symbol(), OP_SELL, a_lots_4, Bid, a_slippage_20, f0_0(Ask, ai_32), f0_4(Bid, ai_36), a_comment_40, a_magic_48, a_datetime_52, a_color_56);
         error_64 = GetLastError();
         if (error_64 == 0/* NO_ERROR */) break;
         if (!((error_64 == 4/* SERVER_BUSY */ || error_64 == 137/* BROKER_BUSY */ || error_64 == 146/* TRADE_CONTEXT_BUSY */ || error_64 == 136/* OFF_QUOTES */))) break;
         Sleep(5000);
      }
   }
   return (ticket_60);
}
	 				  		 	   				 	    	  	 	 	 		  		  	 	 	  	 	 		  	 	 	 	 			           					 	 		  		  				 	 	 						    	    	   	 				  	  	   		  	 	
double f0_9(double ad_0, int ai_8) {
   if (ai_8 == 0) return (0);
   return (ad_0 - ai_8 * Point);
}
	 		 					 		 	 			   		 	     		 			     	    	 	 			 	 	 				  				 		    	 	 							 	  	  	 			    					 			  	 	 	    			  	  		  	  			  		
double f0_0(double ad_0, int ai_8) {
   if (ai_8 == 0) return (0);
   return (ad_0 + ai_8 * Point);
}
	      				 		  		 	 	 	 			 				   			    	 			 		 	 		 		 	    	  		 	  				  		  	   	 	  	  		 	 					     	   			    	 	 	 	 	 				    					
double f0_13(double ad_0, int ai_8) {
   if (ai_8 == 0) return (0);
   return (ad_0 + ai_8 * Point);
}
	   	  				  	  		 			 	 								    		    					 		   		 		      	   	 	  		 	  		      	 	 		  		 							  	  	   	 	    	   	 	 	  			     				
double f0_4(double ad_0, int ai_8) {
   if (ai_8 == 0) return (0);
   return (ad_0 - ai_8 * Point);
}
			    		   		  	 		 	 	   	 						 			  			 			    	 		    	     	 		 	 	 			  	 	 	   		   	  	 		 				 	    	 					   	  	 	 		  				 		 					
double f0_5() {
   double ld_ret_0 = 0;
   for (g_pos_276 = OrdersTotal() - 1; g_pos_276 >= 0; g_pos_276--) {
      OrderSelect(g_pos_276, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber)
         if (OrderType() == OP_BUY || OrderType() == OP_SELL) ld_ret_0 += OrderProfit();
   }
   return (ld_ret_0);
}
				  		   				   	  				    	 	 					  			  	 		  		  		  		 	 	 								  			   			 	  	 	 		   	  	 	  		  					 			 		 		    	 			 							 	 
void f0_14(int ai_0, int ai_4, double a_price_8) {
   int li_16;
   double order_stoploss_20;
   double price_28;
   if (ai_4 != 0) {
      for (int pos_36 = OrdersTotal() - 1; pos_36 >= 0; pos_36--) {
         if (OrderSelect(pos_36, SELECT_BY_POS, MODE_TRADES)) {
            if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
            if (OrderSymbol() == Symbol() || OrderMagicNumber() == MagicNumber) {
               if (OrderType() == OP_BUY) {
                  li_16 = NormalizeDouble((Bid - a_price_8) / Point, 0);
                  if (li_16 < ai_0) continue;
                  order_stoploss_20 = OrderStopLoss();
                  price_28 = Bid - ai_4 * Point;
                  if (order_stoploss_20 == 0.0 || (order_stoploss_20 != 0.0 && price_28 > order_stoploss_20)) OrderModify(OrderTicket(), a_price_8, price_28, OrderTakeProfit(), 0, Aqua);
               }
               if (OrderType() == OP_SELL) {
                  li_16 = NormalizeDouble((a_price_8 - Ask) / Point, 0);
                  if (li_16 < ai_0) continue;
                  order_stoploss_20 = OrderStopLoss();
                  price_28 = Ask + ai_4 * Point;
                  if (order_stoploss_20 == 0.0 || (order_stoploss_20 != 0.0 && price_28 < order_stoploss_20)) OrderModify(OrderTicket(), a_price_8, price_28, OrderTakeProfit(), 0, Red);
               }
            }
            Sleep(1000);
         }
      }
   }
}
	 		    		 			 				  	   	   		 	 						  	  		  	 		 	  	 		  	 					      		 						  		  	 	 				  		 				      	 		 	   		 			  				   					 	
double f0_7() {
   if (f0_12() == 0) gd_320 = AccountEquity();
   if (gd_320 < gd_328) gd_320 = gd_328;
   else gd_320 = AccountEquity();
   gd_328 = AccountEquity();
   return (gd_320);
}
			 			 	     			 			 	    		   			    	 				        	       			  	   	  	 	  			 	  					  	 			 			   	 	 			  			  		 	   	 			       		     	
double f0_2() {
   double order_open_price_0;
   int ticket_8;
   double ld_unused_12 = 0;
   int ticket_20 = 0;
   for (int pos_24 = OrdersTotal() - 1; pos_24 >= 0; pos_24--) {
      OrderSelect(pos_24, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_BUY) {
         ticket_8 = OrderTicket();
         if (ticket_8 > ticket_20) {
            order_open_price_0 = OrderOpenPrice();
            ld_unused_12 = order_open_price_0;
            ticket_20 = ticket_8;
         }
      }
   }
   return (order_open_price_0);
}
			 	 			    		 	 						   			 				  	   					 	       	      	   	  			 	 	 		 	 	   	 		  			 	 				 		 	 	 		 			 		  	      		   	 	 		  	 		
double f0_6() {
   double order_open_price_0;
   int ticket_8;
   double ld_unused_12 = 0;
   int ticket_20 = 0;
   for (int pos_24 = OrdersTotal() - 1; pos_24 >= 0; pos_24--) {
      OrderSelect(pos_24, SELECT_BY_POS, MODE_TRADES);
      if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue;
      if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber && OrderType() == OP_SELL) {
         ticket_8 = OrderTicket();
         if (ticket_8 > ticket_20) {
            order_open_price_0 = OrderOpenPrice();
            ld_unused_12 = order_open_price_0;
            ticket_20 = ticket_8;
         }
      }
   }
   return (order_open_price_0);
}