//+------------------------------------------------------------------+ //| Gold Scalping Bot for MT5 (XAUUSD) | //| Advanced Structure - For Educational Purpose Only | //+------------------------------------------------------------------+ #property copyright "Copyright © 2015, Amin Pro Trading" //#property link "http://cmillion.narod.ru"

#import "kernel32.dll" int _lopen(string a0, int a1); int _lclose(int a0); #import

extern bool allow_Buy_deals = TRUE; extern bool allow_Sell_deals = TRUE; extern bool prohibit_first_order = TRUE; extern bool open_orders_by_trend = FALSE; extern int first_step = 10; extern int do_not_place_order_near = 30; extern int step_of_change = 5; extern int distance_between_orders = 30; extern double maximum_loss = 100000.0; extern double loss_close_by_total_profit = 10.0;

//--- USER'S LOT SETTINGS - Control lot size from here extern string Lot_Settings = "Control Lot Size From Here"; extern double Lots_Normal = 0.01; extern double Lots_Recovery_Start_1 = 0.01; extern double Lots_Recovery_Step_1 = 0.01; extern double Lots_Recovery_Max_1 = 0.30; extern double Lots_Recovery_Start_2 = 0.03; extern double Lots_Recovery_Step_2 = 0.03; extern double Lots_Recovery_Max_2 = 0.30; //--- End of User's Lot Settings

extern int lot_rounding = 2; extern double profit_close_2_directions = 10.0; extern double profit_close_1_direction = 50.0; extern int K_auto_calculate_profit = 50; extern double loss_for_closing = 100000.0; extern string ____________________ = ""; extern string Trailing_Settings = "0-off 1-candles 2-fractals >2-points"; extern int trailing_length = 1; extern int trailing_step = 0; extern int minimum_profit_trailing = 10; extern int offset_from_fractal_candle = 0; extern int timeframe_candles_or_fractals = 15; extern string __________________ = ""; extern string Other_Settings = ""; extern int Magic = 777; extern int font_size = 10; extern color output_information_color = Lime; extern int Stoploss = 0; extern int Takeprofit = 0; extern string ___________________ = ""; extern string Indicator_Settings = "RSI"; extern bool opening_1_order_by_indicator = FALSE; extern int oversold_zone = 15; extern int overbought_zone = 85; extern int RSI_Period = 5; extern int indicator_timeframe = 0; extern int Key = 0;

bool G_bool_292; double G_tickvalue_296; int Gi_304; int Gi_308 = 3456; int G_acc_number_312; int G_slippage_316; string Gs_320; int RecoveryPhase = 0;

