extern string af4 = "BlackBox10"; extern string Bar_Tf = "--------Таймфрейм для бара-------"; extern int TF_Op1 = 30; extern string Block = "-------Параметры -------"; extern double PipStepExponent = 1.0; extern double LotExponent1 = 1.7; extern double LotExponent2 = 2.08; extern int StepX = 5; extern double LotSize = 0.01; extern int PipStep = 10; extern int PipStep2 = 20; extern int TP = 10; extern int MaxTrades = 10; extern string GeneralBlock = "-------Общие параметры-------"; extern bool Ostanov = TRUE; extern double Limit = 50.0; extern int OpenNewTF = 1; extern int OpenNextTF = 1; extern int Povtor = 1; extern bool FixLot = FALSE; extern int LotStep = 2000; extern string a = "работа советника в пятницу до"; extern bool CloseFriday = TRUE; extern int CloseFridayHour = 19; extern string OfficialVariable = "-------Служебные переменые-------"; extern string InformationOnChartString = "InformationOnChart - отключить для тестера (замедляет)"; extern bool InformationOnChart = TRUE; extern int MagicNumber = 12345; extern string af5 = "-===Kazakstan treider==- "; extern int LotDecimal = 0; int g_datetime_248 = 0; int g_datetime_252 = 0; int g_ticket_260; int gi_264; bool gi_268; bool gi_272; double g_lots_276; double g_lots_284; double g_lots_292; double g_lots_300; double g_price_324; string g_comment_332; int gi_340; int init() { LotDecimal = LotDecimal(); return (0); } int deinit() { return (0); } int start() { int l_slippage_16; int li_0 = 1623994; int l_acc_number_4 = AccountNumber(); if (l_acc_number_4 != li_0) { Alert("You can not use this account (" + DoubleToStr(l_acc_number_4, 0) + ") with this program!"); return (0); } double l_iopen_8 = iOpen(Symbol(), TF_Op1, 0); if (l_iopen_8 < Bid) gi_340 = 1; else if (l_iopen_8 > Bid) gi_340 = -1; if (LotDecimal == 0) LotDecimal = LotDecimal(); Information(); gi_268 = TRUE; gi_272 = TRUE; if (Ostanov && CountTrades("buy") > 0 && CountTrades("sell") > 0 && Balance("buy", "Balance") + Balance("sell", "Balance") >= AccountEquity() / Limit) { l_slippage_16 = 3; for (int l_pos_20 = OrdersTotal() - 1; l_pos_20 >= 0; l_pos_20--) { if (!(OrderSelect(l_pos_20, SELECT_BY_POS, MODE_TRADES))) break; if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_BID), l_slippage_16); if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), MarketInfo(OrderSymbol(), MODE_ASK), l_slippage_16); } } if (g_datetime_248 != iTime(NULL, OpenNewTF, 0)) { g_ticket_260 = 0; gi_264 = CountTrades("buy"); if (CloseFriday == TRUE && DayOfWeek() == 5 && TimeCurrent() >= StrToTime(CloseFridayHour + ":00")) return (0); if (gi_340 > 0) { if (iRSI(NULL, PERIOD_H1, 14, PRICE_CLOSE, 0) < 70.0) { if (iCustom(NULL, PERIOD_M5, "Silence2_02", 11, 220, 2, 0) < 80.0) { if (gi_264 == 0 && gi_268 == TRUE) { g_comment_332 = "BlackBox10 " + Symbol() + " - Buy " + ((gi_264 + 1)); g_lots_292 = NewLot("buy"); while (g_ticket_260 < 1) { g_price_324 = Prof("buy"); Print("Покупаем. Новый. Параметры. символ=" + Symbol() + ", лот=" + DoubleToStr(g_lots_292, 2) + ", цена=" + DoubleToStr(Ask, 4) + " профит=" + DoubleToStr(g_price_324, 4) + ", коммент=" + g_comment_332 + " маджик=" + MagicNumber); g_ticket_260 = OrderSend(Symbol(), OP_BUY, g_lots_292, Ask, 3, 0, g_price_324, g_comment_332, MagicNumber, 0, Blue); if (g_ticket_260 < 1) { Print("Ошибка: ", GetLastError(), " Новая попытка покупки через " + (60 * Povtor) + " секунд"); Sleep(1000 * (60 * Povtor)); } RefreshRates(); } } } } } gi_264 = CountTrades("sell"); if (CloseFriday == TRUE && DayOfWeek() == 5 && TimeCurrent() >= StrToTime(CloseFridayHour + ":00")) return (0); if (gi_340 < 0) { if (iRSI(NULL, PERIOD_H1, 14, PRICE_CLOSE, 0) > 30.0) { if (iCustom(NULL, PERIOD_M5, "Silence2_02", 11, 220, 2, 0) < 80.0) { if (gi_264 == 0 && gi_272 == TRUE) { g_comment_332 = "BlackBox10 " + Symbol() + " - Sell " + ((gi_264 + 1)); g_lots_300 = NewLot("sell"); while (g_ticket_260 < 1) { g_price_324 = Prof("sell"); Print("Продаем. Новый. Параметры. символ=" + Symbol() + ", лот=" + DoubleToStr(g_lots_300, 2) + ", цена=" + DoubleToStr(Bid, 4) + " профит=" + DoubleToStr(g_price_324, 4) + ", коммент=" + g_comment_332 + " маджик=" + MagicNumber); g_ticket_260 = OrderSend(Symbol(), OP_SELL, g_lots_300, Bid, 3, 0, g_price_324, g_comment_332, MagicNumber, 0, Red); if (g_ticket_260 < 1) { Print("Ошибка: ", GetLastError(), " Новая попытка покупки через " + (60 * Povtor) + " секунд"); Sleep(1000 * (60 * Povtor)); } RefreshRates(); } } } } } g_datetime_248 = iTime(NULL, OpenNewTF, 0); } if (g_datetime_252 != iTime(NULL, OpenNextTF, 0)) { g_ticket_260 = 0; gi_264 = CountTrades("buy"); if (gi_264 > 0 && NextOrder("buy")) { g_comment_332 = "BlackBox10 " + Symbol() + " - Buy " + ((gi_264 + 1)); g_lots_276 = NextLot("buy"); while (g_ticket_260 < 1) { Print("Покупаем. Следующий. Параметры. символ:" + Symbol() + ", лот=" + DoubleToStr(g_lots_276, 2) + ", цена =" + DoubleToStr(Ask, 4) + ", коммент=" + g_comment_332 + ", маджик=" + MagicNumber); g_ticket_260 = OrderSend(Symbol(), OP_BUY, g_lots_276, Ask, 3, 0, 0, g_comment_332, MagicNumber, 0, Blue); if (g_ticket_260 < 1) { Print("Ошибка: ", GetLastError(), " Новая попытка покупки через " + (60 * Povtor) + " секунд"); Sleep(1000 * (60 * Povtor)); } else Сorrect("buy"); RefreshRates(); } } gi_264 = CountTrades("sell"); if (gi_264 > 0 && NextOrder("sell")) { g_comment_332 = "BlackBox10 " + Symbol() + " - Sell " + ((gi_264 + 1)); g_lots_284 = NextLot("sell"); while (g_ticket_260 < 1) { Print("Продаем. Следующий. Параметры. символ:" + Symbol() + ", лот=" + DoubleToStr(g_lots_284, 2) + ", цена=" + DoubleToStr(Bid, 4) + ", коммент=" + g_comment_332 + ", маджик=" + MagicNumber); g_ticket_260 = OrderSend(Symbol(), OP_SELL, g_lots_284, Bid, 3, 0, 0, g_comment_332, MagicNumber, 0, Red); if (g_ticket_260 < 1) { Print("Ошибка: ", GetLastError(), " Новая попытка продажи через " + (60 * Povtor) + " секунд"); Sleep(1000 * (60 * Povtor)); } else Сorrect("sell"); RefreshRates(); } } g_datetime_252 = iTime(NULL, OpenNextTF, 0); } return (0); } double Prof(string as_0) { double ld_ret_8 = 0; if (TP < MarketInfo(Symbol(), MODE_STOPLEVEL)) TP = MarketInfo(Symbol(), MODE_STOPLEVEL); if (as_0 == "buy") ld_ret_8 = Ask + TP * Point; if (as_0 == "sell") ld_ret_8 = Bid - TP * Point; return (ld_ret_8); } void Сorrect(string as_0) { double l_price_12; double l_price_20 = AveragePrice(as_0); for (int l_pos_8 = OrdersTotal() - 1; l_pos_8 >= 0; l_pos_8--) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (as_0 == "buy") { if (OrderType() == OP_BUY) { l_price_12 = l_price_20 + TP * Point; if (OrderTakeProfit() != l_price_12) { Print("Модифицируем покупку. Безубыток = " + DoubleToStr(l_price_20, 4) + ", ТР = " + DoubleToStr(TP, 4) + " Новый уровень = " + DoubleToStr(l_price_12, 4)); OrderModify(OrderTicket(), l_price_20, OrderStopLoss(), l_price_12, 0, Yellow); } } } if (as_0 == "sell") { if (OrderType() == OP_SELL) { l_price_12 = l_price_20 - TP * Point; if (OrderTakeProfit() != l_price_12) { Print("Модифицируем продажу. Безубыток = " + DoubleToStr(l_price_20, 4) + ", ТР = " + DoubleToStr(TP, 4) + " Новый уровень = " + DoubleToStr(l_price_12, 4)); OrderModify(OrderTicket(), l_price_20, OrderStopLoss(), l_price_12, 0, Yellow); } } } } } } double NewLot(string as_0) { double ld_ret_8; double l_minlot_16 = MarketInfo(Symbol(), MODE_MINLOT); if (as_0 == "buy") { if (FixLot) ld_ret_8 = LotSize; else ld_ret_8 = NormalizeDouble(LotSize * NormalizeDouble(AccountBalance() / LotStep, 0), LotDecimal); } if (as_0 == "sell") { if (FixLot) ld_ret_8 = LotSize; else ld_ret_8 = NormalizeDouble(LotSize * NormalizeDouble(AccountBalance() / LotStep, 0), LotDecimal); } if (ld_ret_8 < l_minlot_16) ld_ret_8 = l_minlot_16; return (ld_ret_8); } double NextLot(string as_0) { double ld_ret_8; int li_16 = CountTrades(as_0); if (as_0 == "buy") { if (li_16 >= StepX) ld_ret_8 = NormalizeDouble(FindLastOrder(as_0, "Lots") * LotExponent2, LotDecimal); else ld_ret_8 = NormalizeDouble(FindLastOrder(as_0, "Lots") * LotExponent1, LotDecimal); } if (as_0 == "sell") { if (li_16 >= StepX) ld_ret_8 = NormalizeDouble(FindLastOrder(as_0, "Lots") * LotExponent2, LotDecimal); else ld_ret_8 = NormalizeDouble(FindLastOrder(as_0, "Lots") * LotExponent1, LotDecimal); } return (ld_ret_8); } int NextOrder(string as_0) { int li_20; double l_ima_8 = iMA(Symbol(), PERIOD_M15, 30, 0, MODE_SMA, PRICE_CLOSE, 0); bool li_ret_16 = FALSE; if (as_0 == "buy" && l_ima_8 < Bid) { if (iCustom(NULL, PERIOD_M15, "Silence2_02", 12, 96, 2, 0) < 80.0) li_20 = NormalizeDouble(PipStep * MathPow(PipStepExponent, CountTrades(as_0)), 0); else li_20 = NormalizeDouble(PipStep2 * MathPow(PipStepExponent, CountTrades(as_0)), 0); if (FindLastOrder(as_0, "Price") - Ask >= li_20 * Point && CountTrades(as_0) < MaxTrades) li_ret_16 = TRUE; } if (as_0 == "sell" && l_ima_8 > Bid) { if (iCustom(NULL, PERIOD_M15, "Silence2_02", 12, 96, 2, 0) < 80.0) li_20 = NormalizeDouble(PipStep * MathPow(PipStepExponent, CountTrades(as_0)), 0); else li_20 = NormalizeDouble(PipStep2 * MathPow(PipStepExponent, CountTrades(as_0)), 0); if (Bid - FindLastOrder(as_0, "Price") >= li_20 * Point && CountTrades(as_0) < MaxTrades) li_ret_16 = TRUE; } return (li_ret_16); } double FindLastOrder(string as_0, string as_8) { double l_ord_open_price_16; double l_ord_lots_24; int l_ticket_36 = 0; for (int l_pos_32 = OrdersTotal() - 1; l_pos_32 >= 0; l_pos_32--) { OrderSelect(l_pos_32, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (as_0 == "buy") { if (OrderType() == OP_BUY) { if (OrderTicket() > l_ticket_36) { l_ord_open_price_16 = OrderOpenPrice(); l_ord_lots_24 = OrderLots(); l_ticket_36 = OrderTicket(); } } } if (as_0 == "sell") { if (OrderType() == OP_SELL) { if (OrderTicket() > l_ticket_36) { l_ord_open_price_16 = OrderOpenPrice(); l_ord_lots_24 = OrderLots(); l_ticket_36 = OrderTicket(); } } } } } if (as_8 == "Price") return (l_ord_open_price_16); if (as_8 == "Lots") return (l_ord_lots_24); return (0.0); } int CountTrades(string as_0) { int l_count_8 = 0; for (int l_pos_12 = OrdersTotal() - 1; l_pos_12 >= 0; l_pos_12--) { OrderSelect(l_pos_12, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (as_0 == "buy") if (OrderType() == OP_BUY) l_count_8++; if (as_0 == "sell") if (OrderType() == OP_SELL) l_count_8++; } } return (l_count_8); } double AveragePrice(string as_0) { double ld_8 = 0; double ld_16 = 0; for (int l_pos_24 = OrdersTotal() - 1; l_pos_24 >= 0; l_pos_24--) { OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (as_0 == "buy") { if (OrderType() == OP_BUY) { ld_8 += OrderOpenPrice() * OrderLots(); ld_16 += OrderLots(); } } if (as_0 == "sell") { if (OrderType() == OP_SELL) { ld_8 += OrderOpenPrice() * OrderLots(); ld_16 += OrderLots(); } } } } ld_8 = NormalizeDouble(ld_8 / ld_16, Digits); return (ld_8); } void Information() { if (InformationOnChart) { Comment("" + " BlackBox10PRO " + Symbol() + "\n" + " ------------------------------------------------" + "\n" + " Broker: " + AccountCompany() + ". AccountLeverage: 1:" + DoubleToStr(AccountLeverage(), 0) + "\n" + " ------------------------------------------------" + "\n" + " Buy open -> " + CountTrades("buy") + " MaxTrades -> " + MaxTrades + "\n" + " Open balance: " + DoubleToStr(Balance("buy", "Balance"), 2) + "\n" + " Open lot: " + DoubleToStr(Balance("buy", "Lot"), 2) + "\n" + " ------------------------------------------------" + "\n" + " Sell open -> " + CountTrades("sell") + " MaxTrades -> " + MaxTrades + "\n" + " Open balance: " + DoubleToStr(Balance("sell", "Balance"), 2) + "\n" + " Open lot: " + DoubleToStr(Balance("sell", "Lot"), 2) + "\n" + " ------------------------------------------------" + "\n" + " Close Lock: " + DoubleToStr(AccountEquity() / Limit, 2) + "\n" + " Balance Buy && Sell: " + DoubleToStr(Balance("buy", "Balance") + Balance("sell", "Balance"), 2)); } } double Balance(string as_0, string as_8) { double ld_ret_16 = 0; for (int l_pos_24 = OrdersTotal() - 1; l_pos_24 >= 0; l_pos_24--) { OrderSelect(l_pos_24, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() != Symbol() || OrderMagicNumber() != MagicNumber) continue; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { if (as_0 == "buy") { if (OrderType() == OP_BUY) { if (as_8 == "Balance") ld_ret_16 = ld_ret_16 + OrderProfit() - OrderSwap() - OrderCommission(); if (as_8 == "Lot") ld_ret_16 += OrderLots(); } } if (as_0 == "sell") { if (OrderType() == OP_SELL) { if (as_8 == "Balance") ld_ret_16 = ld_ret_16 + OrderProfit() - OrderSwap() - OrderCommission(); if (as_8 == "Lot") ld_ret_16 += OrderLots(); } } } } return (ld_ret_16); } double LotDecimal() { double l_lotstep_0 = MarketInfo(Symbol(), MODE_LOTSTEP); int li_ret_8 = MathCeil(MathAbs(MathLog(l_lotstep_0) / MathLog(10))); return (li_ret_8); }