#property copyright "Bonansa Investment Co., Ltd." #property link "http://bonansa.blog47.fc2.com/" #include string gs_unused_76 = "著作権及び禁止止事項"; string gs_unused_84 = "当社の販売している自動売買プログラム(EA)についての著作権は、当社が有しています。"; string gs_unused_92 = "無断で転載・転用・複製等をすることを禁止します。"; string gs_unused_100 = "また当社のEAをリバースエンジニアリング、逆コンパイル、逆アセンブルすることを禁止します。"; string gs_unused_108 = "さらに当社のEAの技術的な制限を回避して使用することを禁止します。"; string gs_unused_116 = "上記の事項に違反した場合、違約金として違反件数に300万円を乗じた金額を当社に支払うものとします。"; extern bool SafetyMode = FALSE; double g_high_128; double g_low_136; bool gi_144 = TRUE; extern int SignalPeriod = 22; extern int HourToStart = 20; extern int TradingHours = 3; extern int MaxPosition = 3; int g_count_164 = 0; extern int TakeProfit = 100; extern int StopLoss = 100; extern int Slippage = 3; extern int OrderSendRetries = 5; extern int maxSpread = 15; bool gi_188 = FALSE; int gi_192 = 10; bool gi_196 = FALSE; extern bool MoneyManagement = FALSE; extern int Risk_percent = 10; extern double minLots = 0.1; extern double maxLots = 1.0; extern bool UseATRStop = FALSE; extern int ATRTimeframe = 30; extern int ATRPeriod = 10; double gd_236; extern double ATRStoplevel = 3.0; string gs_gbpchf_252 = "GBPCHF"; int g_magic_260 = 20081111; string g_comment_264 = "FN-GBPCHF"; int gia_272[100][2] = {15829, 100, 18437, 100, 17537, 100, 201027023, 10, 76089, 10, 99016, 1, 24276, 1, 201105005, 1, 9999999, 1, 201226007, 1, 201114041, 1, 123620, 1, 201104007, 1, 123308, 1, 201229044, 3, 201107016, 1, 201117001, 1, 125600, 1, 128230, 1, 71702, 1, 201215023, 1, 128735, 1, 126070, 1, 127851, 1, 201126006, 1, 210116041, 1, 201009003, 1, 201229010, 1, 201110015, 1, 210107022, 1, 201107006, 1, 155080, 1, 201203009, 1, 210121046, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1, 9999999, 1}; int gi_unused_276 = -1; int gi_unused_280 = -1; int gi_unused_284 = -1; bool gi_unused_288 = FALSE; int gi_292; int gi_296; int g_count_300; double g_price_304; double g_price_312; double g_minlot_320; double g_maxlot_328; double g_lotstep_336; double g_lotsize_344; double gd_352 = 0.0; int gi_360; double gd_364 = 1.0; bool gi_372 = FALSE; bool gi_376 = FALSE; bool gi_380 = FALSE; bool gi_384 = FALSE; bool gi_388 = FALSE; double g_high_392; double g_low_400; double g_high_408 = -1.0; double g_low_416 = -1.0; int gia_424[6] = {-1, -1, -1, -1, -1, -1}; bool gi_428 = FALSE; string g_str_concat_432; string gs_440; bool g_ord_close_448; bool g_bool_452; int g_ticket_456; int g_error_460; int gi_464 = -1; int gi_468 = -1; int gia_472[]; int gia_476[]; double gda_480[]; double gda_484[]; double gda_488[]; double gda_492[]; double gda_496[]; double gda_500[]; double gda_504[]; int gia_508[]; int gia_512[]; string gsa_516[]; int g_bars_520; int init() { HideTestIndicators(TRUE); if (StringSubstr(Symbol(), 0, 6) == gs_gbpchf_252) gs_gbpchf_252 = Symbol(); gs_440 = AccountCurrency(); gi_292 = MarketInfo(gs_gbpchf_252, MODE_STOPLEVEL); gi_296 = MarketInfo(gs_gbpchf_252, MODE_SPREAD); g_minlot_320 = MarketInfo(gs_gbpchf_252, MODE_MINLOT); g_maxlot_328 = MarketInfo(gs_gbpchf_252, MODE_MAXLOT); g_lotstep_336 = MarketInfo(gs_gbpchf_252, MODE_LOTSTEP); g_lotsize_344 = MarketInfo(gs_gbpchf_252, MODE_LOTSIZE); gi_360 = StringLen(StringConcatenate(g_lotstep_336, "")) - 2; if (TradingHours > 6) TradingHours = 6; if (MaxPosition > TradingHours) MaxPosition = TradingHours; for (int l_index_0 = 0; l_index_0 < TradingHours; l_index_0++) { gia_424[l_index_0] = HourToStart + l_index_0; if (gia_424[l_index_0] > 23) gia_424[l_index_0] = gia_424[l_index_0] - 24; } if (Digits == 3 || Digits == 5) gd_364 = 10; gi_192 = MathMin(25, MathMax((gi_292 - gi_296) / gd_364, gi_192)); if (TakeProfit > gi_192) gi_192 = TakeProfit; Risk_percent = MathMin(25, MathMax(1, Risk_percent)); OrderSendRetries = MathMin(25, MathMax(1, OrderSendRetries)); if (gs_440 == "JPY") g_lotsize_344 = 10000000; if (g_minlot_320 < 0.0 || g_maxlot_328 <= 0.0 || g_lotstep_336 <= 0.0) { logError("Init", "invalid MarketInfo() results [" + g_minlot_320 + "," + g_maxlot_328 + "," + g_lotstep_336 + "]"); return (-1); } gi_428 = FALSE; for (l_index_0 = 0; l_index_0 < ArraySize(gia_272) / 2; l_index_0++) { if (AccountNumber() == gia_272[l_index_0][0] || (StrToInteger(AccountName()) == gia_272[l_index_0][0] && StrToInteger(AccountName()) != 0)) { gd_352 = NormalizeDouble(gia_272[l_index_0][1] / g_lotstep_336, 0) * g_lotstep_336; gi_428 = TRUE; break; } } maxLots = NormalizeDouble(MathMin(gd_352, MathMax(g_minlot_320, maxLots)) / g_lotstep_336, 0) * g_lotstep_336; minLots = NormalizeDouble(MathMin(gd_352, MathMax(g_minlot_320, minLots)) / g_lotstep_336, 0) * g_lotstep_336; if (!gi_428) { g_str_concat_432 = StringConcatenate(AccountNumber(), " is not registered."); Comment(g_str_concat_432); Alert(g_str_concat_432); return (-1); } if (CheckExpiration()) return (-1); if (Symbol() != gs_gbpchf_252) { g_str_concat_432 = StringConcatenate("Please attach this EA to ", gs_gbpchf_252, " chart."); Comment(g_str_concat_432); Alert(g_str_concat_432); return (-1); } g_bars_520 = Bars; CheckPosition(); if (SafetyMode == TRUE) TPModify(); return (1); } int deinit() { return (1); } int start() { if (Symbol() != gs_gbpchf_252) return (-1); if (!gi_428) return (-1); if (CheckExpiration()) return (-1); if (g_bars_520 != Bars) init(); HighLowSignal(); if (CheckPosition() == -1) { gi_468 = -1; CheckPosition(); } if (SafetyMode == TRUE && g_high_392 != g_high_408 || g_low_400 != g_low_416) { if (TPModify() != -1) { g_high_408 = g_high_392; g_low_416 = g_low_400; } } int l_hour_0 = Hour(); if (l_hour_0 != gia_424[0] && l_hour_0 != gia_424[1] && l_hour_0 != gia_424[2] && l_hour_0 != gia_424[3] && l_hour_0 != gia_424[4] && l_hour_0 != gia_424[5]) return (-1); if ((DayOfWeek() == 1 && l_hour_0 < 10) || DayOfWeek() < 1) return (-1); if ((DayOfWeek() == 5 && l_hour_0 > 10) || DayOfWeek() > 5) return (-1); if (Ask - Bid > maxSpread * gd_364 * Point) return (-1); PositionCount(); Function_Trade(); return (1); } bool CheckExpiration() { bool li_ret_0 = FALSE; g_str_concat_432 = ""; if (gi_428) { g_str_concat_432 = StringConcatenate(g_str_concat_432, "Registered to ", AccountNumber(), "\nRegistered Max. Lots: ", DoubleToStr(gd_352, gi_360)); } g_str_concat_432 = StringConcatenate(g_str_concat_432, "\nTime to Entry: ", gia_424[0], ":00 - ", gia_424[TradingHours - 1], ":59"); if (SafetyMode) { g_str_concat_432 = StringConcatenate(g_str_concat_432, "\nSafetyMode: on"); } else { g_str_concat_432 = StringConcatenate(g_str_concat_432, "\nSafetyMode: off"); } g_str_concat_432 = StringConcatenate(g_str_concat_432, "\nSignalPeriod: ", SignalPeriod, ", MaxPosition: ", MaxPosition); if (!UseATRStop) { g_str_concat_432 = StringConcatenate(g_str_concat_432, "\nTakeProfit: ", TakeProfit, ", StopLoss: ", StopLoss); } else { gd_236 = MathCeil(iATR(NULL, ATRTimeframe, ATRPeriod, 0) * ATRStoplevel * MathPow(10, Digits)); if (gd_236 < (gi_292 + gi_296) / gd_364) gd_236 = (gi_292 + gi_296) / gd_364; g_str_concat_432 = StringConcatenate(g_str_concat_432, "\nTakeProfit: ", TakeProfit, ", ATRStopLoss: ", gd_236, "\nATRStop setting: ", ATRTimeframe, " - ", ATRPeriod, " - ", ATRStoplevel); } if (!MoneyManagement) { g_str_concat_432 = StringConcatenate(g_str_concat_432, "\nMM: off, FixedLotSize: ", DoubleToStr(LotSize(), gi_360)); } else { g_str_concat_432 = StringConcatenate(g_str_concat_432, "\nMM: on, Risk%: ", Risk_percent, ", MMLotSize: ", DoubleToStr(LotSize(), gi_360), "\nMin. Lots: ", DoubleToStr(minLots, gi_360), ", Max. Lots: ", DoubleToStr(maxLots, gi_360)); } Comment(g_str_concat_432); return (li_ret_0); } int TPModify() { CacheOrders(); if (SafetyMode) { for (int l_index_0 = 0; l_index_0 < gi_464; l_index_0++) { if (gia_476[l_index_0] == 0) { g_count_300 = 0; while (g_count_300 < OrderSendRetries) { RefreshRates(); g_price_304 = NormalizeDouble(g_high_128, Digits); if (g_price_304 < NormalizeDouble(Bid + gi_292 * Point, Digits)) g_price_304 = NormalizeDouble(Bid + gi_292 * Point, Digits); if (g_price_304 >= NormalizeDouble(gda_492[l_index_0], Digits)) break; if (TradeIsBusy() < 0) return (-1); g_bool_452 = OrderModify(gia_472[l_index_0], gda_484[l_index_0], gda_488[l_index_0], g_price_304, 0, Blue); TradeIsNotBusy(); if (g_bool_452) { g_count_300 = OrderSendRetries; gda_492[l_index_0] = g_price_304; } else { g_count_300++; g_error_460 = GetLastError(); logError("CheckPosition", StringConcatenate("failed to modify LONG T/P - attempt #", g_count_300), g_error_460); Sleep(500); } } } else { if (gia_476[l_index_0] == 1) { g_count_300 = 0; while (g_count_300 < OrderSendRetries) { RefreshRates(); g_price_304 = NormalizeDouble(g_low_136 + gi_296 * Point, Digits); if (g_price_304 > NormalizeDouble(Ask - gi_292 * Point, Digits)) g_price_304 = NormalizeDouble(Ask - gi_292 * Point, Digits); if (g_price_304 <= NormalizeDouble(gda_492[l_index_0], Digits)) break; if (TradeIsBusy() < 0) return (-1); g_bool_452 = OrderModify(gia_472[l_index_0], gda_484[l_index_0], gda_488[l_index_0], g_price_304, 0, Blue); TradeIsNotBusy(); if (g_bool_452) { g_count_300 = OrderSendRetries; gda_492[l_index_0] = g_price_304; } else { g_count_300++; g_error_460 = GetLastError(); logError("CheckPosition", StringConcatenate("failed to modify SHORT T/P - attempt #", g_count_300), g_error_460); Sleep(500); } } } } } } return (1); } void HighLowSignal() { gi_372 = FALSE; gi_376 = FALSE; g_high_392 = High[iHighest(NULL, 0, MODE_HIGH, SignalPeriod, 1)]; g_low_400 = Low[iLowest(NULL, 0, MODE_LOW, SignalPeriod, 1)]; if (Bid <= g_low_400) gi_372 = TRUE; if (Bid >= g_high_392) gi_376 = TRUE; g_high_128 = g_high_392; g_low_136 = g_low_400; } void PositionCount() { g_count_164 = 0; gi_380 = FALSE; for (int l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++) { OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == g_magic_260 && OrderSymbol() == Symbol()) g_count_164++; } if (g_count_164 < MaxPosition) gi_380 = TRUE; } int NoPos() { bool li_ret_0 = TRUE; for (int l_index_4 = 0; l_index_4 < gi_464; l_index_4++) { if (Hour() == TimeHour(gia_508[l_index_4])) { li_ret_0 = FALSE; break; } } return (li_ret_0); } int CheckPosition() { CacheOrders(); gi_384 = FALSE; gi_388 = FALSE; if (gi_144 == TRUE) { gi_384 = gi_376; gi_388 = gi_372; } if (!gi_188) { for (int l_index_0 = 0; l_index_0 < gi_464; l_index_0++) { if (gia_476[l_index_0] == 0 && gi_384 == TRUE) { g_count_300 = 0; while (g_count_300 < OrderSendRetries) { RefreshRates(); if (TradeIsBusy() < 0) return (-1); g_ord_close_448 = OrderClose(gia_472[l_index_0], gda_480[l_index_0], Bid, Slippage, White); TradeIsNotBusy(); if (!g_ord_close_448) { g_count_300++; g_error_460 = GetLastError(); logError("CheckPosition", StringConcatenate("failed to close LONG order - attempt #", g_count_300), g_error_460); if (NormalizeDouble(gda_488[l_index_0], Digits) < NormalizeDouble(Ask - gi_292 * Point, Digits)) { RefreshRates(); g_price_312 = NormalizeDouble(Ask - gi_292 * Point, Digits); g_bool_452 = OrderModify(gia_472[l_index_0], gda_484[l_index_0], g_price_312, gda_492[l_index_0], 0, Blue); } if (g_error_460 == 2/* COMMON_ERROR */) return (-1); if (g_error_460 == 4108/* INVALID_TICKET */) { g_count_300 = OrderSendRetries; gi_468 = -1; } else Sleep(500); } else { g_count_300 = OrderSendRetries; gi_468 = -1; } } } else { if (gia_476[l_index_0] == 1 && gi_388 == TRUE) { g_count_300 = 0; while (g_count_300 < OrderSendRetries) { RefreshRates(); if (TradeIsBusy() < 0) return (-1); g_ord_close_448 = OrderClose(gia_472[l_index_0], gda_480[l_index_0], Ask, Slippage, White); TradeIsNotBusy(); if (!g_ord_close_448) { g_count_300++; g_error_460 = GetLastError(); logError("CheckPosition", StringConcatenate("failed to close SHORT order - attempt #", g_count_300), g_error_460); if (NormalizeDouble(gda_488[l_index_0], Digits) > NormalizeDouble(Bid + gi_292 * Point, Digits)) { RefreshRates(); g_price_312 = NormalizeDouble(Bid + gi_292 * Point, Digits); g_bool_452 = OrderModify(gia_472[l_index_0], gda_484[l_index_0], g_price_312, gda_492[l_index_0], 0, Blue); } if (g_error_460 == 2/* COMMON_ERROR */) return (-1); if (g_error_460 == 4108/* INVALID_TICKET */) { g_count_300 = OrderSendRetries; gi_468 = -1; } else Sleep(500); } else { g_count_300 = OrderSendRetries; gi_468 = -1; } } } } } } if (gi_188) { for (int l_index_4 = 0; l_index_4 < gi_464; l_index_4++) { if (gia_476[l_index_4] == 0 && (Bid >= gda_484[l_index_4] + TakeProfit * gd_364 * Point && gda_492[l_index_4] != gda_484[l_index_4] + TakeProfit * gd_364 * Point) || gi_384 == TRUE) { g_count_300 = 0; while (g_count_300 < OrderSendRetries) { RefreshRates(); if (TradeIsBusy() < 0) return (-1); g_ord_close_448 = OrderClose(gia_472[l_index_4], gda_480[l_index_4], Bid, Slippage, White); TradeIsNotBusy(); if (!g_ord_close_448) { g_count_300++; g_error_460 = GetLastError(); logError("CheckPosition", StringConcatenate("failed to close LONG order - attempt #", g_count_300), g_error_460); if (NormalizeDouble(gda_488[l_index_4], Digits) < NormalizeDouble(Ask - gi_292 * Point, Digits)) { RefreshRates(); g_price_312 = NormalizeDouble(Ask - gi_292 * Point, Digits); g_bool_452 = OrderModify(gia_472[l_index_4], gda_484[l_index_4], g_price_312, gda_492[l_index_4], 0, Blue); } if (g_error_460 == 2/* COMMON_ERROR */) return (-1); if (g_error_460 == 4108/* INVALID_TICKET */) { g_count_300 = OrderSendRetries; gi_468 = -1; } else Sleep(500); } else { g_count_300 = OrderSendRetries; gi_468 = -1; } } } else { if (gia_476[l_index_4] == 1 && (Ask <= gda_484[l_index_4] - TakeProfit * gd_364 * Point && gda_492[l_index_4] != gda_484[l_index_4] - TakeProfit * gd_364 * Point) || gi_388 == TRUE) { g_count_300 = 0; while (g_count_300 < OrderSendRetries) { RefreshRates(); if (TradeIsBusy() < 0) return (-1); g_ord_close_448 = OrderClose(gia_472[l_index_4], gda_480[l_index_4], Ask, Slippage, White); TradeIsNotBusy(); if (!g_ord_close_448) { g_count_300++; g_error_460 = GetLastError(); logError("CheckPosition", StringConcatenate("failed to close SHORT order - attempt #", g_count_300), g_error_460); if (NormalizeDouble(gda_488[l_index_4], Digits) > NormalizeDouble(Bid + gi_292 * Point, Digits)) { RefreshRates(); g_price_312 = NormalizeDouble(Bid + gi_292 * Point, Digits); g_bool_452 = OrderModify(gia_472[l_index_4], gda_484[l_index_4], g_price_312, gda_492[l_index_4], 0, Blue); } if (g_error_460 == 2/* COMMON_ERROR */) return (-1); if (g_error_460 == 4108/* INVALID_TICKET */) { g_count_300 = OrderSendRetries; gi_468 = -1; } else Sleep(500); } else { g_count_300 = OrderSendRetries; gi_468 = -1; } } } else { if (gia_476[l_index_4] == 0 && gi_196 && gda_492[l_index_4] > NormalizeDouble(gda_484[l_index_4] + TakeProfit * gd_364 * Point, Digits) && Bid < gda_484[l_index_4]) { g_count_300 = 0; while (g_count_300 < OrderSendRetries) { RefreshRates(); g_price_304 = NormalizeDouble(Ask + gi_192 * gd_364 * Point, Digits); if (g_price_304 < NormalizeDouble(gda_484[l_index_4] + TakeProfit * gd_364 * Point, Digits)) g_price_304 = NormalizeDouble(gda_484[l_index_4] + TakeProfit * gd_364 * Point, Digits); if (g_price_304 >= NormalizeDouble(gda_492[l_index_4], Digits)) break; if (TradeIsBusy() < 0) return (-1); g_bool_452 = OrderModify(gia_472[l_index_4], gda_484[l_index_4], gda_488[l_index_4], g_price_304, 0, Blue); TradeIsNotBusy(); if (g_bool_452) { g_count_300 = OrderSendRetries; gda_492[l_index_4] = g_price_304; } else { g_count_300++; logError("CheckPosition", StringConcatenate("failed to modify LONG T/P - attempt #", g_count_300), GetLastError()); Sleep(500); } } } else { if (gia_476[l_index_4] == 1 && gi_196 && gda_492[l_index_4] < NormalizeDouble(gda_484[l_index_4] - TakeProfit * gd_364 * Point, Digits) && Ask > gda_484[l_index_4]) { g_count_300 = 0; while (g_count_300 < OrderSendRetries) { RefreshRates(); g_price_304 = NormalizeDouble(Bid - gi_192 * gd_364 * Point, Digits); if (g_price_304 > NormalizeDouble(gda_484[l_index_4] - TakeProfit * gd_364 * Point, Digits)) g_price_304 = NormalizeDouble(gda_484[l_index_4] - TakeProfit * gd_364 * Point, Digits); if (g_price_304 <= NormalizeDouble(gda_492[l_index_4], Digits)) break; if (TradeIsBusy() < 0) return (-1); g_bool_452 = OrderModify(gia_472[l_index_4], gda_484[l_index_4], gda_488[l_index_4], g_price_304, 0, Blue); TradeIsNotBusy(); if (g_bool_452) { g_count_300 = OrderSendRetries; gda_492[l_index_4] = g_price_304; } else { g_count_300++; logError("CheckPosition", StringConcatenate("failed to modify SHORT T/P - attempt #", g_count_300), GetLastError()); Sleep(500); } } } } } } } } return (1); } double LotSize() { double ld_ret_0; if (MoneyManagement) { if (AccountLeverage() <= 0) { logError("LotSize", StringConcatenate("CalculateVolume: invalid AccountLeverage() [", AccountLeverage(), "]")); return (-1); } ld_ret_0 = NormalizeDouble(100.0 * (AccountFreeMargin() * (NormalizeDouble(Risk_percent, 1) / 100.0)) / g_lotsize_344, 2); ld_ret_0 = NormalizeDouble(ld_ret_0 / g_lotstep_336, 0) * g_lotstep_336; ld_ret_0 = MathMin(maxLots, MathMax(minLots, ld_ret_0)); } else ld_ret_0 = minLots; return (ld_ret_0); } void Function_Trade() { if (gi_372 && gi_380 && NoPos()) { g_count_300 = 0; while (g_count_300 < OrderSendRetries) { if (TradeIsBusy() < 0) return; RefreshRates(); if (gi_188) g_price_304 = Ask + gi_192 * gd_364 * Point; else g_price_304 = Ask + TakeProfit * gd_364 * Point; if (StopLoss > (gi_292 + gi_296) / gd_364 - 1.0) g_price_312 = Ask - StopLoss * gd_364 * Point; else g_price_312 = Ask - 60.0 * gd_364 * Point; if (UseATRStop) g_price_312 = Ask - gd_236 * gd_364 * Point; g_ticket_456 = OrderSend(gs_gbpchf_252, OP_BUY, LotSize(), Ask, Slippage, g_price_312, g_price_304, g_comment_264, g_magic_260, 0, Blue); TradeIsNotBusy(); if (g_ticket_456 == -1) { g_count_300++; logError("Function_Trade", StringConcatenate("could not open LONG order - attempt #", g_count_300)); Sleep(500); } else { g_count_300 = OrderSendRetries; gi_468 = -1; } } } if (gi_376 && gi_380 && NoPos()) { g_count_300 = 0; while (g_count_300 < OrderSendRetries) { if (TradeIsBusy() < 0) break; RefreshRates(); if (gi_188) g_price_304 = Bid - gi_192 * gd_364 * Point; else g_price_304 = Bid - TakeProfit * gd_364 * Point; if (StopLoss > (gi_292 + gi_296) / gd_364 - 1.0) g_price_312 = Bid + StopLoss * gd_364 * Point; else g_price_312 = Bid + 60.0 * gd_364 * Point; if (UseATRStop) g_price_312 = Bid + gd_236 * gd_364 * Point; g_ticket_456 = OrderSend(gs_gbpchf_252, OP_SELL, LotSize(), Bid, Slippage, g_price_312, g_price_304, g_comment_264, g_magic_260, 0, Red); TradeIsNotBusy(); if (g_ticket_456 == -1) { g_count_300++; logError("Function_Trade", StringConcatenate("could not open SHORT order - attempt #", g_count_300)); Sleep(500); } else { g_count_300 = OrderSendRetries; gi_468 = -1; } } } } void CacheOrders() { if (gi_468 != OrdersTotal()) InitializeOrders(g_magic_260); } void InitializeOrders(int ai_unused_0) { int li_unused_4 = 0; int l_ord_total_8 = OrdersTotal(); int li_12 = MathMax(l_ord_total_8, 1); ArrayResize(gia_472, li_12); ArrayResize(gia_476, li_12); ArrayResize(gda_480, li_12); ArrayResize(gda_484, li_12); ArrayResize(gda_488, li_12); ArrayResize(gda_492, li_12); ArrayResize(gia_508, li_12); ArrayResize(gda_496, li_12); ArrayResize(gda_500, li_12); ArrayResize(gda_504, li_12); ArrayResize(gsa_516, li_12); ArrayResize(gia_512, li_12); ArrayInitialize(gia_472, 0); ArrayInitialize(gia_476, 0); ArrayInitialize(gda_480, 0); ArrayInitialize(gda_484, 0); ArrayInitialize(gda_488, 0); ArrayInitialize(gda_492, 0); ArrayInitialize(gia_508, 0); ArrayInitialize(gda_496, 0); ArrayInitialize(gda_500, 0); ArrayInitialize(gda_504, 0); ArrayInitialize(gia_512, 0); gi_464 = 0; for (int l_pos_16 = l_ord_total_8 - 1; l_pos_16 >= 0; l_pos_16--) { if (!OrderSelect(l_pos_16, SELECT_BY_POS)) logError("InitializeOrders", "failed to select order", GetLastError()); else { if (OrderMagicNumber() == g_magic_260 && OrderSymbol() == gs_gbpchf_252) { gia_472[gi_464] = OrderTicket(); gia_476[gi_464] = OrderType(); gda_480[gi_464] = NormalizeDouble(OrderLots(), gi_360); gda_484[gi_464] = NormalizeDouble(OrderOpenPrice(), Digits); gda_488[gi_464] = NormalizeDouble(OrderStopLoss(), Digits); gda_492[gi_464] = NormalizeDouble(OrderTakeProfit(), Digits); gia_508[gi_464] = OrderOpenTime(); gda_496[gi_464] = NormalizeDouble(OrderProfit(), 2); gda_500[gi_464] = NormalizeDouble(OrderSwap(), 2); gda_504[gi_464] = NormalizeDouble(OrderCommission(), 2); gsa_516[gi_464] = OrderComment(); gia_512[gi_464] = OrderExpiration(); gi_464++; } } } li_12 = MathMax(gi_464, 1); ArrayResize(gia_472, li_12); ArrayResize(gia_476, li_12); ArrayResize(gda_480, li_12); ArrayResize(gda_484, li_12); ArrayResize(gda_488, li_12); ArrayResize(gda_492, li_12); ArrayResize(gia_508, li_12); ArrayResize(gda_496, li_12); ArrayResize(gda_500, li_12); ArrayResize(gda_504, li_12); ArrayResize(gsa_516, li_12); ArrayResize(gia_512, li_12); gi_468 = l_ord_total_8; } int TradeIsBusy(int ai_0 = 30) { if (IsTesting()) return (1); int l_error_4 = 0; int li_8 = GetTickCount(); while (true) { if (IsStopped()) { logInfo("The expert was terminated by the user!"); return (-1); } if (GetTickCount() - li_8 > 1000 * ai_0) { logInfo("Waiting time (" + ai_0 + " sec) exceeded!"); return (-2); } if (GlobalVariableCheck("BNTradeIsBusy")) break; l_error_4 = GetLastError(); if (l_error_4 != 0/* NO_ERROR */) { logError("TradeIsBusy", "GlobalVariableCheck", l_error_4); Sleep(100); continue; } if (GlobalVariableSet("BNTradeIsBusy", 1.0) > 0) return (1); l_error_4 = GetLastError(); if (l_error_4 == 0/* NO_ERROR */) continue; logError("TradeIsBusy", "GlobalVariableSet", l_error_4); Sleep(100); } while (true) { if (IsStopped()) { logInfo("The expert was terminated by the user!"); return (-1); } if (GetTickCount() - li_8 > 1000 * ai_0) { logInfo("The waiting time (" + ai_0 + " sec) exceeded!"); return (-2); } if (GlobalVariableSetOnCondition("BNTradeIsBusy", 1.0, 0.0)) return (1); l_error_4 = GetLastError(); if (l_error_4 != 0/* NO_ERROR */) { logError("TradeIsBusy", "GlobalVariableSetOnCondition", l_error_4); continue; } logInfo("Wait until another expert finishes trading..."); Comment("Wait until another expert finishes trading..."); Sleep(1000); Comment(""); } return /*(WARN)*/; } void TradeIsNotBusy() { int l_error_0; if (IsTesting() == 0) { while (true) { if (IsStopped()) { logInfo("The expert was terminated by the user!"); return; } if (GlobalVariableSet("BNTradeIsBusy", 0.0) > 0) return; else { l_error_0 = GetLastError(); if (l_error_0 != 0/* NO_ERROR */) logError("TradeIsNotBusy", "GlobalVariableSet", l_error_0); } Sleep(100); } } } void logError(string as_0, string as_8, int ai_16 = -1) { Print("ERROR: in " + as_0 + "()"); Print("ERROR: " + as_8); int l_error_20 = GetLastError(); if (ai_16 != -1) l_error_20 = ai_16; if (l_error_20 != 0/* NO_ERROR */) Print("ERROR: code=" + l_error_20 + " - " + ErrorDescription(l_error_20)); } void logInfo(string as_0) { Print("INFO: " + as_0); }