int init() { Gs_320 = " " + AccountCurrency(); G_tickvalue_296 = MarketInfo(Symbol(), MODE_TICKVALUE); if(!IsDllsAllowed()) { Comment("DLL imports are not allowed. Please enable them in the expert's properties."); return(0); } timeframe_candles_or_fractals = f0_4285(timeframe_candles_or_fractals); if(Digits == 5 || Digits == 3) G_slippage_316 = 30; Comment("Grid-Crawler"); Gi_304 = MarketInfo(Symbol(), MODE_STOPLEVEL); if(distance_between_orders < Gi_304) { Alert("distance_between_orders is less than STOPLEVEL. Changed to ", Gi_304); distance_between_orders = Gi_304; } if(first_step < Gi_304) { Alert("first_step is less than STOPLEVEL. Changed to ", Gi_304); first_step = Gi_304; } if(Lots_Recovery_Step_1 <= 0) Lots_Recovery_Step_1 = 0.01; if(Lots_Recovery_Step_2 <= 0) Lots_Recovery_Step_2 = 0.01; int y_0 = font_size + font_size / 2; ObjectCreate("Balance", OBJ_LABEL, 0, 0, 0); ObjectSet("Balance", OBJPROP_CORNER, 1); ObjectSet("Balance", OBJPROP_XDISTANCE, 5); ObjectSet("Balance", OBJPROP_YDISTANCE, y_0); y_0 += font_size * 2; ObjectCreate("Equity", OBJ_LABEL, 0, 0, 0); ObjectSet("Equity", OBJPROP_CORNER, 1); ObjectSet("Equity", OBJPROP_XDISTANCE, 5); ObjectSet("Equity", OBJPROP_YDISTANCE, y_0); y_0 += font_size * 2; ObjectCreate("FreeMargin", OBJ_LABEL, 0, 0, 0); ObjectSet("FreeMargin", OBJPROP_CORNER, 1); ObjectSet("FreeMargin", OBJPROP_XDISTANCE, 5); ObjectSet("FreeMargin", OBJPROP_YDISTANCE, y_0); y_0 += font_size * 2; G_acc_number_312 = AccountNumber(); G_bool_292 = (!IsDemo()) && (!IsTesting()); ObjectCreate("ProfitB", OBJ_LABEL, 0, 0, 0); ObjectSet("ProfitB", OBJPROP_CORNER, 1); ObjectSet("ProfitB", OBJPROP_XDISTANCE, 5); ObjectSet("ProfitB", OBJPROP_YDISTANCE, y_0); y_0 += font_size * 2; ObjectCreate("ProfitS", OBJ_LABEL, 0, 0, 0); ObjectSet("ProfitS", OBJPROP_CORNER, 1); ObjectSet("ProfitS", OBJPROP_XDISTANCE, 5); ObjectSet("ProfitS", OBJPROP_YDISTANCE, y_0); y_0 += font_size * 2; ObjectCreate("Profit", OBJ_LABEL, 0, 0, 0); ObjectSet("Profit", OBJPROP_CORNER, 1); ObjectSet("Profit", OBJPROP_XDISTANCE, 5); ObjectSet("Profit", OBJPROP_YDISTANCE, y_0); y_0 += 3 * font_size; int count_4 = 0; string name_8 = "Param" + count_4; ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0); ObjectSet(name_8, OBJPROP_CORNER, 1); ObjectSet(name_8, OBJPROP_XDISTANCE, 5); ObjectSet(name_8, OBJPROP_YDISTANCE, y_0); y_0 += font_size * 2; ObjectSetText(name_8, "--------------------------------------------------------", font_size, "Arial", Aqua); count_4++; name_8 = "Param" + count_4; ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0); ObjectSet(name_8, OBJPROP_CORNER, 1); ObjectSet(name_8, OBJPROP_XDISTANCE, 5); ObjectSet(name_8, OBJPROP_YDISTANCE, y_0); y_0 += 3 * font_size; ObjectSetText(name_8, "Set Parameters", font_size + 2, "Arial", Aqua); count_4++; name_8 = "Param" + count_4; string str_concat_16 = ""; if(allow_Buy_deals) str_concat_16 = "Buy "; if(allow_Sell_deals) str_concat_16 = StringConcatenate(str_concat_16, "Sell "); ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0); ObjectSet(name_8, OBJPROP_CORNER, 1); ObjectSet(name_8, OBJPROP_XDISTANCE, 5); ObjectSet(name_8, OBJPROP_YDISTANCE, y_0); y_0 += font_size * 2; ObjectSetText(name_8, StringConcatenate("Allowed ", str_concat_16), font_size, "Arial", output_information_color); count_4++; name_8 = "Object" + count_4; if(!open_orders_by_trend) { ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0); ObjectSet(name_8, OBJPROP_CORNER, 1); ObjectSet(name_8, OBJPROP_XDISTANCE, 5); ObjectSet(name_8, OBJPROP_YDISTANCE, y_0); y_0 += font_size * 2; ObjectSetText(name_8, "Do not open orders by trend ", font_size, "Arial", output_information_color); count_4++; name_8 = "Object" + count_4; } ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0); ObjectSet(name_8, OBJPROP_CORNER, 1); ObjectSet(name_8, OBJPROP_XDISTANCE, 5); ObjectSet(name_8, OBJPROP_YDISTANCE, y_0); y_0 += 2 * font_size; if(prohibit_first_order) ObjectSetText(name_8, "Advisor places the first order", font_size, "Arial", output_information_color); else ObjectSetText(name_8, "Advisor waits for the first order", font_size, "Arial", output_information_color); count_4++; name_8 = "Param" + count_4; ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0); ObjectSet(name_8, OBJPROP_CORNER, 1); ObjectSet(name_8, OBJPROP_XDISTANCE, 5); ObjectSet(name_8, OBJPROP_YDISTANCE, y_0); y_0 += font_size * 2; ObjectSetText(name_8, StringConcatenate("First step ", first_step, " p"), font_size, "Arial", output_information_color); count_4++; name_8 = "Param" + count_4; ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0); ObjectSet(name_8, OBJPROP_CORNER, 1); ObjectSet(name_8, OBJPROP_XDISTANCE, 5); ObjectSet(name_8, OBJPROP_YDISTANCE, y_0); y_0 += font_size * 2; ObjectSetText(name_8, StringConcatenate("Minimum distance to price ", do_not_place_order_near, " p"), font_size, "Arial", output_information_color); count_4++; name_8 = "Param" + count_4; ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0); ObjectSet(name_8, OBJPROP_CORNER, 1); ObjectSet(name_8, OBJPROP_XDISTANCE, 5); ObjectSet(name_8, OBJPROP_YDISTANCE, y_0); y_0 += font_size * 2; ObjectSetText(name_8, StringConcatenate("Order change step ", step_of_change, " p"), font_size, "Arial", output_information_color); count_4++; name_8 = "Param" + count_4; ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0); ObjectSet(name_8, OBJPROP_CORNER, 1); ObjectSet(name_8, OBJPROP_XDISTANCE, 5); ObjectSet(name_8, OBJPROP_YDISTANCE, y_0); y_0 += font_size * 2; ObjectSetText(name_8, StringConcatenate("Step between orders ", distance_between_orders, " p"), font_size, "Arial", output_information_color); count_4++; name_8 = "Param" + count_4; ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0); ObjectSet(name_8, OBJPROP_CORNER, 1); ObjectSet(name_8, OBJPROP_XDISTANCE, 5); ObjectSet(name_8, OBJPROP_YDISTANCE, y_0); y_0 += font_size * 2; ObjectSetText(name_8, "--------------------------------------------------------", font_size, "Arial", Aqua); count_4++; name_8 = "Param" + count_4; ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0); ObjectSet(name_8, OBJPROP_CORNER, 1); ObjectSet(name_8, OBJPROP_XDISTANCE, 35); ObjectSet(name_8, OBJPROP_YDISTANCE, y_0); ObjectSetText(name_8, "do not open this direction", font_size, "Arial", output_information_color); count_4++; name_8 = "Param" + count_4; ObjectCreate("Char.b", OBJ_LABEL, 0, 0, 0); ObjectSet("Char.b", OBJPROP_CORNER, 1); ObjectSet("Char.b", OBJPROP_XDISTANCE, 5); ObjectSet("Char.b", OBJPROP_YDISTANCE, y_0); y_0 += font_size * 2; ObjectSetText("Char.b", CharToStr(233), font_size, "Wingdings", Lime); ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0); ObjectSet(name_8, OBJPROP_CORNER, 1); ObjectSet(name_8, OBJPROP_XDISTANCE, 35); ObjectSet(name_8, OBJPROP_YDISTANCE, y_0); ObjectSetText(name_8, StringConcatenate("upon reaching loss ", maximum_loss, Gs_320), font_size, "Arial", output_information_color); count_4++; name_8 = "Param" + count_4; ObjectCreate("Char.s", OBJ_LABEL, 0, 0, 0); ObjectSet("Char.s", OBJPROP_CORNER, 1); ObjectSet("Char.s", OBJPROP_XDISTANCE, 5); ObjectSet("Char.s", OBJPROP_YDISTANCE, y_0); y_0 += font_size * 2; ObjectSetText("Char.s", CharToStr(234), font_size, "Wingdings", Lime); ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0); ObjectSet(name_8, OBJPROP_CORNER, 1); ObjectSet(name_8, OBJPROP_XDISTANCE, 5); ObjectSet(name_8, OBJPROP_YDISTANCE, y_0); y_0 += font_size * 2; ObjectSetText(name_8, "--------------------------------------------------------", font_size, "Arial", Aqua); count_4++; name_8 = "Param" + count_4; ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0); ObjectSet(name_8, OBJPROP_CORNER, 1); ObjectSet(name_8, OBJPROP_XDISTANCE, 35); ObjectSet(name_8, OBJPROP_YDISTANCE, y_0); y_0 += font_size; ObjectSetText(name_8, "close by total profit", font_size, "Arial", output_information_color); count_4++; name_8 = "Param" + count_4; ObjectCreate("Char.op", OBJ_LABEL, 0, 0, 0); ObjectSet("Char.op", OBJPROP_CORNER, 1); ObjectSet("Char.op", OBJPROP_XDISTANCE, 5); ObjectSet("Char.op", OBJPROP_YDISTANCE, y_0); y_0 += font_size; ObjectSetText("Char.op", CharToStr(75), font_size + 2, "Wingdings", Silver); ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0); ObjectSet(name_8, OBJPROP_CORNER, 1); ObjectSet(name_8, OBJPROP_XDISTANCE, 35); ObjectSet(name_8, OBJPROP_YDISTANCE, y_0); y_0 += font_size * 2; ObjectSetText(name_8, StringConcatenate("upon drawdown ", loss_close_by_total_profit, Gs_320), font_size, "Arial", output_information_color); count_4++; name_8 = "Param" + count_4; ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0); ObjectSet(name_8, OBJPROP_CORNER, 1); ObjectSet(name_8, OBJPROP_XDISTANCE, 5); ObjectSet(name_8, OBJPROP_YDISTANCE, y_0); y_0 += font_size * 2; ObjectSetText(name_8, "--------------------------------------------------------", font_size, "Arial", Aqua); count_4++; name_8 = "Param" + count_4; ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0); ObjectSet(name_8, OBJPROP_CORNER, 1); ObjectSet(name_8, OBJPROP_XDISTANCE, 5); ObjectSet(name_8, OBJPROP_YDISTANCE, y_0); y_0 += 2 * font_size; ObjectSetText(name_8, "User Controlled Lot Settings", font_size, "Arial", output_information_color); count_4++; name_8 = "Param" + count_4; ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0); ObjectSet(name_8, OBJPROP_CORNER, 1); ObjectSet(name_8, OBJPROP_XDISTANCE, 5); ObjectSet(name_8, OBJPROP_YDISTANCE, y_0); y_0 += 2 * font_size; ObjectSetText(name_8, StringConcatenate("profit for closing all ", profit_close_2_directions, Gs_320), font_size, "Arial", output_information_color); count_4++; name_8 = "Param" + count_4; if(f0_8364()) profit_close_2_directions = 0.01; if(K_auto_calculate_profit == 0) f0_12282("profit_close.1_direction", StringConcatenate("profit closing direction ", profit_close_1_direction, Gs_320), 5, y_0, output_information_color); else { f0_12282("StopProfit1", StringConcatenate("Auto-calculation of closing profit ", K_auto_calculate_profit), 5, 0, output_information_color); y_0 += font_size * 2; f0_12282("StopProfit2", StringConcatenate("Auto-calculation of closing profit ", K_auto_calculate_profit), 5, 0, output_information_color); } y_0 += 2 * font_size; count_4++; name_8 = "Param" + count_4; ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0); ObjectSet(name_8, OBJPROP_CORNER, 1); ObjectSet(name_8, OBJPROP_XDISTANCE, 5); ObjectSet(name_8, OBJPROP_YDISTANCE, y_0); y_0 += 2 * font_size; ObjectSetText(name_8, StringConcatenate("loss closing buy/sell ", loss_for_closing, Gs_320), font_size, "Arial", output_information_color); count_4++; name_8 = "Param" + count_4; if(trailing_length != 0) { if(trailing_length == 1) str_concat_16 = StringConcatenate("By candles ", f0_9613(timeframe_candles_or_fractals), " +- ", offset_from_fractal_candle); if(trailing_length == 2) str_concat_16 = StringConcatenate("By fractals ", f0_9613(timeframe_candles_or_fractals), " ", f0_9613(timeframe_candles_or_fractals), " +- ", offset_from_fractal_candle); if(trailing_length > 2) str_concat_16 = StringConcatenate("By pips ", trailing_length, " p"); if(trailing_step > 0) str_concat_16 = StringConcatenate(str_concat_16, " with step ", trailing_step, " p", " minimum trailing profit ", minimum_profit_trailing, " p"); ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0); ObjectSet(name_8, OBJPROP_CORNER, 1); ObjectSet(name_8, OBJPROP_XDISTANCE, 5); ObjectSet(name_8, OBJPROP_YDISTANCE, y_0); y_0 += 2 * font_size; ObjectSetText(name_8, StringConcatenate("trailing_length ", str_concat_16), font_size, "Arial", output_information_color); count_4++; name_8 = "Param" + count_4; } ObjectCreate(name_8, OBJ_LABEL, 0, 0, 0); ObjectSet(name_8, OBJPROP_CORNER, 1); ObjectSet(name_8, OBJPROP_XDISTANCE, 5); ObjectSet(name_8, OBJPROP_YDISTANCE, y_0); y_0 += font_size * 2; ObjectSetText(name_8, "--------------------------------------------------------", font_size, "Arial", Aqua); count_4++; name_8 = "Param" + count_4; loss_close_by_total_profit = -1.0 * loss_close_by_total_profit; maximum_loss = -1.0 * maximum_loss; loss_for_closing = -1.0 * loss_for_closing; return(0); }

