/* Generated by EX4-TO-MQ4 decompiler V4.0.225.1g [] Website: http://purebeam.biz E-mail : purebeam@gmail.com */ #property copyright "Copyright 2011, www.wallstreet-forex.com" #property link "http://www.wallstreet-forex.com" #import "wininet.dll" int InternetOpenA(string a0, int a1, string a2, string a3, int a4); int InternetOpenUrlA(int a0, string a1, string a2, int a3, int a4, int a5); int InternetCloseHandle(int a0); #import "WALLSTREET.dll" int SessionInit(int a0, int a1, int a2, int a3, string a4); int SessionDeinit(int a0, int a1, int a2, int a3, string a4); int ParamValue(int a0, int a1); bool CheckCloseLong(int a0, double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9); bool CheckCloseShort(int a0, double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8, double a9); bool CheckOpenLong(int a0, double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8); bool CheckOpenShort(int a0, double a1, double a2, double a3, double a4, double a5, double a6, double a7, double a8); #import extern int Magic = 4698523; extern string EA_Comment = ""; extern int MaxSpread = 4; extern int Slippage = 2; int gi_96 = 3; int gi_100 = 3; extern bool StealthMode = FALSE; bool gi_108 = TRUE; extern bool CloseOnlyOnProfit = FALSE; extern bool NFA = FALSE; extern bool No_Hedge = FALSE; extern string SS = "==== Custom Settings ===="; extern int StopLoss = 0; extern int TakeProfit = 0; extern int SecureProfit = 0; extern int SecureProfitTriger = 0; extern bool UseCustomPair = FALSE; extern string UseSettingsFrom = "EURUSD"; extern string MM = "==== Risk Management ===="; extern bool RecoveryMode = FALSE; extern double FixedLots = 0.1; extern double AutoMM = 0.0; extern double AutoMM_Max = 20.0; extern string WS = "==== Wallstreet shadow ===="; extern bool ShadowMode = True; extern double lotsize=0; extern int level=5; //extern int trackingmagic=16384; extern int mymagic=347895; extern int sl=40; color clCloseBuy = Green; color clCloseSell = Red; //int Slippage = 3; int NumberOfTry=3; bool gbNoInit = False; // Флаг неудачной инициализации //---------------------------------------------------- int gi_196 = 50; double gd_200 = 25.0; double gd_208 = 1.1; int g_period_216 = 0; int gi_220 = 0; int gi_224 = 0; int gi_228 = 0; int gi_232 = 0; int gi_236 = 0; int gi_240 = 0; int g_period_244 = 0; int gi_248 = 0; int gi_252 = 0; int gi_256 = 0; int gi_260 = 0; int gi_264 = 0; int g_period_268 = 0; int gi_272 = 0; int g_period_276 = 0; int gi_280 = 0; int gi_284 = 0; int gi_288 = -1; bool gi_292 = TRUE; bool gi_296 = FALSE; int g_stoplevel_300 = 0; double g_minlot_304 = 0.01; double g_maxlot_312 = 0.01; double g_lotstep_320 = 0.01; int g_lotsize_328 = 100000; double g_marginrequired_332 = 1000.0; double gd_340 = 0.0001; double gd_unused_348 = 0.1; double gd_unused_356 = 1.0; //-------------shadow--------------------------- int MyOrders[], trackingOrders[]; int in, r ,i,t,m,ticket; double a,b ,c, k = 1; double ps, pt, pp, lot; int trackingmagic; #include //------------------------------------------ int CheckWWW() { int li_20; bool li_ret_0 = TRUE; string ls_4 = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; Q312461)"; bool li_12 = FALSE; int li_16 = InternetOpenA(ls_4, li_12, "0", "0", 0); if (li_16 != 0) { li_20 = InternetOpenUrlA(li_16, "http://www.wallstreet-forex.com", "0", 0, -2080374528, 0); if (li_20 == 0) li_ret_0 = FALSE; else InternetCloseHandle(li_20); InternetCloseHandle(li_16); } else li_ret_0 = FALSE; return (li_ret_0); } void init() { gi_292 = TRUE; gi_288 = -1; Comment(""); if (ObjectFind("BKGR") >= 0) ObjectDelete("BKGR"); if (ObjectFind("BKGR2") >= 0) ObjectDelete("BKGR2"); if (ObjectFind("BKGR3") >= 0) ObjectDelete("BKGR3"); if (ObjectFind("BKGR4") >= 0) ObjectDelete("BKGR4"); if (ObjectFind("LV") >= 0) ObjectDelete("LV"); //------------shadow--------------------------- trackingmagic=Magic; if (Digits == 5) { k = 10; sl = sl*10; } ArrayResize(MyOrders, 0); ArrayResize(trackingOrders, 0); //Восстанавливаем потерянные позиции по комментариям // Shadow for ####### r=0; string st; for ( i = 0; i < OrdersTotal(); i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { if (OrderMagicNumber() == mymagic) { ticket = OrderTicket(); st = StringSubstr(OrderComment(), 11); t = StrToInteger(st); if (OrderSelect(t,SELECT_BY_TICKET)) { Print("Order Selected ", t); if (OrderCloseTime() == 0) //Добавляем только открытые ордеры. { r = ArraySize(trackingOrders); ArrayResize(trackingOrders, r+1); ArrayResize(MyOrders, r+1); trackingOrders[r] = OrderTicket(); MyOrders[r] = ticket; } else { //Если остался свой ордер, а оригинального нет - закрываем. OrderSelect(ticket, SELECT_BY_TICKET); ClosePosBySelect(); } } } } } if (r > 0) Print("Найдены старые ордера"); gbNoInit=False; if (!IsTradeAllowed()) { Message("Для нормальной работы советника необходимо\n"+ "Разрешить советнику торговать"); gbNoInit=True; return; } if (!IsLibrariesAllowed()) { Message("Для нормальной работы советника необходимо\n"+ "Разрешить импорт из внешних экспертов"); gbNoInit=True; return; } if (!IsTesting()) { if (IsExpertEnabled()) Message("Советник будет запущен следующим тиком"); else Message("Отжата кнопка \"Разрешить запуск советников\""); } if (level < 0) { Message("Level can not negative"); gbNoInit=True; return; } if (trackingmagic == 0 || trackingmagic == NULL ) { Message("You must set trackingmagic"); gbNoInit=True; return; } Message("Working"); return(0); } int deinit() { Comment(""); if (ObjectFind("BKGR") >= 0) ObjectDelete("BKGR"); if (ObjectFind("BKGR2") >= 0) ObjectDelete("BKGR2"); if (ObjectFind("BKGR3") >= 0) ObjectDelete("BKGR3"); if (ObjectFind("BKGR4") >= 0) ObjectDelete("BKGR4"); if (ObjectFind("LV") >= 0) ObjectDelete("LV"); if (gi_288 != -1) gi_288 = MyDeinit(); return (0); } int start() { double l_price_8; double ld_16; double ld_24; color l_color_32; double l_lots_40; int l_ticket_144; double l_price_156; double l_price_164; string ls_180; string ls_0 = ""; double ld_48 = 0; double ld_56 = 0; double ld_64 = 0; double ld_72 = 1; //---------------shadow---------------------------------------------------- if (ShadowMode) { trackingmagic=Magic; if (gbNoInit) { Message("Не удалось инициализировать советник!"); return; } for (i = 0; i < ArraySize(trackingOrders); i++) { if (OrderSelect(trackingOrders[i], SELECT_BY_TICKET)) { if (OrderCloseTime() != 0) // Ордер закрылся { OrderSelect(MyOrders[i],SELECT_BY_TICKET); //TODO: Обработка ошибок ClosePosBySelect(); //OrderClose(OrderTicket(), OrderLots(), pp, 3, Red); ArrayShift(trackingOrders, i); ArrayShift(MyOrders, i); Print("Закрылись"); } continue; } } for (i = 0; i < OrdersTotal(); i++) { if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) { t=OrderType(); if (t==OP_BUY || t==OP_SELL) { m = OrderMagicNumber(); if ( m == trackingmagic ) { in = ArraySearch(trackingOrders, OrderTicket()); if (in == -1) { // Найден неотслежуемый ордер c = OrderOpenPrice(); a = MarketInfo(OrderSymbol(), MODE_ASK); b = MarketInfo(OrderSymbol(), MODE_BID); if (t == OP_BUY) { //Проверяем BUY if ( c - b <= level * k * Point ) // Удовлетворяет разница { continue; } pp = a; ps = pp - sl * Point; } else { // Проверяем SELL if ( a - c <= level * k * Point ) { continue; } pp = b; ps = pp + sl * Point; } Print("Trying open ", OrderSymbol(), " ", pp, " ", ps , " ", 0, " Bid: ", Bid); if (lotsize == 0) {lot = OrderLots();} else {lot = lotsize;} //ticket = OrderSend(OrderSymbol(), t, OrderLots(), pp, Slippage, ps, pt, "Shadow for " + OrderTicket(), mymagic, 0, Green); ticket = OrderSend(OrderSymbol(), t, OrderLots(), pp, Slippage, 0, 0, "Shadow for " + OrderTicket(), mymagic, 0, Green); if(ticket<0) { Print("OrderSend failed with error #",GetLastError()); return(0); } //ps = OrderStopLoss(); //pt = OrderTakeProfit(); //ModifyOrder(-1, ps, double tp=0, datetime ex=0) //Добавляем в отслеживаемые r = ArraySize(trackingOrders); ArrayResize(trackingOrders, r+1); ArrayResize(MyOrders, r+1); trackingOrders[r] = OrderTicket(); MyOrders[r] = ticket; } else { //Проверяем на изменения pt = OrderTakeProfit(); ps = OrderStopLoss(); t = OrderTicket(); ticket = MyOrders[in]; if (OrderSelect(ticket, SELECT_BY_TICKET) == true) { if (OrderTakeProfit() == pt && OrderStopLoss() == ps) { continue; } else { Print(t, " <> ", ticket); // Нужна обработка ошибок //ModifyOrder(-1, ps, pt); if (OrderModify(OrderTicket(), OrderOpenPrice(), ps, pt,0,Blue) == False) Print("Can not modify ", GetLastError(), " price: ", OrderOpenPrice(), " SL: ", ps, " TP: ", pt); } } else { Print("Cannot select my order ", ticket, " ", in, " error ", GetLastError()); //ArrayPrint(MyOrders); //ArrayPrint(trackingOrders); //gbNoInit = true; } } } } } } //MarketInfo(OrderSymbol(), MODE_BID); //OrderProfit( ) } //------------------------------------------------------------------- if (DayOfWeek() == 1 && iVolume(NULL, PERIOD_D1, 0) < 5.0) return (0); if (StringLen(Symbol()) < 6) return (0); if (gi_292) { gi_292 = FALSE; g_stoplevel_300 = MarketInfo(Symbol(), MODE_STOPLEVEL); g_minlot_304 = MarketInfo(Symbol(), MODE_MINLOT); g_maxlot_312 = MarketInfo(Symbol(), MODE_MAXLOT); g_lotsize_328 = MarketInfo(Symbol(), MODE_LOTSIZE); g_lotstep_320 = MarketInfo(Symbol(), MODE_LOTSTEP); g_marginrequired_332 = MarketInfo(Symbol(), MODE_MARGINREQUIRED); if (Digits <= 3) gd_340 = 0.01; else gd_340 = 0.0001; if (Digits == 3 || Digits == 5) gd_unused_348 = 0.1; else gd_unused_348 = 1; Comment("\nInitializing ..."); Sleep(1000); gi_296 = CheckWWW(); Sleep(1000); if (!gi_296) gi_292 = TRUE; } if ((!IsTesting()) && IsStopped()) return (0); if ((!IsTesting()) && !IsTradeAllowed()) return (0); if ((!IsTesting()) && IsTradeContextBusy()) return (0); if (IsDllsAllowed() == FALSE) { Comment("\nWarning: Set Parameter **AllowDLL Imports** ON in menu Tools -> Options -> ExpertAdvisors."); Print("Warning: Set Parameter **AllowDLL Imports** ON in menu Tools -> Options -> ExpertAdvisors."); Alert("Warning: Set Parameter **AllowDLL Imports** ON in menu Tools -> Options -> ExpertAdvisors."); Sleep(30000); return (0); } if (gi_288 <= 0) { if (!gi_296) { Comment("\nInternet connection problem"); Alert("Internet connection problem"); Sleep(10000); return (0); } Comment("\nUpdating settings ..."); Sleep(2000); gi_288 = MyFirstInit(); Sleep(2000); if (gi_288 < 0) Comment("\nInitializing ..."); } if (gi_288 <= 0) { if (gi_288 == -8) { Comment("\nUnsupported currency pair " + Symbol()); Alert("Unsupported currency pair " + Symbol()); } else { Comment("\nInitialization is failed with error code " + DoubleToStr(gi_288, 0)); Alert("Initialization is failed with error code " + DoubleToStr(gi_288, 0)); } Sleep(10000); return (0); } if (g_period_216 <= 0 || g_period_244 <= 0 || g_period_268 <= 0 || g_period_276 <= 0) { Comment("\nWrong initialization parameters for pair " + Symbol()); Alert("Wrong initialization parameters for pair " + Symbol()); Sleep(10000); return (0); } HideTestIndicators(TRUE); double l_iclose_80 = iClose(NULL, PERIOD_M15, 1); double l_ima_88 = iMA(NULL, PERIOD_M15, g_period_216, 0, MODE_SMMA, PRICE_CLOSE, 1); double l_iwpr_96 = iWPR(NULL, PERIOD_M15, g_period_244, 1); double l_iatr_104 = iATR(NULL, PERIOD_M15, g_period_268, 1); double l_icci_112 = iCCI(NULL, PERIOD_M15, g_period_276, PRICE_TYPICAL, 1); HideTestIndicators(FALSE); double ld_120 = 0; if (StringSubstr(AccountCurrency(), 0, 3) == "JPY") { ld_120 = MarketInfo("USDJPY" + StringSubstr(Symbol(), 6), MODE_BID); if (ld_120 > 0.1) ld_72 = ld_120; else ld_72 = 84; } if (StringSubstr(AccountCurrency(), 0, 3) == "GBP") { ld_120 = MarketInfo("GBPUSD" + StringSubstr(Symbol(), 6), MODE_BID); if (ld_120 > 0.1) ld_72 = 1 / ld_120; else ld_72 = 0.6211180124; } if (StringSubstr(AccountCurrency(), 0, 3) == "EUR") { ld_120 = MarketInfo("EURUSD" + StringSubstr(Symbol(), 6), MODE_BID); if (ld_120 > 0.1) ld_72 = 1 / ld_120; else ld_72 = 0.7042253521; } if (AutoMM > 0.0 && (!RecoveryMode)) l_lots_40 = MathMax(g_minlot_304, MathMin(g_maxlot_312, MathCeil(MathMin(AutoMM_Max, AutoMM) / ld_72 / 100.0 * AccountFreeMargin() / g_lotstep_320 / (g_lotsize_328 / 100)) * g_lotstep_320)); if (AutoMM > 0.0 && RecoveryMode) l_lots_40 = CalcLots(); if (AutoMM == 0.0) l_lots_40 = FixedLots; ls_0 = ls_0 + "\n " + "\n " + "\n Authorization - OK!" + "\n -----------------------------------------------" + "\n SL = " + StopLoss + " pips / TP = " + TakeProfit + " pips" + "\n Spread = " + DoubleToStr((Ask - Bid) / gd_340, 1) + " pips"; if (Ask - Bid > MaxSpread * gd_340) ls_0 = ls_0 + " - TOO HIGH"; else ls_0 = ls_0 + " - NORMAL"; ls_0 = ls_0 + "\n -----------------------------------------------"; if (AutoMM > 0.0) { ls_0 = ls_0 + "\n AutoMM - ENABLED" + "\n Risk = " + DoubleToStr(AutoMM, 1) + "%"; } ls_0 = ls_0 + "\n Trading Lots = " + DoubleToStr(l_lots_40, 2); ls_0 = ls_0 + "\n -----------------------------------------------"; if (RecoveryMode) { ls_0 = ls_0 + "\n Recovery Mode - ENABLED"; } else { ls_0 = ls_0 + "\n Recovery Mode - DISABLED"; } if (StealthMode) { ls_0 = ls_0 + "\n Stealth Mode - ENABLED"; } else { ls_0 = ls_0 + "\n Stealth Mode - DISABLED"; } ls_0 = ls_0 + "\n -----------------------------------------------"; Comment(ls_0); if (ObjectFind("BKGR") < 0) { ObjectCreate("BKGR", OBJ_LABEL, 0, 0, 0); ObjectSetText("BKGR", "g", 110, "Webdings", LightSlateGray); ObjectSet("BKGR", OBJPROP_CORNER, 0); ObjectSet("BKGR", OBJPROP_BACK, TRUE); ObjectSet("BKGR", OBJPROP_XDISTANCE, 5); ObjectSet("BKGR", OBJPROP_YDISTANCE, 15); } if (ObjectFind("BKGR2") < 0) { ObjectCreate("BKGR2", OBJ_LABEL, 0, 0, 0); ObjectSetText("BKGR2", "g", 110, "Webdings", DimGray); ObjectSet("BKGR2", OBJPROP_BACK, TRUE); ObjectSet("BKGR2", OBJPROP_XDISTANCE, 5); ObjectSet("BKGR2", OBJPROP_YDISTANCE, 60); } if (ObjectFind("BKGR3") < 0) { ObjectCreate("BKGR3", OBJ_LABEL, 0, 0, 0); ObjectSetText("BKGR3", "g", 110, "Webdings", DimGray); ObjectSet("BKGR3", OBJPROP_CORNER, 0); ObjectSet("BKGR3", OBJPROP_BACK, TRUE); ObjectSet("BKGR3", OBJPROP_XDISTANCE, 5); ObjectSet("BKGR3", OBJPROP_YDISTANCE, 45); } if (ObjectFind("LV") < 0) { ObjectCreate("LV", OBJ_LABEL, 0, 0, 0); ObjectSetText("LV", "WALL STREET ROBOT", 9, "Tahoma Bold", White); ObjectSet("LV", OBJPROP_CORNER, 0); ObjectSet("LV", OBJPROP_BACK, FALSE); ObjectSet("LV", OBJPROP_XDISTANCE, 13); ObjectSet("LV", OBJPROP_YDISTANCE, 23); } if (ObjectFind("BKGR4") < 0) { ObjectCreate("BKGR4", OBJ_LABEL, 0, 0, 0); ObjectSetText("BKGR4", "g", 110, "Webdings", DimGray); ObjectSet("BKGR4", OBJPROP_CORNER, 0); ObjectSet("BKGR4", OBJPROP_BACK, TRUE); ObjectSet("BKGR4", OBJPROP_XDISTANCE, 5); ObjectSet("BKGR4", OBJPROP_YDISTANCE, 84); } if (TakeProfit < g_stoplevel_300 * Point / gd_340) TakeProfit = g_stoplevel_300 * Point / gd_340; if (StopLoss < g_stoplevel_300 * Point / gd_340) StopLoss = g_stoplevel_300 * Point / gd_340; Slippage = Slippage * gd_340; int l_count_128 = 0; int l_count_132 = 0; int l_count_136 = 0; int l_count_140 = 0; if (CloseOnlyOnProfit) gi_240 = FALSE; for (int l_pos_152 = OrdersTotal() - 1; l_pos_152 >= 0; l_pos_152--) { if (!OrderSelect(l_pos_152, SELECT_BY_POS, MODE_TRADES)) Print("Error in OrderSelect! Position:", l_pos_152); else { if (OrderType() <= OP_SELL && OrderSymbol() == Symbol()) { if (OrderMagicNumber() != Magic) { if (OrderType() == OP_BUY) l_count_136++; else l_count_140++; } if (OrderMagicNumber() == Magic) { ld_64 += OrderProfit(); if (OrderType() == OP_BUY) ld_48 = (Bid - OrderOpenPrice()) / gd_340; else ld_48 = (OrderOpenPrice() - Ask) / gd_340; ld_56 += ld_48; if (OrderType() == OP_BUY) { l_count_128++; if (OrderStopLoss() == 0.0 && StealthMode == FALSE) { l_price_156 = NormalizeDouble(OrderOpenPrice() - StopLoss * gd_340, Digits); l_price_164 = NormalizeDouble(OrderOpenPrice() + TakeProfit * gd_340, Digits); OrderModify(OrderTicket(), OrderOpenPrice(), l_price_156, l_price_164, 0, Green); } else { if (Bid >= OrderOpenPrice() + TakeProfit * gd_340 || Bid <= OrderOpenPrice() - StopLoss * gd_340 || CloseLong(OrderOpenPrice(), l_iwpr_96, l_iclose_80, iOpen(NULL, PERIOD_M1, 1), iClose(NULL, PERIOD_M1, 1))) { for (int li_148 = 1; li_148 <= MathMax(1, gi_96); li_148++) { RefreshRates(); if (OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Bid, Digits), Slippage, Violet)) { l_count_128--; break; } Sleep(MathMax(100, 1000 * gi_100)); } Sleep(5000); } else if (Bid - OrderOpenPrice() > SecureProfitTriger * gd_340 && MathAbs(OrderOpenPrice() + SecureProfit * gd_340 - OrderStopLoss()) >= Point) OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(OrderOpenPrice() + SecureProfit * gd_340, Digits), OrderTakeProfit(), 0, Blue); } } else { l_count_132++; if (OrderStopLoss() == 0.0 && StealthMode == FALSE) { l_price_156 = NormalizeDouble(OrderOpenPrice() + StopLoss * gd_340, Digits); l_price_164 = NormalizeDouble(OrderOpenPrice() - TakeProfit * gd_340, Digits); OrderModify(OrderTicket(), OrderOpenPrice(), l_price_156, l_price_164, 0, Green); } else { if (Ask <= OrderOpenPrice() - TakeProfit * gd_340 || Ask >= OrderOpenPrice() + StopLoss * gd_340 || CloseShort(OrderOpenPrice(), l_iwpr_96, l_iclose_80, iOpen(NULL, PERIOD_M1, 1), iClose(NULL, PERIOD_M1, 1))) { for (li_148 = 1; li_148 <= MathMax(1, gi_96); li_148++) { RefreshRates(); if (OrderClose(OrderTicket(), OrderLots(), NormalizeDouble(Ask, Digits), Slippage, Violet)) { l_count_132--; break; } Sleep(MathMax(100, 1000 * gi_100)); } Sleep(5000); } else if (OrderOpenPrice() - Ask > SecureProfitTriger * gd_340 && MathAbs(OrderOpenPrice() - SecureProfit * gd_340 - OrderStopLoss()) >= Point) OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(OrderOpenPrice() - SecureProfit * gd_340, Digits), OrderTakeProfit(), 0, Red); } } } } } } ls_0 = ls_0 + "\n Account Ballance = " + DoubleToStr(AccountBalance(), 2); if (l_count_128 == 0 && l_count_132 == 0) { ls_0 = ls_0 + "\n No active trades" + "\n"; } else { ls_0 = ls_0 + "\n Current trade " + DoubleToStr(ld_56, 1) + "\n Account Profit = " + DoubleToStr(ld_64, 2); } Comment(ls_0); bool li_172 = TRUE; bool li_176 = TRUE; if (NFA == TRUE && l_count_132 > 0 || l_count_128 > 0) { li_172 = FALSE; li_176 = FALSE; } if (NFA == TRUE && l_count_140 > 0 || l_count_136 > 0) { li_172 = FALSE; li_176 = FALSE; } if (No_Hedge == TRUE && l_count_132 > 0 || l_count_140 > 0) li_172 = FALSE; if (No_Hedge == TRUE && l_count_128 > 0 || l_count_136 > 0) li_176 = FALSE; if (!gi_108) gi_272 = 1000; else gi_272 = gi_272; if (l_iatr_104 <= gi_264 * gd_340) return (0); int l_cmd_36 = -1; if (l_count_128 < 1 && OpenLong(l_iclose_80, l_ima_88, l_iwpr_96, l_icci_112)) { if (Ask - Bid > MaxSpread * gd_340) { Print("BUY not taken!!! - High spead..."); Sleep(1000); } else { if (!li_172) { Print("BUY not taken!!! - No Hedge, or FIFO restriction ..."); Sleep(1000); } else { ls_180 = "BUY"; l_cmd_36 = 0; l_color_32 = Aqua; RefreshRates(); l_price_8 = NormalizeDouble(Ask, Digits); ld_16 = l_price_8 - StopLoss * gd_340; ld_24 = l_price_8 + TakeProfit * gd_340; } } } if (l_count_132 < 1 && OpenShort(l_iclose_80, l_ima_88, l_iwpr_96, l_icci_112)) { if (Ask - Bid > MaxSpread * gd_340) { Print("SELL not taken!!! - High spead..."); Sleep(1000); } else { if (!li_176) { Print("SELL not taken!!! - No Hedge, or FIFO restriction ..."); Sleep(1000); } else { ls_180 = "SELL"; l_cmd_36 = 1; l_color_32 = Red; RefreshRates(); l_price_8 = NormalizeDouble(Bid, Digits); ld_16 = l_price_8 + StopLoss * gd_340; ld_24 = l_price_8 - TakeProfit * gd_340; } } } if (l_cmd_36 >= OP_BUY && CheckLossPause()) { for (li_148 = 1; li_148 <= MathMax(1, gi_96); li_148++) { l_ticket_144 = OrderSend(Symbol(), l_cmd_36, l_lots_40, l_price_8, Slippage, 0, 0, EA_Comment, Magic, 0, l_color_32); if (l_ticket_144 >= 0) break; Sleep(MathMax(100, 1000 * gi_100)); RefreshRates(); if (l_cmd_36 == OP_BUY) l_price_8 = NormalizeDouble(Ask, Digits); else if (l_cmd_36 == OP_SELL) l_price_8 = NormalizeDouble(Bid, Digits); } Sleep(5000); if (l_ticket_144 > 0) { if (OrderSelect(l_ticket_144, SELECT_BY_TICKET, MODE_TRADES)) Print("Order " + ls_180 + " opened!: ", OrderOpenPrice()); } else Print("Error opening " + ls_180 + " order!: ", GetLastError()); } return (0); } double CalcLots() { double ld_16; int l_count_24; double ld_28; int li_36; double ld_40; int li_48; double ld_52; int li_60; double ld_8 = 1; if (gd_208 > 0.0 && AutoMM > 0.0) { ld_16 = 0; l_count_24 = 0; ld_28 = 0; li_36 = 0; ld_40 = 0; li_48 = 0; for (int l_pos_64 = OrdersHistoryTotal() - 1; l_pos_64 >= 0; l_pos_64--) { if (OrderSelect(l_pos_64, SELECT_BY_POS, MODE_HISTORY)) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) { l_count_24++; ld_16 += OrderProfit(); if (ld_16 > ld_40) { ld_40 = ld_16; li_48 = l_count_24; } if (ld_16 < ld_28) { ld_28 = ld_16; li_36 = l_count_24; } if (l_count_24 >= gi_196) break; } } } if (li_48 <= li_36) ld_8 = MathPow(gd_208, li_36); else { ld_16 = ld_40; l_count_24 = li_48; ld_52 = ld_40; li_60 = li_48; for (l_pos_64 = OrdersHistoryTotal() - li_48 - 1; l_pos_64 >= 0; l_pos_64--) { if (OrderSelect(l_pos_64, SELECT_BY_POS, MODE_HISTORY)) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) { if (l_count_24 >= gi_196) break; l_count_24++; ld_16 += OrderProfit(); if (ld_16 < ld_52) { ld_52 = ld_16; li_60 = l_count_24; } } } } if (li_60 == li_48 || ld_52 == ld_40) ld_8 = MathPow(gd_208, li_36); else { if (MathAbs(ld_28 - ld_40) / MathAbs(ld_52 - ld_40) >= (gd_200 + 100.0) / 100.0) ld_8 = MathPow(gd_208, li_36); else ld_8 = MathPow(gd_208, li_60); } } } for (double ld_ret_0 = MathMax(g_minlot_304, MathMin(g_maxlot_312, MathCeil(MathMin(AutoMM_Max, ld_8 * AutoMM) / 100.0 * AccountFreeMargin() / g_lotstep_320 / (g_lotsize_328 / 100)) * g_lotstep_320)); ld_ret_0 >= 2.0 * g_minlot_304 && 1.05 * (ld_ret_0 * g_marginrequired_332) >= AccountFreeMargin(); ld_ret_0 -= g_minlot_304) { } return (ld_ret_0); } int CheckLossPause() { int l_datetime_4; bool li_ret_0 = TRUE; if (gi_280 > 0 && gi_284 > 0) { l_datetime_4 = 0; for (int l_pos_8 = OrdersHistoryTotal() - 1; l_pos_8 >= 0; l_pos_8--) { if (OrderSelect(l_pos_8, SELECT_BY_POS, MODE_HISTORY)) { if (OrderSymbol() == Symbol() && OrderMagicNumber() == Magic) { if (!((OrderType() == OP_BUY && (OrderClosePrice() - OrderOpenPrice()) / gd_340 <= (-gi_280)) || (OrderType() == OP_SELL && (OrderOpenPrice() - OrderClosePrice()) / gd_340 <= (-gi_280)))) break; l_datetime_4 = OrderCloseTime(); break; } } } if (TimeCurrent() - l_datetime_4 < 3600 * gi_284) li_ret_0 = FALSE; } return (li_ret_0); } int MyFirstInit() { int li_ret_0; if (UseCustomPair) li_ret_0 = SessionInit(AccountNumber(), IsTesting(), IsDemo(), WindowHandle(Symbol(), Period()), StringSubstr(UseSettingsFrom, 0, 6)); else li_ret_0 = SessionInit(AccountNumber(), IsTesting(), IsDemo(), WindowHandle(Symbol(), Period()), StringSubstr(Symbol(), 0, 6)); if (li_ret_0 >= 0) { g_period_216 = ParamValue(li_ret_0, 1); gi_220 = ParamValue(li_ret_0, 2); gi_224 = ParamValue(li_ret_0, 3); gi_228 = ParamValue(li_ret_0, 4); gi_232 = ParamValue(li_ret_0, 5); gi_236 = ParamValue(li_ret_0, 6); gi_240 = ParamValue(li_ret_0, 7); g_period_244 = ParamValue(li_ret_0, 8); gi_248 = ParamValue(li_ret_0, 9); if (SecureProfit <= 0) SecureProfit = ParamValue(li_ret_0, 10); if (SecureProfitTriger <= 0) SecureProfitTriger = ParamValue(li_ret_0, 11); gi_252 = ParamValue(li_ret_0, 12); gi_256 = ParamValue(li_ret_0, 13); gi_260 = ParamValue(li_ret_0, 14); gi_264 = ParamValue(li_ret_0, 15); g_period_268 = ParamValue(li_ret_0, 16); gi_272 = ParamValue(li_ret_0, 17); g_period_276 = ParamValue(li_ret_0, 18); gi_280 = ParamValue(li_ret_0, 19); gi_284 = ParamValue(li_ret_0, 20); if (StopLoss <= 0) StopLoss = ParamValue(li_ret_0, 21); if (TakeProfit <= 0) TakeProfit = ParamValue(li_ret_0, 22); } return (li_ret_0); } int MyDeinit() { int li_ret_0; if (UseCustomPair) li_ret_0 = SessionDeinit(AccountNumber(), IsTesting(), IsDemo(), WindowHandle(Symbol(), Period()), StringSubstr(UseSettingsFrom, 0, 6)); else li_ret_0 = SessionDeinit(AccountNumber(), IsTesting(), IsDemo(), WindowHandle(Symbol(), Period()), StringSubstr(Symbol(), 0, 6)); return (li_ret_0); } int CloseLong(double ad_0, double ad_8, double ad_16, double ad_24, double ad_32) { bool li_40 = FALSE; li_40 = CheckCloseLong(gi_288, ad_0, ad_8, ad_16, ad_24, ad_32, gi_240, Bid, Ask, gd_340); return (li_40); } int CloseShort(double ad_0, double ad_8, double ad_16, double ad_24, double ad_32) { bool li_40 = FALSE; li_40 = CheckCloseShort(gi_288, ad_0, ad_8, ad_16, ad_24, ad_32, gi_240, Bid, Ask, gd_340); return (li_40); } int OpenLong(double ad_0, double ad_8, double ad_16, double ad_24) { bool li_32 = FALSE; li_32 = CheckOpenLong(gi_288, ad_0, ad_8, ad_16, ad_24, gi_272, Bid, Ask, gd_340); return (li_32); } int OpenShort(double ad_0, double ad_8, double ad_16, double ad_24) { bool li_32 = FALSE; li_32 = CheckOpenShort(gi_288, ad_0, ad_8, ad_16, ad_24, gi_272, Bid, Ask, gd_340); return (li_32); } //------------------------------------------------------------------ //+------------shadow------------------------------------------------------+ void Message(string m) { Comment(m); if (StringLen(m)>0) Print(m); } //+------------------------------------------------------------------+ //| Выполняет поиск элемента массива по значению и возвращает индекс | //| найденного элемента или -1. | //| Параметры: | //| m - массив элементов | //| e - значение элемента | //+------------------------------------------------------------------+ int ArraySearch(int& m[], int e) { int i, r=ArraySize(m); for (i=0; i