#property copyright "Forex Invest Group & Yuriy Tokman" #property link "info@forexinvest.ee , yuriytokman@gmail.com" #include extern string _____0_____ = "Настройки точек входа"; extern int TimeFrame = 0; extern int shift_open = 0; extern int period = 12; extern int applied_price = 0; extern int level_adx = 10; extern string ____1___ = "Настройки ордеров"; extern int Displacement = 0; extern int steps = 20; extern bool Line = FALSE; extern int quantity = 5; extern string ____2___ = "Торговые настройки"; extern double Lots = 0.1; extern bool Choice_method = TRUE; extern double Risk = 0.0; extern int StopLoss = 0; extern int TakeProfit = 18; extern int MagicNumber = 28081975; extern int Slippage = 30; extern int NumberOfTry = 5; extern bool MarketWatch = FALSE; extern bool UseSound = TRUE; extern string NameFileSound = "expert.wav"; extern color clOpenBuy = LightBlue; extern color clOpenSell = LightCoral; extern color clDelete = Honeydew; extern color clCloseBuy = Aqua; extern color clCloseSell = Tomato; extern string NameCloseSound = "ok.wav"; extern string _____Трал_______ = "______Настройки трала __________________"; extern bool Traling = TRUE; extern bool TSProfitOnly = TRUE; extern int TStop.Buy = 35; extern int TStop.Sell = 40; extern int TrailingStep = 20; extern string _____Averag_____ = "______Настройки ордеров усреднения_____"; extern bool AVERAGES = TRUE; extern int Averag = 25; extern double koef_averag = 1.0; extern int alfa_lot = 1; extern double koef_lot = 2.0; extern double StopLoss_Av = 0.0; extern int TakeProfit_Av = 10; extern string _____Lock_____ = "______Настройки ордеров Locka_____"; extern bool Lock = TRUE; extern int lock_pips = 10; extern double koef_lot_lock = 2.0; extern int MN_Lock = 333; extern int StopLoss_Lock = 0; string gs_328 = ""; bool gi_336 = FALSE; bool gi_340 = FALSE; int gi_344 = 1; extern bool ShowComment = FALSE; int g_time_352 = 0; int init() { gi_340 = FALSE; if (!IsTradeAllowed()) { Message("Для нормальной работы советника необходимо\n" + "Разрешить советнику торговать"); gi_340 = TRUE; return; } if (!IsLibrariesAllowed()) { Message("Для нормальной работы советника необходимо\n" + "Разрешить импорт из внешних экспертов"); gi_340 = TRUE; return; } if (!IsTesting()) { if (IsExpertEnabled()) Message("Советник будет запущен следующим тиком"); else Message("Отжата кнопка \"Разрешить запуск советников\""); } GetLogoType(); GetAvtor(); return (0); } int deinit() { if (!IsTesting()) Comment(""); GetDellName(); return (0); } int start() { string ls_8; double ld_72; double ld_80; double ld_128; double ld_140; double ld_152; double ld_164; double l_lots_0 = 0; if (Lots > 0.0) l_lots_0 = Lots; else l_lots_0 = GetLot(); if (gi_336) { Message("Критическая ошибка! Советник ОСТАНОВЛЕН!"); return; } if (gi_340) { Message("Не удалось инициализировать советник!"); return; } if (!IsTesting() && !IsDemo()) { if (gi_344 > 0 && gi_344 != AccountNumber()) { Comment("Торговля на счёте: " + AccountNumber() + " ЗАПРЕЩЕНА!"); return; } Comment(""); } if (ShowComment) { ls_8 = "CurTime=" + TimeToStr(TimeCurrent(), TIME_MINUTES) + " Кол.ордеров=" + DoubleToStr(quantity * 2, 0) + " Растоян. между ордерами=" + steps + " TakeProfit=" + TakeProfit + " StopLoss=" + StopLoss + " Lots=" + DoubleToStr(l_lots_0, 2) + " Смещение=" + Displacement + "\n+------------------------------+" + "\n Баланс=" + DoubleToStr(AccountBalance(), 2) + "\n Эквити=" + DoubleToStr(AccountEquity(), 2) + "\n Прибыль=" + DoubleToStr(AccountEquity() - AccountBalance(), 3) + " $" + "\n Прибыль=" + DoubleToStr(100.0 * (AccountEquity() / AccountBalance() - 1.0), 3) + " %" + "\n+------------------------------+"; Comment(ls_8); } else Comment(""); if (Traling && !ExistPositions(Symbol(), OP_BUY, MN_Lock)) SimpleTrailing(Symbol(), OP_BUY, MagicNumber); if (Traling && !ExistPositions(Symbol(), OP_SELL, MN_Lock)) SimpleTrailing(Symbol(), OP_SELL, MagicNumber); double ld_16 = MarketInfo(Symbol(), MODE_STOPLEVEL) * Point; int l_digits_24 = Digits; double ld_28 = 100; if (l_digits_24 == 3 || l_digits_24 >= 5) ld_28 = 1000; int li_36 = 1000.0 * Lots * TakeProfit_Av / ld_28; double ld_40 = 0; double ld_48 = 0; double ld_unused_56 = 0; int li_64 = NumberOfPositions(Symbol(), OP_BUY, MN_Lock); int li_68 = NumberOfPositions(Symbol(), OP_SELL, MN_Lock); if (GetProfitOpenPosInCurrency(Symbol(), OP_BUY, MagicNumber) + GetProfitOpenPosInCurrency(Symbol(), OP_SELL, MN_Lock) > li_36 && ExistPositions(Symbol(), OP_SELL, MN_Lock)) { ClosePosFirstProfit(Symbol(), OP_BUY, MagicNumber); ClosePosFirstProfit(Symbol(), OP_SELL, MN_Lock); } if (GetProfitOpenPosInCurrency(Symbol(), OP_SELL, MagicNumber) + GetProfitOpenPosInCurrency(Symbol(), OP_BUY, MN_Lock) > li_36 && ExistPositions(Symbol(), OP_BUY, MN_Lock)) { ClosePosFirstProfit(Symbol(), OP_SELL, MagicNumber); ClosePosFirstProfit(Symbol(), OP_BUY, MN_Lock); } if (AVERAGES && NevBar()) { if (PriceOpenLastPos(Symbol(), OP_BUY, MN_Lock) - Ask > Averag * GetPoint() * li_64 * koef_averag && GetProfitOpenPosInCurrency(Symbol(), OP_BUY, MN_Lock) < 0.0 && GetSignal() == 1) { ld_40 = NormalizeDouble(GetLotLastPos(0, OP_BUY, MN_Lock) * koef_lot, alfa_lot); if (StopLoss_Av > 0.0) ld_48 = Bid - StopLoss_Av * GetPoint(); else ld_48 = 0; OpenPosition(Symbol(), OP_BUY, ld_40, ld_48, 0, MN_Lock); } if (Bid - PriceOpenLastPos(Symbol(), OP_SELL, MN_Lock) > Averag * GetPoint() * li_68 * koef_averag && GetProfitOpenPosInCurrency(Symbol(), OP_SELL, MN_Lock) < 0.0 && GetSignal() == -1) { ld_40 = NormalizeDouble(GetLotLastPos(0, OP_SELL, MN_Lock) * koef_lot, alfa_lot); if (StopLoss_Av > 0.0) ld_48 = Ask + StopLoss_Av * GetPoint(); else ld_48 = 0; OpenPosition(Symbol(), OP_SELL, ld_40, ld_48, 0, MN_Lock); } } if (Lock) { if (PriceOpenLastPos(Symbol(), OP_BUY, MagicNumber) - Ask > lock_pips * GetPoint() && !ExistPositions(Symbol(), OP_SELL, MN_Lock)) { ld_72 = NormalizeDouble(GetLotLastPos(0, OP_BUY, MagicNumber) * koef_lot_lock, alfa_lot); if (StopLoss_Lock > 0) ld_80 = Ask + StopLoss_Lock * GetPoint(); else ld_80 = 0; OpenPosition(Symbol(), OP_SELL, ld_72, ld_80, 0, MN_Lock); } if (Bid - PriceOpenLastPos(Symbol(), OP_SELL, MagicNumber) > lock_pips * GetPoint() && !ExistPositions(Symbol(), OP_BUY, MN_Lock) && ExistPositions(Symbol(), OP_SELL, MagicNumber)) { ld_72 = NormalizeDouble(GetLotLastPos(0, OP_SELL, MagicNumber) * koef_lot_lock, alfa_lot); if (StopLoss_Lock > 0) ld_80 = Bid - StopLoss_Lock * GetPoint(); else ld_80 = 0; OpenPosition(Symbol(), OP_BUY, ld_72, ld_80, 0, MN_Lock); } } int l_count_88 = 0; double ld_92 = Displacement * GetPoint(); double ld_100 = 0; while (ld_92 < Bid) { ld_92 += steps * GetPoint(); l_count_88++; } ld_100 = ld_92 - steps * GetPoint(); if (Line) { SetHLine(Lime, "r", ld_92); SetHLine(Red, "s", ld_100); } double ld_108 = 0; double ld_116 = 0; if (!ExistPositions(Symbol(), OP_BUY, MagicNumber) && ObjectFind("label") > -1) { for (int l_count_124 = 0; l_count_124 < quantity; l_count_124++) { ld_128 = ld_92 + l_count_124 * steps * GetPoint(); if (!ExistOrdersByPrice(Symbol(), OP_BUYSTOP, MagicNumber, ld_128) && !ExistPosByPrice(Symbol(), OP_BUY, MagicNumber, ld_128) && ld_128 - Ask > ld_16) { if (StopLoss > 0) ld_108 = ld_128 - StopLoss * GetPoint(); else ld_108 = 0; if (TakeProfit > 0) ld_116 = ld_128 + TakeProfit * GetPoint(); else ld_116 = 0; SetOrder(Symbol(), OP_BUYSTOP, l_lots_0, ld_128, ld_108, ld_116, MagicNumber); } } for (int l_count_136 = 0; l_count_136 <= 10; l_count_136++) { ld_140 = ld_92 + (l_count_136 + quantity) * steps * GetPoint(); if (ExistOrdersByPrice(Symbol(), OP_BUYSTOP, MagicNumber, ld_140)) CloseOrderBySelect(); } } if (!ExistPositions(Symbol(), OP_SELL, MagicNumber) && ObjectFind("label") > -1) { for (int l_count_148 = 0; l_count_148 < quantity; l_count_148++) { ld_152 = ld_100 - l_count_148 * steps * GetPoint(); if (!ExistOrdersByPrice(Symbol(), OP_SELLSTOP, MagicNumber, ld_152) && !ExistPosByPrice(Symbol(), OP_SELL, MagicNumber, ld_152) && Bid - ld_152 > ld_16) { if (StopLoss > 0) ld_108 = ld_152 + StopLoss * GetPoint(); else ld_108 = 0; if (TakeProfit > 0) ld_116 = ld_152 - TakeProfit * GetPoint(); else ld_116 = 0; SetOrder(Symbol(), OP_SELLSTOP, l_lots_0, ld_152, ld_108, ld_116, MagicNumber); } } for (int l_count_160 = 0; l_count_160 <= 10; l_count_160++) { ld_164 = ld_100 - (l_count_160 + quantity) * steps * GetPoint(); if (ExistOrdersByPrice(Symbol(), OP_SELLSTOP, MagicNumber, ld_164)) CloseOrderBySelect(); } } return (0); } void SetHLine(color a_color_0, string a_dbl2str_4 = "", double a_bid_12 = 0.0, int a_style_20 = 0, int a_width_24 = 1) { if (a_dbl2str_4 == "") a_dbl2str_4 = DoubleToStr(Time[0], 0); if (a_bid_12 <= 0.0) a_bid_12 = Bid; if (ObjectFind(a_dbl2str_4) < 0) ObjectCreate(a_dbl2str_4, OBJ_HLINE, 0, 0, 0); ObjectSet(a_dbl2str_4, OBJPROP_PRICE1, a_bid_12); ObjectSet(a_dbl2str_4, OBJPROP_COLOR, a_color_0); ObjectSet(a_dbl2str_4, OBJPROP_STYLE, a_style_20); ObjectSet(a_dbl2str_4, OBJPROP_WIDTH, a_width_24); } bool ExistOrdersByPrice(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1, double ad_16 = -1.0) { int l_digits_24; int l_ord_total_32 = OrdersTotal(); if (as_0 == "0") as_0 = Symbol(); for (int l_pos_28 = 0; l_pos_28 < l_ord_total_32; l_pos_28++) { if (OrderSelect(l_pos_28, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == as_0 || as_0 == "" && a_cmd_8 < OP_BUY || OrderType() == a_cmd_8) { if (OrderType() > OP_SELL && OrderType() < 6) { l_digits_24 = MarketInfo(OrderSymbol(), MODE_DIGITS); ad_16 = NormalizeDouble(ad_16, l_digits_24); if (ad_16 < 0.0 || ad_16 == NormalizeDouble(OrderOpenPrice(), l_digits_24)) if (a_magic_12 < 0 || OrderMagicNumber() == a_magic_12) return (TRUE); } } } } return (FALSE); } bool ExistPosByPrice(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1, double ad_16 = 0.0) { double ld_24; double ld_32; int l_digits_40; int l_ord_total_48 = OrdersTotal(); if (as_0 == "0") as_0 = Symbol(); for (int l_pos_44 = 0; l_pos_44 < l_ord_total_48; l_pos_44++) { if (OrderSelect(l_pos_44, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == as_0 || as_0 == "" && a_cmd_8 < OP_BUY || OrderType() == a_cmd_8) { if (OrderType() == OP_BUY || OrderType() == OP_SELL) { if (a_magic_12 < 0 || OrderMagicNumber() == a_magic_12) { l_digits_40 = MarketInfo(OrderSymbol(), MODE_DIGITS); ld_24 = NormalizeDouble(ad_16, l_digits_40); ld_32 = NormalizeDouble(OrderOpenPrice(), l_digits_40); if (ad_16 <= 0.0 || ld_24 == ld_32) return (TRUE); } } } } } return (FALSE); } void SetOrder(string a_symbol_0, int a_cmd_8, double a_lots_12, double a_price_20, double a_price_28 = 0.0, double a_price_36 = 0.0, int a_magic_44 = 0, int a_datetime_48 = 0) { color l_color_52; int l_datetime_56; double l_ask_60; double l_bid_68; double ld_76; int l_error_84; int l_ticket_92; string l_comment_100 = gs_328 + " " + WindowExpertName() + " " + GetNameTF(Period()); if (a_symbol_0 == "" || a_symbol_0 == "0") a_symbol_0 = Symbol(); int l_stoplevel_96 = MarketInfo(a_symbol_0, MODE_STOPLEVEL); if (a_cmd_8 == OP_BUYLIMIT || a_cmd_8 == OP_BUYSTOP) l_color_52 = clOpenBuy; else l_color_52 = clOpenSell; if (a_datetime_48 > 0 && a_datetime_48 < TimeCurrent()) a_datetime_48 = 0; for (int li_88 = 1; li_88 <= NumberOfTry; li_88++) { if (!IsTesting() && !IsExpertEnabled() || IsStopped()) { Print("SetOrder(): Остановка работы функции"); return; } while (!IsTradeAllowed()) Sleep(5000); RefreshRates(); l_datetime_56 = TimeCurrent(); l_ticket_92 = OrderSend(a_symbol_0, a_cmd_8, a_lots_12, a_price_20, Slippage, a_price_28, a_price_36, l_comment_100, a_magic_44, a_datetime_48, l_color_52); if (l_ticket_92 > 0) { if (!(UseSound)) break; PlaySound(NameFileSound); return; } l_error_84 = GetLastError(); if (l_error_84 == 128/* TRADE_TIMEOUT */ || l_error_84 == 142 || l_error_84 == 143) { Sleep(66000); if (ExistOrders(a_symbol_0, a_cmd_8, a_magic_44, l_datetime_56)) { if (!(UseSound)) break; PlaySound(NameFileSound); return; } Print("Error(", l_error_84, ") set order: ", ErrorDescription(l_error_84), ", try ", li_88); } else { ld_76 = GetPoint(); l_ask_60 = MarketInfo(a_symbol_0, MODE_ASK); l_bid_68 = MarketInfo(a_symbol_0, MODE_BID); if (l_error_84 == 130/* INVALID_STOPS */) { switch (a_cmd_8) { case OP_BUYLIMIT: if (a_price_20 > l_ask_60 - l_stoplevel_96 * ld_76) a_price_20 = l_ask_60 - l_stoplevel_96 * ld_76; if (a_price_28 > a_price_20 - (l_stoplevel_96 + 1) * ld_76) a_price_28 = a_price_20 - (l_stoplevel_96 + 1) * ld_76; if (a_price_36 > 0.0 && a_price_36 < a_price_20 + (l_stoplevel_96 + 1) * ld_76) a_price_36 = a_price_20 + (l_stoplevel_96 + 1) * ld_76; break; case OP_BUYSTOP: if (a_price_20 < l_ask_60 + (l_stoplevel_96 + 1) * ld_76) a_price_20 = l_ask_60 + (l_stoplevel_96 + 1) * ld_76; if (a_price_28 > a_price_20 - (l_stoplevel_96 + 1) * ld_76) a_price_28 = a_price_20 - (l_stoplevel_96 + 1) * ld_76; if (a_price_36 > 0.0 && a_price_36 < a_price_20 + (l_stoplevel_96 + 1) * ld_76) a_price_36 = a_price_20 + (l_stoplevel_96 + 1) * ld_76; break; case OP_SELLLIMIT: if (a_price_20 < l_bid_68 + l_stoplevel_96 * ld_76) a_price_20 = l_bid_68 + l_stoplevel_96 * ld_76; if (a_price_28 > 0.0 && a_price_28 < a_price_20 + (l_stoplevel_96 + 1) * ld_76) a_price_28 = a_price_20 + (l_stoplevel_96 + 1) * ld_76; if (a_price_36 > a_price_20 - (l_stoplevel_96 + 1) * ld_76) a_price_36 = a_price_20 - (l_stoplevel_96 + 1) * ld_76; break; case OP_SELLSTOP: if (a_price_20 > l_bid_68 - l_stoplevel_96 * ld_76) a_price_20 = l_bid_68 - l_stoplevel_96 * ld_76; if (a_price_28 > 0.0 && a_price_28 < a_price_20 + (l_stoplevel_96 + 1) * ld_76) a_price_28 = a_price_20 + (l_stoplevel_96 + 1) * ld_76; if (a_price_36 > a_price_20 - (l_stoplevel_96 + 1) * ld_76) a_price_36 = a_price_20 - (l_stoplevel_96 + 1) * ld_76; } Print("SetOrder(): Скорректированы ценовые уровни"); } Print("Error(", l_error_84, ") set order: ", ErrorDescription(l_error_84), ", try ", li_88); Print("Ask=", l_ask_60, " Bid=", l_bid_68, " sy=", a_symbol_0, " ll=", a_lots_12, " op=", GetNameOP(a_cmd_8), " pp=", a_price_20, " sl=", a_price_28, " tp=", a_price_36, " mn=", a_magic_44); if (l_ask_60 == 0.0 && l_bid_68 == 0.0) Message("SetOrder(): Проверьте в обзоре рынка наличие символа " + a_symbol_0); if (l_error_84 == 2/* COMMON_ERROR */ || l_error_84 == 64/* ACCOUNT_DISABLED */ || l_error_84 == 65/* INVALID_ACCOUNT */ || l_error_84 == 133/* TRADE_DISABLED */) { gi_336 = TRUE; return; } if (l_error_84 == 4/* SERVER_BUSY */ || l_error_84 == 131/* INVALID_TRADE_VOLUME */ || l_error_84 == 132/* MARKET_CLOSED */) { Sleep(300000); return; } if (l_error_84 == 8/* TOO_FREQUENT_REQUESTS */ || l_error_84 == 141/* TOO_MANY_REQUESTS */) Sleep(100000); if (l_error_84 == 139/* ORDER_LOCKED */ || l_error_84 == 140/* LONG_POSITIONS_ONLY_ALLOWED */ || l_error_84 == 148/* ERR_TRADE_TOO_MANY_ORDERS */) break; if (l_error_84 == 146/* TRADE_CONTEXT_BUSY */) while (IsTradeContextBusy()) Sleep(11000); if (l_error_84 == 147/* ERR_TRADE_EXPIRATION_DENIED */) a_datetime_48 = 0; else if (l_error_84 != 135/* PRICE_CHANGED */ && l_error_84 != 138/* REQUOTE */) Sleep(7700.0); } } } string GetNameTF(int a_timeframe_0 = 0) { if (a_timeframe_0 == 0) a_timeframe_0 = Period(); switch (a_timeframe_0) { case PERIOD_M1: return ("M1"); case PERIOD_M5: return ("M5"); case PERIOD_M15: return ("M15"); case PERIOD_M30: return ("M30"); case PERIOD_H1: return ("H1"); case PERIOD_H4: return ("H4"); case PERIOD_D1: return ("Daily"); case PERIOD_W1: return ("Weekly"); case PERIOD_MN1: return ("Monthly"); } return ("UnknownPeriod"); } bool ExistOrders(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1, int ai_16 = 0) { int l_cmd_28; int l_ord_total_24 = OrdersTotal(); if (as_0 == "0") as_0 = Symbol(); for (int l_pos_20 = 0; l_pos_20 < l_ord_total_24; l_pos_20++) { if (OrderSelect(l_pos_20, SELECT_BY_POS, MODE_TRADES)) { l_cmd_28 = OrderType(); if (l_cmd_28 > OP_SELL && l_cmd_28 < 6) { if (OrderSymbol() == as_0 || as_0 == "" && a_cmd_8 < OP_BUY || l_cmd_28 == a_cmd_8) { if (a_magic_12 < 0 || OrderMagicNumber() == a_magic_12) if (ai_16 <= OrderOpenTime()) return (TRUE); } } } } return (FALSE); } string GetNameOP(int ai_0) { switch (ai_0) { case 0: return ("Buy"); case 1: return ("Sell"); case 2: return ("Buy Limit"); case 3: return ("Sell Limit"); case 4: return ("Buy Stop"); case 5: return ("Sell Stop"); } return ("Unknown Operation"); } void Message(string as_0) { Comment(as_0); if (StringLen(as_0) > 0) Print(as_0); } void CloseOrderBySelect() { bool l_ord_delete_4; int l_error_8; if (OrderSelect(OrderTicket(), SELECT_BY_TICKET, MODE_TRADES)) { for (int li_0 = 1; li_0 <= NumberOfTry; li_0++) { if (!IsTesting() && !IsExpertEnabled() || IsStopped()) break; while (!IsTradeAllowed()) Sleep(5000); l_ord_delete_4 = OrderDelete(OrderTicket(), clDelete); if (l_ord_delete_4) { if (!(UseSound)) break; PlaySound(NameFileSound); return; } l_error_8 = GetLastError(); Print("Ошибка (", l_error_8, ") при удалении BUYSTOP", ": ", ErrorDescription(l_error_8), ", попытка ", li_0); Sleep(5000); } } } void SimpleTrailing(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1) { double ld_16; double l_price_24; int l_ord_total_36 = OrdersTotal(); if (as_0 == "0") as_0 = Symbol(); for (int l_pos_32 = 0; l_pos_32 < l_ord_total_36; l_pos_32++) { if (OrderSelect(l_pos_32, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == as_0 || as_0 == "" && a_cmd_8 < OP_BUY || OrderType() == a_cmd_8) { ld_16 = GetPoint(); if (a_magic_12 < 0 || OrderMagicNumber() == a_magic_12) { if (OrderType() == OP_BUY) { l_price_24 = MarketInfo(OrderSymbol(), MODE_BID); if (!TSProfitOnly || l_price_24 - OrderOpenPrice() > TStop.Buy * ld_16) if (OrderStopLoss() < l_price_24 - (TStop.Buy + TrailingStep - 1) * ld_16) ModifyOrder(-1, l_price_24 - TStop.Buy * ld_16, -1); } if (OrderType() == OP_SELL) { l_price_24 = MarketInfo(OrderSymbol(), MODE_ASK); if (!TSProfitOnly || OrderOpenPrice() - l_price_24 > TStop.Sell * ld_16) if (OrderStopLoss() > l_price_24 + (TStop.Sell + TrailingStep - 1) * ld_16 || OrderStopLoss() == 0.0) ModifyOrder(-1, l_price_24 + TStop.Sell * ld_16, -1); } } } } } } void ModifyOrder(double a_ord_open_price_0 = -1.0, double a_ord_stoploss_8 = 0.0, double a_ord_takeprofit_16 = 0.0, int a_datetime_24 = 0) { bool l_bool_28; color l_color_32; double l_ask_44; double l_bid_52; int l_error_80; int l_digits_76 = MarketInfo(OrderSymbol(), MODE_DIGITS); if (a_ord_open_price_0 <= 0.0) a_ord_open_price_0 = OrderOpenPrice(); if (a_ord_stoploss_8 < 0.0) a_ord_stoploss_8 = OrderStopLoss(); if (a_ord_takeprofit_16 < 0.0) a_ord_takeprofit_16 = OrderTakeProfit(); a_ord_open_price_0 = NormalizeDouble(a_ord_open_price_0, l_digits_76); a_ord_stoploss_8 = NormalizeDouble(a_ord_stoploss_8, l_digits_76); a_ord_takeprofit_16 = NormalizeDouble(a_ord_takeprofit_16, l_digits_76); double ld_36 = NormalizeDouble(OrderOpenPrice(), l_digits_76); double ld_60 = NormalizeDouble(OrderStopLoss(), l_digits_76); double ld_68 = NormalizeDouble(OrderTakeProfit(), l_digits_76); if (a_ord_open_price_0 != ld_36 || a_ord_stoploss_8 != ld_60 || a_ord_takeprofit_16 != ld_68) { for (int li_84 = 1; li_84 <= NumberOfTry; li_84++) { if (!IsTesting() && !IsExpertEnabled() || IsStopped()) break; while (!IsTradeAllowed()) Sleep(5000); RefreshRates(); l_bool_28 = OrderModify(OrderTicket(), a_ord_open_price_0, a_ord_stoploss_8, a_ord_takeprofit_16, a_datetime_24, l_color_32); if (l_bool_28) { if (!(UseSound)) break; PlaySound(NameFileSound); return; } l_error_80 = GetLastError(); l_ask_44 = MarketInfo(OrderSymbol(), MODE_ASK); l_bid_52 = MarketInfo(OrderSymbol(), MODE_BID); Print("Error(", l_error_80, ") modifying order: ", ErrorDescription(l_error_80), ", try ", li_84); Print("Ask=", l_ask_44, " Bid=", l_bid_52, " sy=", OrderSymbol(), " op=" + GetNameOP(OrderType()), " pp=", a_ord_open_price_0, " sl=", a_ord_stoploss_8, " tp=", a_ord_takeprofit_16); Sleep(10000); } } } double GetProfitOpenPosInCurrency(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1) { double ld_ret_16 = 0; int l_ord_total_28 = OrdersTotal(); if (as_0 == "0") as_0 = Symbol(); for (int l_pos_24 = 0; l_pos_24 < l_ord_total_28; l_pos_24++) { if (OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == as_0 || as_0 == "" && a_cmd_8 < OP_BUY || OrderType() == a_cmd_8) { if (OrderType() == OP_BUY || OrderType() == OP_SELL) if (a_magic_12 < 0 || OrderMagicNumber() == a_magic_12) ld_ret_16 += OrderProfit() + OrderCommission() + OrderSwap(); } } } return (ld_ret_16); } double PriceOpenLastPos(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1) { int l_datetime_16; double l_ord_open_price_20 = 0; int l_ord_total_32 = OrdersTotal(); if (as_0 == "0") as_0 = Symbol(); for (int l_pos_28 = 0; l_pos_28 < l_ord_total_32; l_pos_28++) { if (OrderSelect(l_pos_28, 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 (l_datetime_16 < OrderOpenTime()) { l_datetime_16 = OrderOpenTime(); l_ord_open_price_20 = OrderOpenPrice(); } } } } } } } return (l_ord_open_price_20); } double GetLotLastPos(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1) { int l_datetime_16; double l_ord_lots_20 = -1; int l_ord_total_32 = OrdersTotal(); if (as_0 == "0") as_0 = Symbol(); for (int l_pos_28 = 0; l_pos_28 < l_ord_total_32; l_pos_28++) { if (OrderSelect(l_pos_28, 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 (l_datetime_16 < OrderOpenTime()) { l_datetime_16 = OrderOpenTime(); l_ord_lots_20 = OrderLots(); } } } } } } } return (l_ord_lots_20); } void OpenPosition(string a_symbol_0, int a_cmd_8, double a_lots_12, double a_price_20 = 0.0, double a_price_28 = 0.0, int a_magic_36 = 0) { color l_color_40; int l_datetime_44; double l_price_48; double l_ask_56; double l_bid_64; int l_digits_72; int l_error_76; int l_ticket_84 = 0; string l_comment_88 = gs_328 + " " + WindowExpertName() + " " + GetNameTF(Period()); if (a_symbol_0 == "" || a_symbol_0 == "0") a_symbol_0 = Symbol(); if (a_cmd_8 == OP_BUY) l_color_40 = clOpenBuy; else l_color_40 = clOpenSell; for (int li_80 = 1; li_80 <= NumberOfTry; li_80++) { if (!IsTesting() && !IsExpertEnabled() || IsStopped()) { Print("OpenPosition(): Остановка работы функции"); break; } while (!IsTradeAllowed()) Sleep(5000); RefreshRates(); l_digits_72 = MarketInfo(a_symbol_0, MODE_DIGITS); l_ask_56 = MarketInfo(a_symbol_0, MODE_ASK); l_bid_64 = MarketInfo(a_symbol_0, MODE_BID); if (a_cmd_8 == OP_BUY) l_price_48 = l_ask_56; else l_price_48 = l_bid_64; l_price_48 = NormalizeDouble(l_price_48, l_digits_72); l_datetime_44 = TimeCurrent(); if (MarketWatch) l_ticket_84 = OrderSend(a_symbol_0, a_cmd_8, a_lots_12, l_price_48, Slippage, 0, 0, l_comment_88, a_magic_36, 0, l_color_40); else l_ticket_84 = OrderSend(a_symbol_0, a_cmd_8, a_lots_12, l_price_48, Slippage, a_price_20, a_price_28, l_comment_88, a_magic_36, 0, l_color_40); if (l_ticket_84 > 0) { if (!(UseSound)) break; PlaySound(NameFileSound); break; } l_error_76 = GetLastError(); if (l_ask_56 == 0.0 && l_bid_64 == 0.0) Message("Проверьте в Обзоре рынка наличие символа " + a_symbol_0); Print("Error(", l_error_76, ") opening position: ", ErrorDescription(l_error_76), ", try ", li_80); Print("Ask=", l_ask_56, " Bid=", l_bid_64, " sy=", a_symbol_0, " ll=", a_lots_12, " op=", GetNameOP(a_cmd_8), " pp=", l_price_48, " sl=", a_price_20, " tp=", a_price_28, " mn=", a_magic_36); if (l_error_76 == 2/* COMMON_ERROR */ || l_error_76 == 64/* ACCOUNT_DISABLED */ || l_error_76 == 65/* INVALID_ACCOUNT */ || l_error_76 == 133/* TRADE_DISABLED */) { gi_336 = TRUE; break; } if (l_error_76 == 4/* SERVER_BUSY */ || l_error_76 == 131/* INVALID_TRADE_VOLUME */ || l_error_76 == 132/* MARKET_CLOSED */) { Sleep(300000); break; } if (l_error_76 == 128/* TRADE_TIMEOUT */ || l_error_76 == 142 || l_error_76 == 143) { Sleep(66666.0); if (ExistPositions(a_symbol_0, a_cmd_8, a_magic_36, l_datetime_44)) { if (!(UseSound)) break; PlaySound(NameFileSound); break; } } if (l_error_76 == 140/* LONG_POSITIONS_ONLY_ALLOWED */ || l_error_76 == 148/* ERR_TRADE_TOO_MANY_ORDERS */ || l_error_76 == 4110/* LONGS__NOT_ALLOWED */ || l_error_76 == 4111/* SHORTS_NOT_ALLOWED */) break; if (l_error_76 == 141/* TOO_MANY_REQUESTS */) Sleep(100000); if (l_error_76 == 145/* TRADE_MODIFY_DENIED */) Sleep(17000); if (l_error_76 == 146/* TRADE_CONTEXT_BUSY */) while (IsTradeContextBusy()) Sleep(11000); if (l_error_76 != 135/* PRICE_CHANGED */) Sleep(7700.0); } if (MarketWatch && l_ticket_84 > 0 && a_price_20 > 0.0 || a_price_28 > 0.0) if (OrderSelect(l_ticket_84, SELECT_BY_TICKET)) ModifyOrder(-1, a_price_20, a_price_28); } bool ExistPositions(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1, int ai_16 = 0) { int l_ord_total_24 = OrdersTotal(); if (as_0 == "0") as_0 = Symbol(); for (int l_pos_20 = 0; l_pos_20 < l_ord_total_24; l_pos_20++) { if (OrderSelect(l_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 (TRUE); } } } } } return (FALSE); } int NevBar() { if (g_time_352 == Time[0]) return (0); g_time_352 = Time[0]; return (1); } int NumberOfPositions(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1) { int l_ord_total_20 = OrdersTotal(); int l_count_24 = 0; if (as_0 == "0") as_0 = Symbol(); for (int l_pos_16 = 0; l_pos_16 < l_ord_total_20; l_pos_16++) { if (OrderSelect(l_pos_16, 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) l_count_24++; } } } } return (l_count_24); } void ClosePosFirstProfit(string as_0 = "", int a_cmd_8 = -1, int a_magic_12 = -1) { int l_ord_total_20 = OrdersTotal(); if (as_0 == "0") as_0 = Symbol(); for (int l_pos_16 = l_ord_total_20 - 1; l_pos_16 >= 0; l_pos_16--) { if (OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == as_0 || as_0 == "" && a_cmd_8 < OP_BUY || OrderType() == a_cmd_8) { if (OrderType() == OP_BUY || OrderType() == OP_SELL) { if (a_magic_12 < 0 || OrderMagicNumber() == a_magic_12) if (OrderProfit() + OrderSwap() > 0.0) ClosePosBySelect(); } } } } l_ord_total_20 = OrdersTotal(); for (l_pos_16 = l_ord_total_20 - 1; l_pos_16 >= 0; l_pos_16--) { if (OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == as_0 || as_0 == "" && a_cmd_8 < OP_BUY || OrderType() == a_cmd_8) { if (OrderType() == OP_BUY || OrderType() == OP_SELL) if (a_magic_12 < 0 || OrderMagicNumber() == a_magic_12) ClosePosBySelect(); } } } } void ClosePosBySelect() { bool l_ord_close_0; color l_color_4; double l_ord_lots_8; double ld_16; double ld_24; double l_price_32; int l_error_40; if (OrderType() == OP_BUY || OrderType() == OP_SELL) { for (int li_44 = 1; li_44 <= NumberOfTry; li_44++) { if (!IsTesting() && !IsExpertEnabled() || IsStopped()) break; while (!IsTradeAllowed()) Sleep(5000); RefreshRates(); ld_16 = NormalizeDouble(MarketInfo(OrderSymbol(), MODE_ASK), Digits); ld_24 = NormalizeDouble(MarketInfo(OrderSymbol(), MODE_BID), Digits); if (OrderType() == OP_BUY) { l_price_32 = ld_24; l_color_4 = clCloseBuy; } else { l_price_32 = ld_16; l_color_4 = clCloseSell; } l_ord_lots_8 = OrderLots(); l_ord_close_0 = OrderClose(OrderTicket(), l_ord_lots_8, l_price_32, Slippage, l_color_4); if (l_ord_close_0) { if (!(UseSound)) break; PlaySound(NameCloseSound); return; } l_error_40 = GetLastError(); if (l_error_40 == 146/* TRADE_CONTEXT_BUSY */) while (IsTradeContextBusy()) Sleep(11000); Print("Error(", l_error_40, ") Close ", GetNameOP(OrderType()), " ", ErrorDescription(l_error_40), ", try ", li_44); Print(OrderTicket(), " Ask=", ld_16, " Bid=", ld_24, " pp=", l_price_32); Print("sy=", OrderSymbol(), " ll=", l_ord_lots_8, " sl=", OrderStopLoss(), " tp=", OrderTakeProfit(), " mn=", OrderMagicNumber()); Sleep(5000); } } else Print("Некорректная торговая операция. Close ", GetNameOP(OrderType())); } double GetPoint() { int li_0 = StringFind(Symbol(), "JPY"); if (li_0 == -1) return (0.0001); return (0.01); } void Label(string a_name_0, string a_text_8, int a_corner_16 = 2, int a_x_20 = 3, int a_y_24 = 15, int a_fontsize_28 = 10, string a_fontname_32 = "Arial", color a_color_40 = 3329330) { if (ObjectFind(a_name_0) != -1) ObjectDelete(a_name_0); ObjectCreate(a_name_0, OBJ_LABEL, 0, 0, 0, 0, 0); ObjectSet(a_name_0, OBJPROP_CORNER, a_corner_16); ObjectSet(a_name_0, OBJPROP_XDISTANCE, a_x_20); ObjectSet(a_name_0, OBJPROP_YDISTANCE, a_y_24); ObjectSetText(a_name_0, a_text_8, a_fontsize_28, a_fontname_32, a_color_40); } double GetLot() { double l_free_magrin_0 = 0; if (Choice_method) l_free_magrin_0 = AccountBalance(); else l_free_magrin_0 = AccountFreeMargin(); double l_minlot_8 = MarketInfo(Symbol(), MODE_MINLOT); double l_maxlot_16 = MarketInfo(Symbol(), MODE_MAXLOT); double ld_24 = Risk / 100.0; double ld_ret_32 = MathFloor(l_free_magrin_0 * ld_24 / MarketInfo(Symbol(), MODE_MARGINREQUIRED) / MarketInfo(Symbol(), MODE_LOTSTEP)) * MarketInfo(Symbol(), MODE_LOTSTEP); if (ld_ret_32 < l_minlot_8) ld_ret_32 = l_minlot_8; if (ld_ret_32 > l_maxlot_16) ld_ret_32 = l_maxlot_16; return (ld_ret_32); } void GetAvtor() { string lsa_0[256]; for (int l_index_4 = 0; l_index_4 < 256; l_index_4++) lsa_0[l_index_4] = CharToStr(l_index_4); string ls_8 = lsa_0[70] + lsa_0[97] + lsa_0[99] + lsa_0[116] + lsa_0[111] + lsa_0[114] + lsa_0[121] + lsa_0[32] + lsa_0[111] + lsa_0[102] + lsa_0[32] + lsa_0[116] + lsa_0[104] + lsa_0[101] + lsa_0[32] + lsa_0[97] + lsa_0[100] + lsa_0[118] + lsa_0[105] + lsa_0[115] + lsa_0[101] + lsa_0[114] + lsa_0[115] + lsa_0[58] + lsa_0[32] + lsa_0[121] + lsa_0[117] + lsa_0[114] + lsa_0[105] + lsa_0[121] + lsa_0[116] + lsa_0[111] + lsa_0[107] + lsa_0[109] + lsa_0[97] + lsa_0[110] + lsa_0[64] + lsa_0[103] + lsa_0[109] + lsa_0[97] + lsa_0[105] + lsa_0[108] + lsa_0[46] + lsa_0[99] + lsa_0[111] + lsa_0[109]; Label("label", ls_8, 2, 3, 15, 10); } void GetLogoType() { Label("ytg_logo_1", "Forex", 4, 380, 5, 35, "Times New Roman", Red); Label("ytg_logo_2", "Invest", 4, 488, 25, 35, "Times New Roman", Lime); Label("ytg_logo_3", "GROUP", 4, 420, 50, 11, "Arial Black", Aqua); Label("ytg_logo_4", "И", 4, 373, 45, 26, "Wingdings 3", Red); Label("ytg_logo_5", "З", 4, 585, 9, 26, "Wingdings 3", Lime); for (int l_count_0 = 0; l_count_0 < 36; l_count_0++) Label("ytg_logo_6" + l_count_0, ";", 4, 5 * l_count_0 + 410, 13, 4, "Wingdings", Lime); for (l_count_0 = 0; l_count_0 < 36; l_count_0++) Label("ytg_logo_7" + l_count_0, ";", 4, 5 * l_count_0 + 400, 72, 4, "Wingdings", Red); Label("ytg_logo_8", "www.forexinvest.ee", 4, 450, 77, 8, "Arial", LightCyan); } void GetDellName(string as_0 = "ytg_") { string l_name_8; for (int li_16 = ObjectsTotal() - 1; li_16 >= 0; li_16--) { l_name_8 = ObjectName(li_16); if (StringFind(l_name_8, as_0) != -1) ObjectDelete(l_name_8); } } int GetSignal() { int li_ret_16 = 0; double l_iadx_20 = iADX(Symbol(), TimeFrame, period, applied_price, MODE_PLUSDI, shift_open); double l_iadx_28 = iADX(Symbol(), TimeFrame, period, applied_price, MODE_PLUSDI, shift_open + 1); double l_iadx_36 = iADX(Symbol(), TimeFrame, period, applied_price, MODE_MINUSDI, shift_open); double l_iadx_44 = iADX(Symbol(), TimeFrame, period, applied_price, MODE_MINUSDI, shift_open + 1); if (l_iadx_28 < level_adx && l_iadx_20 > level_adx) li_ret_16 = 1; else if (l_iadx_44 < level_adx && l_iadx_36 > level_adx) li_ret_16 = -1; return (li_ret_16); }