int deinit() { ObjectsDeleteAll(0); return(0); }

int start() { double price_0 = 0.0; double Ld_16 = 0.0; double Ld_24 = 0.0; double Ld_8 = 0.0; double Ld_32 = 0.0; double Ld_40 = 0.0; double order_lots_48 = 0.0; double price_56 = 0.0; double price_64 = 0.0; double price_72 = 0.0; double price_80 = 0.0; int Li_88 = 0; int Li_92 = 0; int Li_96 = 0; int Li_100 = 0; int cmd_104 = 0; int ticket_108 = 0; int ticket_112 = 0; double price_116 = 0.0; double price_124 = 0.0; double price_132 = 0.0; double price_140 = 0.0; double price_148 = 0.0; double price_156 = 0.0; double Ld_164 = 0.0; double Ld_172 = 0.0; double price_180 = 0.0; double price_188 = 0.0; double price_200 = 0.0; double Ld_208 = 0.0; double Ld_216 = 0.0; double price_224 = 0.0; double lots_232 = 0.0; double irsi_240 = 0.0; int ordersInPhase1 = 0; int pos_196 = 0; for(pos_196 = 0; pos_196 < OrdersTotal(); pos_196++) { if(OrderSelect(pos_196, SELECT_BY_POS, MODE_TRADES)) { if(OrderSymbol() == Symbol() && Magic == OrderMagicNumber()) { cmd_104 = OrderType(); order_lots_48 = OrderLots(); price_0 = NormalizeDouble(OrderOpenPrice(), Digits); price_72 = NormalizeDouble(OrderStopLoss(), Digits); price_80 = NormalizeDouble(OrderTakeProfit(), Digits); price_56 = price_72; price_64 = price_80; if(cmd_104 == OP_BUYSTOP) { Li_96++; if(price_116 < price_0 || price_116 == 0.0) price_116 = price_0; ticket_108 = OrderTicket(); price_148 = price_0; } if(cmd_104 == OP_SELLSTOP) { Li_100++; if(price_140 > price_0 || price_140 == 0.0) price_140 = price_0; ticket_112 = OrderTicket(); price_156 = price_0; } if(cmd_104 == OP_BUY) { Li_88++; Ld_32 += order_lots_48; Ld_172 += price_0 * order_lots_48; if(price_116 < price_0 || price_116 == 0.0) price_116 = price_0; if(price_124 > price_0 || price_124 == 0.0) price_124 = price_0; Ld_24 += OrderProfit() + OrderSwap() + OrderCommission(); if(price_72 == 0.0 && Stoploss >= Gi_304 && Stoploss != 0) price_56 = NormalizeDouble(price_0 - Stoploss * Point, Digits); else price_56 = price_72; if(price_80 == 0.0 && Takeprofit >= Gi_304 && Takeprofit != 0) price_64 = NormalizeDouble(price_0 + Takeprofit * Point, Digits); else price_64 = price_80; if(price_56 > price_72 || price_64 != price_80) if(!OrderModify(OrderTicket(), price_0, price_56, price_64, 0, White)) Print("Error OrderModify ", GetLastError()); } if(cmd_104 == OP_SELL) { Li_92++; Ld_40 += order_lots_48; Ld_164 += price_0 * order_lots_48; if(price_140 > price_0 || price_140 == 0.0) price_140 = price_0; if(price_132 < price_0 || price_132 == 0.0) price_132 = price_0; Ld_16 += OrderProfit() + OrderSwap() + OrderCommission(); if(price_72 == 0.0 && Stoploss >= Gi_304 && Stoploss != 0) price_56 = NormalizeDouble(price_0 + Stoploss * Point, Digits); else price_56 = price_72; if(price_80 == 0.0 && Takeprofit >= Gi_304 && Takeprofit != 0) price_64 = NormalizeDouble(price_0 - Takeprofit * Point, Digits); else price_64 = price_80; if(price_56 < price_72 || (price_72 == 0.0 && price_56 != 0.0) || price_64 != price_80) if(!OrderModify(OrderTicket(), price_0, price_56, price_64, 0, White)) Print("Error ", GetLastError()); } } } } Ld_8 = Ld_24 + Ld_16; ObjectDelete("SLb"); ObjectDelete("SLs"); if(Li_88 > 0) { price_180 = NormalizeDouble(Ld_172 / Ld_32, Digits); ObjectCreate("SLb", OBJ_ARROW, 0, Time[0], price_180, 0, 0, 0, 0); ObjectSet("SLb", OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE); ObjectSet("SLb", OBJPROP_COLOR, Blue); } if(Li_92 > 0) { price_188 = NormalizeDouble(Ld_164 / Ld_40, Digits); ObjectCreate("SLs", OBJ_ARROW, 0, Time[0], price_188, 0, 0, 0, 0); ObjectSet("SLs", OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE); ObjectSet("SLs", OBJPROP_COLOR, Red); } if(trailing_length != 0) { for(pos_196 = 0; pos_196 < OrdersTotal(); pos_196++) { if(OrderSelect(pos_196, SELECT_BY_POS, MODE_TRADES)) { if(OrderSymbol() == Symbol() && Magic == OrderMagicNumber()) { cmd_104 = OrderType(); price_72 = NormalizeDouble(OrderStopLoss(), Digits); price_0 = NormalizeDouble(OrderOpenPrice(), Digits); price_56 = price_72; if(cmd_104 == OP_BUY) { price_200 = f0_833(1, Bid, trailing_length); if(price_200 >= price_180 + minimum_profit_trailing * Point && price_200 > price_72 + trailing_step * Point && (Bid - price_200) / Point > Gi_304) price_56 = price_200; if(price_56 > price_72) if(!OrderModify(OrderTicket(), price_0, price_56, OrderTakeProfit(), 0, White)) Print("Error ", GetLastError(), " Trailing Modify Buy SL ", price_72, "->", price_56); } if(cmd_104 == OP_SELL) { price_200 = f0_833(-1, Ask, trailing_length); if(((price_200 <= price_188 - minimum_profit_trailing * Point && price_200 < price_72 - trailing_step * Point) || price_72 == 0.0) && (price_200 - Ask) / Point > Gi_304) price_56 = price_200; if((price_56 < price_72 || price_72 == 0.0) && price_56 != 0.0) if(!OrderModify(OrderTicket(), price_0, price_56, OrderTakeProfit(), 0, White)) Print("Error ", GetLastError(), " Trailing Modify Sell SL ", price_72, "->", price_56, " TP "); } } } } } if(K_auto_calculate_profit == 0) { Ld_208 = profit_close_1_direction; Ld_216 = profit_close_1_direction; } else { if(Ld_32 == 0.0) Ld_208 = Lots_Normal * K_auto_calculate_profit * G_tickvalue_296; else Ld_208 = Ld_32 * K_auto_calculate_profit * G_tickvalue_296; if(Ld_40 == 0.0) Ld_216 = Lots_Normal * K_auto_calculate_profit * G_tickvalue_296; else Ld_216 = Ld_40 * K_auto_calculate_profit * G_tickvalue_296; f0_12282("StopProfit1", StringConcatenate("Auto-calculation of closing profit Buy ", Ld_208), 5, 0, output_information_color); f0_12282("StopProfit2", StringConcatenate("Auto-calculation of closing profit Sell ", Ld_216), 5, 0, output_information_color); } if(Ld_24 > loss_close_by_total_profit && Ld_16 > loss_close_by_total_profit) { ObjectSetText("Char.op", CharToStr(251), font_size + 2, "Wingdings", Silver); if(Ld_24 >= Ld_208) { Print("Closing Buy by Profit ", Ld_24); f0_1880(1); return(0); } if(Ld_16 >= Ld_216) { Print("Closing Sell by Profit ", Ld_16); f0_1880(-1); return(0); } } else { ObjectSetText("Char.op", CharToStr(74), font_size + 2, "Wingdings", Red); if(Ld_8 >= profit_close_2_directions) { Print("Closing all orders by 2 directions profit ", Ld_8); f0_1880(0); return(0); } } if(Ld_24 <= loss_for_closing) { Print("Closing Buy by Loss ", Ld_24); f0_1880(1); return(0); } if(Ld_16 <= loss_for_closing) { Print("Closing Sell by Loss ", Ld_16); f0_1880(-1); return(0); } if(Ld_24 <= maximum_loss) { Comment("Do not open Buy direction"); ObjectSetText("Char.b", CharToStr(225) + CharToStr(251), font_size, "Wingdings", Red); } else ObjectSetText("Char.b", CharToStr(233), font_size, "Wingdings", Lime); if(Ld_16 <= maximum_loss) { Comment("Do not open Sell direction"); ObjectSetText("Char.s", CharToStr(226) + CharToStr(251), font_size, "Wingdings", Red); } else ObjectSetText("Char.s", CharToStr(234), font_size, "Wingdings", Lime); if(Li_88 == 0 || Li_92 == 0) irsi_240 = iRSI(NULL, indicator_timeframe, RSI_Period, PRICE_CLOSE, 0); if(Ld_8 >= 0 && RecoveryPhase > 0) { RecoveryPhase = 0; } else if(Ld_8 < 0 && RecoveryPhase == 0) { RecoveryPhase = 1; }

// --- BUY ORDER LOGIC --- if(Li_96 == 0 && Ld_24 > maximum_loss && allow_Buy_deals) { if(Li_88 == 0) { if(irsi_240 < oversold_zone || (!opening_1_order_by_indicator)) price_224 = NormalizeDouble(Ask + first_step * Point, Digits); else price_224 = 0; } else { price_224 = NormalizeDouble(Ask + do_not_place_order_near * Point, Digits); if(price_224 < NormalizeDouble(price_124 - distance_between_orders * Point, Digits)) price_224 = NormalizeDouble(Ask + distance_between_orders * Point, Digits); } if((Li_88 == 0 || (price_116 != 0.0 && price_224 >= NormalizeDouble(price_116 + distance_between_orders * Point, Digits) && open_orders_by_trend) || (price_124 != 0.0 && price_224 <= NormalizeDouble(price_124 - distance_between_orders * Point, Digits))) && price_224 != 0.0) {

     // --- START FIX: BUY LOT CALCULATION ---
     if(RecoveryPhase == 0)
       {
        lots_232 = Lots_Normal;
        lots_232 = NormalizeDouble(lots_232, lot_rounding); // Normalize
       }
     else if(RecoveryPhase == 1)
       {
        lots_232 = Lots_Recovery_Start_1 + (Li_88 * Lots_Recovery_Step_1);
        
        // FIX: Normalize before comparison to prevent floating point errors
        lots_232 = NormalizeDouble(lots_232, lot_rounding);
        
        if(lots_232 >= Lots_Recovery_Max_1)
          {
           lots_232 = Lots_Recovery_Max_1;
           // Normalize Max Lot as well
           lots_232 = NormalizeDouble(lots_232, lot_rounding); 

           if(Ld_8 < 0)
              RecoveryPhase = 2;
          }
       }
     else // RecoveryPhase == 2
       {
        ordersInPhase1 = MathFloor((Lots_Recovery_Max_1 - Lots_Recovery_Start_1) / Lots_Recovery_Step_1) + 1;
        if(ordersInPhase1 < 0)
           ordersInPhase1 = 0;
        lots_232 = Lots_Recovery_Start_2 + ((Li_88 - ordersInPhase1) * Lots_Recovery_Step_2);

        // FIX: Normalize before comparison
        lots_232 = NormalizeDouble(lots_232, lot_rounding);

        if(lots_232 > Lots_Recovery_Max_2)
          {
           lots_232 = Lots_Recovery_Max_2;
          }
        
        // Normalize Max Lot (redundant but safe)
        lots_232 = NormalizeDouble(lots_232, lot_rounding);
        
        // Safety check: Prevent negative lots if Li_88 < ordersInPhase1 (due to shared RecoveryPhase)
        if (lots_232 <= 0) {
            lots_232 = MarketInfo(Symbol(), MODE_MINLOT);
        }
       }
     // Removed the standalone NormalizeDouble line here, as it's now handled inside each phase.
     // --- END FIX: BUY LOT CALCULATION ---

     if((lots_232 < AccountFreeMargin() / MarketInfo(Symbol(), MODE_MARGINREQUIRED) && Li_88 > 0) || prohibit_first_order)
       {
        if(OrderSend(Symbol(), OP_BUYSTOP, lots_232, price_224, G_slippage_316, 0, 0, "Amin Pro Trading", Magic, 0, Blue) == -1)
           Print("Cannot place BUYSTOP order Lot ", DoubleToStr(lots_232, 2), " Price ", price_224, " Ask ", Ask);
       }
     else
        Comment("Cannot place Lot ", DoubleToStr(lots_232, 2));
    }
 }
// --- SELL ORDER LOGIC --- if(Li_100 == 0 && Ld_16 > maximum_loss && allow_Sell_deals) { if(Li_92 == 0) { if(irsi_240 > overbought_zone || (!opening_1_order_by_indicator)) price_224 = NormalizeDouble(Bid - first_step * Point, Digits); else price_224 = 0; } else { price_224 = NormalizeDouble(Bid - do_not_place_order_near * Point, Digits); if(price_224 < NormalizeDouble(price_132 + distance_between_orders * Point, Digits)) price_224 = NormalizeDouble(Bid - distance_between_orders * Point, Digits); } if((Li_92 == 0 || (price_140 != 0.0 && price_224 <= NormalizeDouble(price_140 - distance_between_orders * Point, Digits) && open_orders_by_trend) || (price_132 != 0.0 && price_224 >= NormalizeDouble(price_132 + distance_between_orders * Point, Digits))) && price_224 != 0.0) {

     // --- START FIX: SELL LOT CALCULATION ---
     if(RecoveryPhase == 0)
       {
        lots_232 = Lots_Normal;
        lots_232 = NormalizeDouble(lots_232, lot_rounding); // Normalize
       }
     else if(RecoveryPhase == 1)
       {
        lots_232 = Lots_Recovery_Start_1 + (Li_92 * Lots_Recovery_Step_1);

        // FIX: Normalize before comparison to prevent floating point errors
        lots_232 = NormalizeDouble(lots_232, lot_rounding);

        if(lots_232 >= Lots_Recovery_Max_1)
          {
           lots_232 = Lots_Recovery_Max_1;
           // Normalize Max Lot as well
           lots_232 = NormalizeDouble(lots_232, lot_rounding);

           if(Ld_8 < 0)
              RecoveryPhase = 2;
          }
       }
     else // RecoveryPhase == 2
       {
        ordersInPhase1 = MathFloor((Lots_Recovery_Max_1 - Lots_Recovery_Start_1) / Lots_Recovery_Step_1) + 1;
        if(ordersInPhase1 < 0)
           ordersInPhase1 = 0;
        lots_232 = Lots_Recovery_Start_2 + ((Li_92 - ordersInPhase1) * Lots_Recovery_Step_2);

        // FIX: Normalize before comparison
        lots_232 = NormalizeDouble(lots_232, lot_rounding);
        
        if(lots_232 > Lots_Recovery_Max_2)
          {
           lots_232 = Lots_Recovery_Max_2;
          }

        // Normalize Max Lot (redundant but safe)
        lots_232 = NormalizeDouble(lots_232, lot_rounding);

        // Safety check: Prevent negative lots if Li_92 < ordersInPhase1 (due to shared RecoveryPhase)
        if (lots_232 <= 0) {
            lots_232 = MarketInfo(Symbol(), MODE_MINLOT);
        }
       }
     // --- END FIX: SELL LOT CALCULATION ---

     if((lots_232 < AccountFreeMargin() / MarketInfo(Symbol(), MODE_MARGINREQUIRED) && Li_92 > 0) || prohibit_first_order)
       {
        if(OrderSend(Symbol(), OP_SELLSTOP, lots_232, price_224, G_slippage_316, 0, 0, "Amin Pro Trading", Magic, 0, Red) == -1)
           Print("Cannot place SELLSTOP order Lot ", DoubleToStr(lots_232, 2), " Price ", price_224, " Bid ", Bid);
       }
     else
        Comment("Cannot place Lot ", DoubleToStr(lots_232, 2));
    }
 }
ObjectSetText("Balance", StringConcatenate("Balance ", DoubleToStr(AccountBalance(), 2)), font_size, "Arial", output_information_color); ObjectSetText("Equity", StringConcatenate("Equity ", DoubleToStr(AccountEquity(), 2)), font_size, "Arial", output_information_color); ObjectSetText("FreeMargin", StringConcatenate("Free Margin ", DoubleToStr(AccountFreeMargin(), 2)), font_size, "Arial", output_information_color); if(Ld_32 > 0.0) { ObjectSetText("ProfitB", StringConcatenate("Buy ", Li_88, " Profit ", DoubleToStr(Ld_24, 2), " Lot = ", DoubleToStr(Ld_32, 2)), font_size, "Arial", f0_11449(Ld_24 > 0.0, 65280, 255)); } else ObjectSetText("ProfitB", "", font_size, "Arial", Gray); if(Ld_40 > 0.0) { ObjectSetText("ProfitS", StringConcatenate("Sell ", Li_92, " Profit ", DoubleToStr(Ld_16, 2), " Lot = ", DoubleToStr(Ld_40, 2)), font_size, "Arial", f0_11449(Ld_16 > 0.0, 65280, 255)); } else ObjectSetText("ProfitS", "", font_size, "Arial", Gray); if(Ld_40 + Ld_32 > 0.0) ObjectSetText("Profit", StringConcatenate("Profit All ", DoubleToStr(Ld_8, 2)), font_size, "Arial", f0_11449(Ld_8 >= 0.0, 32768, 255)); else ObjectSetText("Profit", "", font_size, "Arial", Gray); if(price_148 != 0.0 && allow_Buy_deals) { if(Li_88 == 0) price_224 = NormalizeDouble(Ask + first_step * Point, Digits); else price_224 = NormalizeDouble(Ask + do_not_place_order_near * Point, Digits); if((((NormalizeDouble(price_148 - step_of_change * Point, Digits) > price_224 && price_224 <= NormalizeDouble(price_124 - distance_between_orders * Point, Digits)) || price_124 == 0.0 || open_orders_by_trend) && Li_88 == 0) || price_224 >= NormalizeDouble(price_116 + distance_between_orders * Point, Digits) || price_224 <= NormalizeDouble(price_124 - distance_between_orders * Point, Digits)) { if(!OrderModify(ticket_108, price_224, 0, 0, 0, White)) Print("Error ", GetLastError(), " Order Modify Buy OOP ", price_148, "->", price_224); else Print("Order Buy Modify OOP ", price_0, "->", price_224); } } if(price_156 != 0.0 && allow_Sell_deals) { if(Li_92 == 0) price_224 = NormalizeDouble(Bid - first_step * Point, Digits); else price_224 = NormalizeDouble(Bid - do_not_place_order_near * Point, Digits); if((((NormalizeDouble(price_156 + step_of_change * Point, Digits) < price_224 && price_224 >= NormalizeDouble(price_132 + distance_between_orders * Point, Digits)) || price_132 == 0.0 || open_orders_by_trend) && Li_92 == 0) || price_224 <= NormalizeDouble(price_140 - distance_between_orders * Point, Digits) || price_224 >= NormalizeDouble(price_132 + distance_between_orders * Point, Digits)) { if(!OrderModify(ticket_112, price_224, 0, 0, 0, White)) Print("Error ", GetLastError(), " Order Modify Sell OOP ", price_156, "->", price_224); else Print("Order Sell Modify OOP ", price_0, "->", price_224); } } return(0); }

int f0_1880(int Ai_0) { int error_8; int Li_12 = 0; int cmd_16; int count_24; bool Li_4 = TRUE; int pos_20; if((!G_bool_292) || Key == 5 * G_acc_number_312 - Gi_308) { while(true) { for(pos_20 = OrdersTotal() - 1; pos_20 >= 0; pos_20--) { if(OrderSelect(pos_20, SELECT_BY_POS)) { if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) { cmd_16 = OrderType(); if((cmd_16 == OP_BUY && Ai_0 == 1) || Ai_0 == 0) { Li_4 = OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Bid, Digits), G_slippage_316, Blue); if(Li_4) Comment("Order closed N ", OrderTicket(), " profit ", OrderProfit(), " ", TimeToStr(TimeCurrent(), TIME_SECONDS)); } if((cmd_16 == OP_SELL && Ai_0 == -1) || Ai_0 == 0) { Li_4 = OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Ask, Digits), G_slippage_316, Red); if(Li_4) Comment("Order closed N ", OrderTicket(), " profit ", OrderProfit(), " ", TimeToStr(TimeCurrent(), TIME_SECONDS)); } if((cmd_16 == OP_BUYSTOP && Ai_0 == 1) || Ai_0 == 0) Li_4 = OrderDelete(OrderTicket()); if((cmd_16 == OP_SELLSTOP && Ai_0 == -1) || Ai_0 == 0) Li_4 = OrderDelete(OrderTicket()); if(!Li_4) { error_8 = GetLastError(); if(error_8 >= 2) { if(error_8 == 129) { Comment("Invalid price ", TimeToStr(TimeCurrent(), TIME_SECONDS)); RefreshRates(); continue; } if(error_8 == 146) { if(!(IsTradeContextBusy())) continue; Sleep(2000); continue; } Comment("Error ", error_8, " closing order N ", OrderTicket(), " ", TimeToStr(TimeCurrent(), TIME_SECONDS)); } } } } } count_24 = 0; for(pos_20 = 0; pos_20 < OrdersTotal(); pos_20++) { if(OrderSelect(pos_20, SELECT_BY_POS)) { if(OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) { cmd_16 = OrderType(); if(((cmd_16 == OP_BUYSTOP || cmd_16 == OP_BUY) && Ai_0 == 1) || Ai_0 == 0) count_24++; if(((cmd_16 == OP_SELLSTOP || cmd_16 == OP_SELL) && Ai_0 == -1) || Ai_0 == 0) count_24++; } } } if(count_24 == 0) break; Li_12++; if(Li_12 > 10) { Alert(Symbol(), " Failed to close all deals, ", count_24, " remaining"); return(0); } Sleep(1000); RefreshRates(); if(!G_bool_292 || Key == 5 * G_acc_number_312 - Gi_308) continue; break; } } return(1); }

int f0_11449(bool Ai_0, int Ai_4, int Ai_8) { if(Ai_0) return(Ai_4); return(Ai_8); }

void f0_13961(string As_unused_0, int Ai_unused_8) { f0_4365(); }

void f0_4365() { }

int f0_8364() { string str_concat_0 = StringConcatenate(TerminalPath(), CharToStr(92), "experts", CharToStr(92), WindowExpertName(), ".mq", DoubleToStr(4, 0)); if(_lopen(str_concat_0, 4) >= 0) { _lclose(str_concat_0); return(1); } return(0); }

double f0_833(int Ai_0, double Ad_4, double A_pips_12) { double price_20 = 0; int Li_32 = 0, Li_28 = 0; if(A_pips_12 > 2.0) { if(Ai_0 == 1) price_20 = NormalizeDouble(Ad_4 - A_pips_12 * Point, Digits); else price_20 = NormalizeDouble(Ad_4 + A_pips_12 * Point, Digits); } else { if(A_pips_12 == 2.0) { if(Ai_0 == 1) { for(Li_32 = 1; Li_32 < 100; Li_32++) { price_20 = iFractals(Symbol(), timeframe_candles_or_fractals, MODE_LOWER, Li_32); if(price_20 != 0.0) { price_20 -= NormalizeDouble(offset_from_fractal_candle * Point, Digits); if(Ad_4 - Gi_304 * Point > price_20) break; } else price_20 = 0; } ObjectDelete("FR Buy"); ObjectCreate("FR Buy", OBJ_ARROW, 0, Time[Li_32], price_20 + Point, 0, 0, 0, 0); ObjectSet("FR Buy", OBJPROP_ARROWCODE, 218); ObjectSet("FR Buy", OBJPROP_COLOR, Red); } if(Ai_0 == -1) { for(Li_28 = 1; Li_28 < 100; Li_28++) { price_20 = iFractals(Symbol(), timeframe_candles_or_fractals, MODE_UPPER, Li_28); if(price_20 != 0.0) { price_20 += NormalizeDouble(offset_from_fractal_candle * Point, Digits); if(Ad_4 + Gi_304 * Point < price_20) break; } else price_20 = 0; } ObjectDelete("FR Sell"); ObjectCreate("FR Sell", OBJ_ARROW, 0, Time[Li_28], price_20, 0, 0, 0, 0); ObjectSet("FR Sell", OBJPROP_ARROWCODE, 217); ObjectSet("FR Sell", OBJPROP_COLOR, Red); } } if(A_pips_12 == 1.0) { if(Ai_0 == 1) { for(Li_32 = 1; Li_32 < 500; Li_32++) { price_20 = NormalizeDouble(iLow(Symbol(), timeframe_candles_or_fractals, Li_32) - offset_from_fractal_candle * Point, Digits); if(price_20 != 0.0) { if(Ad_4 - Gi_304 * Point > price_20) break; price_20 = 0; } } ObjectDelete("FR Buy"); ObjectCreate("FR Buy", OBJ_ARROW, 0, iTime(Symbol(), timeframe_candles_or_fractals, Li_32), price_20 + Point, 0, 0, 0, 0); ObjectSet("FR Buy", OBJPROP_ARROWCODE, 159); ObjectSet("FR Buy", OBJPROP_COLOR, Red); } if(Ai_0 == -1) { for(Li_28 = 1; Li_28 < 500; Li_28++) { price_20 = NormalizeDouble(iHigh(Symbol(), timeframe_candles_or_fractals, Li_28) + offset_from_fractal_candle * Point, Digits); if(price_20 != 0.0) { if(Ad_4 + Gi_304 * Point < price_20) break; price_20 = 0; } } ObjectDelete("FR Sell"); ObjectCreate("FR Sell", OBJ_ARROW, 0, iTime(Symbol(), timeframe_candles_or_fractals, Li_28), price_20, 0, 0, 0, 0); ObjectSet("FR Sell", OBJPROP_ARROWCODE, 159); ObjectSet("FR Sell", OBJPROP_COLOR, Red); } } } if(Ai_0 == 1) { if(price_20 != 0.0) { ObjectDelete("SL Buy"); ObjectCreate("SL Buy", OBJ_ARROW, 0, Time[0] + 60 * Period(), price_20, 0, 0, 0, 0); ObjectSet("SL Buy", OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE); ObjectSet("SL Buy", OBJPROP_COLOR, Blue); } if(Gi_304 > 0) { ObjectDelete("STOPLEVEL-"); ObjectCreate("STOPLEVEL-", OBJ_ARROW, 0, Time[0] + 60 * Period(), Ad_4 - Gi_304 * Point, 0, 0, 0, 0); ObjectSet("STOPLEVEL-", OBJPROP_ARROWCODE, 4); ObjectSet("STOPLEVEL-", OBJPROP_COLOR, Blue); } } if(Ai_0 == -1) { if(price_20 != 0.0) { ObjectDelete("SL Sell"); ObjectCreate("SL Sell", OBJ_ARROW, 0, Time[0] + 60 * Period(), price_20, 0, 0, 0, 0); ObjectSet("SL Sell", OBJPROP_ARROWCODE, SYMBOL_RIGHTPRICE); ObjectSet("SL Sell", OBJPROP_COLOR, Pink); } if(Gi_304 > 0) { ObjectDelete("STOPLEVEL+"); ObjectCreate("STOPLEVEL+", OBJ_ARROW, 0, Time[0] + 60 * Period(), Ad_4 + Gi_304 * Point, 0, 0, 0, 0); ObjectSet("STOPLEVEL+", OBJPROP_ARROWCODE, 4); ObjectSet("STOPLEVEL+", OBJPROP_COLOR, Pink); } } return(price_20); }

int f0_4285(int Ai_0) { if(Ai_0 > 43200) return(0); if(Ai_0 > 10080) return(43200); if(Ai_0 > 1440) return(10080); if(Ai_0 > 240) return(1440); if(Ai_0 > 60) return(240); if(Ai_0 > 30) return(60); if(Ai_0 > 15) return(30); if(Ai_0 > 5) return(15); if(Ai_0 > 1) return(5); if(Ai_0 == 1) return(1); if(Ai_0 == 0) return(Period()); return(0); }

string f0_9613(int Ai_0) { if(Ai_0 == 1) return("M1"); if(Ai_0 == 5) return("M5"); if(Ai_0 == 15) return("M15"); if(Ai_0 == 30) return("M30"); if(Ai_0 == 60) return("H1"); if(Ai_0 == 240) return("H4"); if(Ai_0 == 1440) return("D1"); if(Ai_0 == 10080) return("W1"); if(Ai_0 == 43200) return("MN1"); return("period error"); }

void f0_12282(string A_name_0, string A_text_8, int A_x_16, int A_y_20, color A_color_24) { if(ObjectFind(A_name_0) == -1) { ObjectCreate(A_name_0, OBJ_LABEL, 0, 0, 0); ObjectSet(A_name_0, OBJPROP_CORNER, 1); ObjectSet(A_name_0, OBJPROP_XDISTANCE, A_x_16); ObjectSet(A_name_0, OBJPROP_YDISTANCE, A_y_20); } ObjectSetText(A_name_0, A_text_8, font_size, "Arial", A_color_24); }

bot ye mera code ha mere bot ka. bot ab same bot ko me ne mt5 pe convert karna ha. please is me kuch b change na ho aur na is me kuch extra add kiya ho. bus mujay sirf mt5 version chahiye