extern string note11 = "#### zigandzag Parameters ####"; extern int KeelOver = 55; extern int Slalom = 17; extern string note0 = "#### Global Parameters ####"; extern int MagicNumber = 123456; extern bool EachTickMode = TRUE; extern string note01 = "2 = microlot,1 = minilot"; extern int LotDigits = 1; extern double LotPercent = 0.0; extern int Slippage = 3; extern string note1 = "#### Time Parameters ####"; extern bool UseTradingHours = FALSE; extern bool AlertOpenValid = FALSE; extern bool AlertCloseValid = FALSE; extern bool TradeTokyoMarket = FALSE; extern int StartHour1 = 3; extern int StopHour1 = 7; extern bool TradeLondreMarket = TRUE; extern int StartHour5 = 8; extern int StopHour5 = 20; extern string note3 = "--basket loss/profit--"; extern bool BasketProfitLoss = FALSE; extern int BasketProfit = 100000; extern double BasketLoss = 1.0; extern string note5 = "#### TS Parameters ####"; extern int StopLoss.Pips = 500; extern int TakeProfit.Pips = 5000; extern int Trail.Pips = 2000; extern bool Trail.Starts.After.BreakEven = FALSE; extern int Move.To.BreakEven.at.pips = 1500; extern int Move.To.BreakEven.Lock.pips = 100; extern int Move.Trail.Every.xx.Pips = 0; extern bool Use.ADR.for.SL.pips = FALSE; extern double tsl.divisor = 0.4; extern string note9 = "---Close reverse ---"; extern bool Uselogic = FALSE; extern int MaxTradePerBar = 1; datetime g_time_264; int g_count_268 = 0; int g_bars_272 = -1; int g_pos_276; int gi_unused_280; int gi_unused_284; string g_time2str_288; string gs_dummy_296; string gs_unused_304 = " Trailing"; string gs_unused_312 = "Trailing"; double gd_320; double gd_328; double gd_336; double gd_344; double gd_380; double gd_388; double gd_unused_396 = 0.0; bool gi_404 = FALSE; bool gi_408; int gi_412; int init() { MagicNumber = subGenerateMagicNumber(MagicNumber, Symbol()); g_time_264 = Time[0]; g_bars_272 = Bars; if (EachTickMode) gi_412 = 0; else gi_412 = 1; gi_unused_280 = (Ask - Bid) / Point; return (0); } int deinit() { return (0); } int start() { double ld_unused_0; double ld_8; int l_ticket_24; double l_price_28; double l_price_36; if (BasketProfitLoss) { ld_unused_0 = 0; ld_8 = 0; ld_8 = AccountEquity() - AccountBalance(); if (ld_8 > gd_380) gd_380 = ld_8; if (ld_8 < gd_388) gd_388 = ld_8; if (ld_8 >= BasketProfit || ld_8 <= AccountEquity() * (-1.0 * BasketLoss) / 100.0) { CloseBuyOrders(MagicNumber); CloseSellOrders(MagicNumber); return (0); } } if (Use.ADR.for.SL.pips) StopLoss.Pips = NormalizeDouble(Daily.Range() / Point, Digits); gd_344 = NormalizeDouble(Daily.Range() * tsl.divisor, Digits); gi_unused_284 = MathAbs(iHigh(Symbol(), PERIOD_D1, 0) - iLow(Symbol(), PERIOD_D1, 0)) / Point; CheckInitialSLTP(); if (Move.To.BreakEven.at.pips != 0) MoveToBreakEven(); Trail.Stop(); comments(); int li_16 = 0; if (EachTickMode && Bars != g_bars_272) gi_404 = FALSE; int l_ord_total_20 = OrdersTotal(); li_16 = 0; if (UseTradingHours) { gi_408 = TRUE; if (TradeTokyoMarket == TRUE) { if (StartHour1 > 18) { if (Hour() >= StartHour1) gi_408 = FALSE; if (!gi_408) { if (StopHour1 < 24) if (Hour() <= StopHour1) gi_408 = FALSE; } if (StopHour1 >= 0) if (Hour() <= StopHour1) gi_408 = FALSE; } } else { if (Hour() >= StartHour1 && Hour() <= StopHour1) gi_408 = FALSE; if (AlertOpenValid == TRUE) { Alert(" Bourse de Tokyo ouverte "); PlaySound("Tokyo ouverture.wav"); AlertOpenValid = FALSE; AlertCloseValid = TRUE; } } if (gi_408) { if (TradeLondreMarket == TRUE) { if (Hour() >= StartHour5 && Hour() <= StopHour5) gi_408 = FALSE; if (AlertOpenValid == TRUE) { Alert("Bourse de Londre ouverte"); PlaySound("londre ouverture.wav"); AlertOpenValid = FALSE; AlertCloseValid = TRUE; } } } if (gi_408) { Comment("Trading a été arrêté à la demande - mauvais moment de la journée"); return (0); } } double l_icustom_44 = iCustom(NULL, 0, "genius", KeelOver, Slalom, 5, gi_412 + 0); double l_icustom_52 = iCustom(NULL, 0, "genius", KeelOver, Slalom, 6, gi_412 + 0); if (l_icustom_44 > 0.0) li_16 = 1; if (l_icustom_52 > 0.0) li_16 = 2; if (g_bars_272 != Bars) { g_count_268 = 0; g_bars_272 = Bars; } if (li_16 == 1 && (g_count_268 <= MaxTradePerBar && (EachTickMode && !gi_404) || (!EachTickMode && Bars != g_bars_272))) { if (counttradesBUY() < 10) { if (g_time_264 != Time[0]) { g_time_264 = Time[0]; if (l_ticket_24 > 0) g_count_268++; l_ticket_24 = OrderSend(Symbol(), OP_BUY, LotsCalc(), Ask, Slippage, l_price_28, l_price_36, "Buy(#" + MagicNumber + ")", MagicNumber, 0, DodgerBlue); if (l_ticket_24 > 0) { if (OrderSelect(l_ticket_24, SELECT_BY_TICKET, MODE_TRADES)) Print("BUY order opened : ", OrderOpenPrice()); else Print("Error opening BUY order : ", GetLastError()); } if (EachTickMode) gi_404 = TRUE; if (!EachTickMode) g_bars_272 = Bars; return (0); } } } if (li_16 == 2 && (g_count_268 <= MaxTradePerBar && (EachTickMode && !gi_404) || (!EachTickMode && Bars != g_bars_272))) { if (counttradesSELL() < 10) { g_time_264 = Time[0]; if (l_ticket_24 > 0) g_count_268++; l_ticket_24 = OrderSend(Symbol(), OP_SELL, LotsCalc(), Bid, Slippage, l_price_28, l_price_36, "Sell(#" + MagicNumber + ")", MagicNumber, 0, DeepPink); if (l_ticket_24 > 0) { if (OrderSelect(l_ticket_24, SELECT_BY_TICKET, MODE_TRADES)) Print("SELL order opened : ", OrderOpenPrice()); else Print("Error opening SELL order : ", GetLastError()); } if (EachTickMode) gi_404 = TRUE; if (!EachTickMode) g_bars_272 = Bars; return (0); } } if (!EachTickMode) g_bars_272 = Bars; return (0); } double LotsCalc() { int li_8; if (MarketInfo(Symbol(), MODE_MINLOT) == 0.1) li_8 = 1; else if (MarketInfo(Symbol(), MODE_MINLOT) == 0.01) li_8 = 2; double ld_12 = NormalizeDouble(MarketInfo(Symbol(), MODE_MINLOT), li_8); double ld_20 = NormalizeDouble(MarketInfo(Symbol(), MODE_MAXLOT), li_8); double ld_28 = NormalizeDouble(AccountFreeMargin(), 2); double ld_ret_0 = NormalizeDouble(ld_28 * (LotPercent / 100.0) / 1000.0, LotDigits); if (ld_ret_0 > ld_20) ld_ret_0 = ld_20; if (ld_ret_0 < ld_12) ld_ret_0 = ld_12; return (ld_ret_0); } int counttradesBUY() { int l_pos_0 = 0; int l_count_4 = 0; for (l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++) { OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_BUY && OrderSymbol() == Symbol()) l_count_4++; } return (l_count_4); } int counttradesSELL() { int l_pos_0 = 0; int l_count_4 = 0; for (l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++) { OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_SELL && OrderSymbol() == Symbol()) l_count_4++; } return (l_count_4); } void CheckInitialSLTP() { int li_0; int li_4; for (int l_pos_8 = 0; l_pos_8 < OrdersTotal(); l_pos_8++) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_BUY && OrderSymbol() == Symbol()) { if (OrderStopLoss() == 0.0 || OrderTakeProfit() == 0.0) { if (OrderStopLoss() == 0.0) li_0 = StopLoss.Pips; if (OrderTakeProfit() == 0.0) li_4 = TakeProfit.Pips; if ((li_0 > 0 && OrderStopLoss() == 0.0) || (li_4 > 0 && OrderTakeProfit() == 0.0)) { OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - li_0 * Point, OrderOpenPrice() + li_4 * Point, OrderExpiration(), MediumSpringGreen); if (OrderSelect(OrderTicket(), SELECT_BY_TICKET, MODE_TRADES)) Print("Initial SL or TP is Set for Long Entry"); else Print("Error setting initial SL or TP for Long Entry"); } } } if (OrderType() == OP_SELL && OrderSymbol() == Symbol()) { if (OrderStopLoss() == 0.0 || OrderTakeProfit() == 0.0) { if (OrderStopLoss() == 0.0) li_0 = StopLoss.Pips; if (OrderTakeProfit() == 0.0) li_4 = TakeProfit.Pips; if ((li_0 > 0 && OrderStopLoss() == 0.0) || (li_4 > 0 && OrderTakeProfit() == 0.0)) { OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + li_0 * Point, OrderOpenPrice() - li_4 * Point, OrderExpiration(), MediumVioletRed); if (OrderSelect(OrderTicket(), SELECT_BY_TICKET, MODE_TRADES)) Print("Initial SL or TP is Set for Short Entry"); else Print("Error setting initial SL or TP for Short Entry"); } } } } } double Daily.Range() { if (g_time2str_288 == TimeToStr(TimeCurrent(), TIME_DATE)) return (NormalizeDouble(gd_320, Digits)); gd_328 = 0; gd_336 = 0; gd_320 = 0; for (int li_0 = 0; li_0 < iBars(Symbol(), PERIOD_D1); li_0++) { gd_328 = iHigh(Symbol(), PERIOD_D1, li_0) - iLow(Symbol(), PERIOD_D1, li_0); gd_336 += gd_328; } double ld_4 = iBars(Symbol(), PERIOD_D1); gd_320 = gd_336 / ld_4; g_time2str_288 = TimeToStr(TimeCurrent(), TIME_DATE); return (NormalizeDouble(gd_320, Digits)); } void comments() { string ls_unused_48; string ls_unused_0 = ""; string ls_8 = ""; string ls_unused_16 = ""; string ls_unused_24 = ""; string ls_unused_32 = ""; string ls_unused_40 = ""; int li_unused_56 = 0; double l_ord_profit_60 = 0; for (int l_pos_68 = 0; l_pos_68 < OrdersTotal(); l_pos_68++) { OrderSelect(l_pos_68, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_BUY && OrderSymbol() == Symbol()) { OrderSelect(l_pos_68, SELECT_BY_TICKET); li_unused_56 = NormalizeDouble((Bid - OrderOpenPrice()) / Point, Digits); l_ord_profit_60 = OrderProfit(); } if (OrderType() == OP_SELL && OrderSymbol() == Symbol()) { OrderSelect(l_pos_68, SELECT_BY_TICKET); li_unused_56 = NormalizeDouble((OrderOpenPrice() - Ask) / Point, Digits); l_ord_profit_60 = OrderProfit(); } if (Move.To.BreakEven.at.pips > 0) { ls_8 = "s/l will move to b/e after: " + Move.To.BreakEven.at.pips + " pips and lock: " + Move.To.BreakEven.Lock.pips + " pips" + "\n\n"; } else ls_8 = ""; } } void Trail.With.ADR(int ai_0) { double ld_4; double l_price_12; double ld_20; double l_price_28; if (ai_0 == 0) { for (int l_pos_36 = 0; l_pos_36 < OrdersTotal(); l_pos_36++) { OrderSelect(l_pos_36, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_BUY && OrderSymbol() == Symbol()) { ld_4 = NormalizeDouble(gd_344, Digits); l_price_12 = 0; if (OrderStopLoss() < OrderOpenPrice() && OrderOpenPrice() - OrderStopLoss() < gd_344) ld_4 = OrderOpenPrice() - OrderStopLoss(); if (OrderStopLoss() < OrderOpenPrice() && OrderOpenPrice() - OrderStopLoss() >= gd_344) ld_4 = NormalizeDouble(gd_344, Digits); if (Bid > OrderOpenPrice() + ld_4 && OrderStopLoss() < OrderOpenPrice() + (Bid - (OrderOpenPrice() + ld_4))) { l_price_12 = NormalizeDouble(OrderOpenPrice() + (Bid - (OrderOpenPrice() + ld_4)), Digits); Print("b.tsl ", l_price_12); if (OrderStopLoss() < l_price_12) OrderModify(OrderTicket(), OrderOpenPrice(), l_price_12, OrderTakeProfit(), OrderExpiration(), MediumSpringGreen); } } if (OrderType() == OP_SELL && OrderSymbol() == Symbol()) { ld_20 = NormalizeDouble(gd_344, Digits); l_price_28 = 0; if (OrderStopLoss() > OrderOpenPrice() && OrderStopLoss() - OrderOpenPrice() < gd_344) ld_20 = OrderStopLoss() - OrderOpenPrice(); if (OrderStopLoss() > OrderOpenPrice() && OrderStopLoss() - OrderOpenPrice() >= gd_344) ld_20 = NormalizeDouble(gd_344, Digits); if (Ask < OrderOpenPrice() - ld_20 && OrderStopLoss() > OrderOpenPrice() - (OrderOpenPrice() - ld_20) - Ask) { l_price_28 = NormalizeDouble(OrderOpenPrice() - (OrderOpenPrice() - ld_20 - Ask), Digits); Print("s.tsl ", l_price_28); if (OrderStopLoss() > l_price_28) OrderModify(OrderTicket(), OrderOpenPrice(), l_price_28, OrderTakeProfit(), OrderExpiration(), MediumVioletRed); } } } } else { for (l_pos_36 = 0; l_pos_36 < OrdersTotal(); l_pos_36++) { OrderSelect(l_pos_36, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_BUY && OrderSymbol() == Symbol()) { ld_4 = NormalizeDouble(gd_344, Digits); l_price_12 = 0; if (Bid >= OrderOpenPrice() + Move.To.BreakEven.at.pips * Point) { if (OrderStopLoss() < OrderOpenPrice() && OrderOpenPrice() - OrderStopLoss() < gd_344) ld_4 = OrderOpenPrice() - OrderStopLoss(); if (OrderStopLoss() < OrderOpenPrice() && OrderOpenPrice() - OrderStopLoss() >= gd_344) ld_4 = NormalizeDouble(gd_344, Digits); if (Bid > OrderOpenPrice() + ld_4 && OrderStopLoss() < OrderOpenPrice() + (Bid - (OrderOpenPrice() + ld_4))) { l_price_12 = NormalizeDouble(OrderOpenPrice() + (Bid - (OrderOpenPrice() + ld_4)), Digits); Print("b.tsl ", l_price_12); if (OrderStopLoss() < l_price_12) OrderModify(OrderTicket(), OrderOpenPrice(), l_price_12, OrderTakeProfit(), OrderExpiration(), MediumSpringGreen); } } } if (OrderType() == OP_SELL && OrderSymbol() == Symbol()) { ld_20 = NormalizeDouble(gd_344, Digits); l_price_28 = 0; if (Ask <= OrderOpenPrice() - Move.To.BreakEven.at.pips * Point) { if (OrderStopLoss() > OrderOpenPrice() && OrderStopLoss() - OrderOpenPrice() < gd_344) ld_20 = OrderStopLoss() - OrderOpenPrice(); if (OrderStopLoss() > OrderOpenPrice() && OrderStopLoss() - OrderOpenPrice() >= gd_344) ld_20 = NormalizeDouble(gd_344, Digits); if (Ask < OrderOpenPrice() - ld_20 && OrderStopLoss() > OrderOpenPrice() - (OrderOpenPrice() - ld_20) - Ask) { l_price_28 = NormalizeDouble(OrderOpenPrice() - (OrderOpenPrice() - ld_20 - Ask), Digits); Print("s.tsl ", l_price_28); if (OrderStopLoss() > l_price_28) OrderModify(OrderTicket(), OrderOpenPrice(), l_price_28, OrderTakeProfit(), OrderExpiration(), MediumVioletRed); } } } } } } void Trail.With.Standard.Trailing(int ai_0) { double ld_4; double l_price_12; double ld_20; double l_price_28; if (ai_0 == 0) { for (g_pos_276 = 0; g_pos_276 < OrdersTotal(); g_pos_276++) { OrderSelect(g_pos_276, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_BUY && OrderSymbol() == Symbol()) { ld_4 = Trail.Pips * Point; if (Bid > OrderOpenPrice() + ld_4 && OrderStopLoss() < OrderOpenPrice() + (Bid - (OrderOpenPrice() + ld_4))) { l_price_12 = NormalizeDouble(OrderOpenPrice() + (Bid - (OrderOpenPrice() + ld_4)), Digits); Print("b.tsl ", l_price_12); if (OrderStopLoss() < l_price_12) OrderModify(OrderTicket(), OrderOpenPrice(), l_price_12, OrderTakeProfit(), OrderExpiration(), MediumSpringGreen); } } if (OrderType() == OP_SELL && OrderSymbol() == Symbol()) { ld_20 = Trail.Pips * Point; if (Ask < OrderOpenPrice() - ld_20 && OrderStopLoss() > OrderOpenPrice() - (OrderOpenPrice() - ld_20) - Ask) { l_price_28 = NormalizeDouble(OrderOpenPrice() - (OrderOpenPrice() - ld_20 - Ask), Digits); Print("s.tsl ", l_price_28); if (OrderStopLoss() > l_price_28) OrderModify(OrderTicket(), OrderOpenPrice(), l_price_28, OrderTakeProfit(), OrderExpiration(), MediumVioletRed); } } } } else { for (g_pos_276 = 0; g_pos_276 < OrdersTotal(); g_pos_276++) { OrderSelect(g_pos_276, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_BUY && OrderSymbol() == Symbol()) { if (Bid >= OrderOpenPrice() + Move.To.BreakEven.at.pips * Point) { ld_4 = Trail.Pips * Point; if (Bid > OrderOpenPrice() + ld_4 && OrderStopLoss() < OrderOpenPrice() + (Bid - (OrderOpenPrice() + ld_4))) { l_price_12 = NormalizeDouble(OrderOpenPrice() + (Bid - (OrderOpenPrice() + ld_4)), Digits); Print("b.tsl ", l_price_12); if (OrderStopLoss() < l_price_12) OrderModify(OrderTicket(), OrderOpenPrice(), l_price_12, OrderTakeProfit(), OrderExpiration(), MediumSpringGreen); } } } if (OrderType() == OP_SELL && OrderSymbol() == Symbol()) { if (Ask <= OrderOpenPrice() - Move.To.BreakEven.at.pips * Point) { ld_20 = Trail.Pips * Point; if (Ask < OrderOpenPrice() - ld_20 && OrderStopLoss() > OrderOpenPrice() - (OrderOpenPrice() - ld_20) - Ask) { l_price_28 = NormalizeDouble(OrderOpenPrice() - (OrderOpenPrice() - ld_20 - Ask), Digits); Print("s.tsl ", l_price_28); if (OrderStopLoss() > l_price_28) OrderModify(OrderTicket(), OrderOpenPrice(), l_price_28, OrderTakeProfit(), OrderExpiration(), MediumVioletRed); } } } } } } void Trail.With.Every.xx.Pips() { double ld_0; double l_price_8; double ld_16; double l_price_24; double ld_32; int li_40; for (g_pos_276 = 0; g_pos_276 < OrdersTotal(); g_pos_276++) { OrderSelect(g_pos_276, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_BUY && OrderSymbol() == Symbol()) { ld_32 = (Bid - OrderOpenPrice()) / Point; if (ld_32 >= Move.Trail.Every.xx.Pips) { li_40 = MathFloor(ld_32 / Move.Trail.Every.xx.Pips); ld_0 = li_40 * Trail.Pips * Point; if (Bid > OrderOpenPrice() + ld_0 && OrderStopLoss() < OrderOpenPrice() + (Bid - (OrderOpenPrice() + ld_0))) { l_price_8 = NormalizeDouble(OrderOpenPrice() + (Bid - (OrderOpenPrice() + ld_0)), Digits); Print("b.tsl ", l_price_8); if (OrderStopLoss() < l_price_8) OrderModify(OrderTicket(), OrderOpenPrice(), l_price_8, OrderTakeProfit(), OrderExpiration(), MediumSpringGreen); } } } if (OrderType() == OP_SELL && OrderSymbol() == Symbol()) { ld_32 = (OrderOpenPrice() - Ask) / Point; if (ld_32 >= Move.Trail.Every.xx.Pips) { li_40 = MathFloor(ld_32 / Move.Trail.Every.xx.Pips); ld_16 = li_40 * Trail.Pips * Point; if (Ask < OrderOpenPrice() - ld_16 && OrderStopLoss() > OrderOpenPrice() - (OrderOpenPrice() - ld_16) - Ask) { l_price_24 = NormalizeDouble(OrderOpenPrice() - (OrderOpenPrice() - ld_16 - Ask), Digits); Print("s.tsl ", l_price_24); if (OrderStopLoss() > l_price_24) OrderModify(OrderTicket(), OrderOpenPrice(), l_price_24, OrderTakeProfit(), OrderExpiration(), MediumVioletRed); } } } } } void Trail.Stop() { if (Move.Trail.Every.xx.Pips > 0 && Trail.Pips > 0) { Trail.With.Every.xx.Pips(); return; } if (Use.ADR.for.SL.pips) { if (Trail.Starts.After.BreakEven) { Trail.With.ADR(1); return; } Trail.With.ADR(0); return; } if (Trail.Pips > 0) { if (Trail.Starts.After.BreakEven) { Trail.With.Standard.Trailing(1); return; } Trail.With.Standard.Trailing(0); } } void MoveToBreakEven() { for (g_pos_276 = 0; g_pos_276 < OrdersTotal(); g_pos_276++) { OrderSelect(g_pos_276, SELECT_BY_POS, MODE_TRADES); if (OrderType() == OP_BUY && OrderSymbol() == Symbol()) { if (OrderStopLoss() < OrderOpenPrice()) { if (Bid > Move.To.BreakEven.at.pips * Point + OrderOpenPrice()) { OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() + Move.To.BreakEven.Lock.pips * Point, OrderTakeProfit(), OrderExpiration(), MediumSpringGreen); if (OrderSelect(OrderTicket(), SELECT_BY_TICKET, MODE_TRADES)) Print("Long StopLoss Moved to BE at : ", OrderStopLoss()); else Print("Error moving Long StopLoss to BE: ", GetLastError()); } } } if (OrderType() == OP_SELL && OrderSymbol() == Symbol()) { if (OrderStopLoss() > OrderOpenPrice()) { if (Ask < OrderOpenPrice() - Move.To.BreakEven.at.pips * Point) { OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice() - Move.To.BreakEven.Lock.pips * Point, OrderTakeProfit(), OrderExpiration(), MediumVioletRed); if (OrderSelect(OrderTicket(), SELECT_BY_TICKET, MODE_TRADES)) Print("Short StopLoss Moved to BE at : ", OrderStopLoss()); else Print("Error moving Short StopLoss to BE: ", GetLastError()); } } } } } int CloseBuyOrders(int a_magic_0) { int l_ord_total_4 = OrdersTotal(); for (int l_pos_8 = l_ord_total_4 - 1; l_pos_8 >= 0; l_pos_8--) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == a_magic_0 && OrderSymbol() == Symbol()) if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, 3); } return (0); } int CloseSellOrders(int a_magic_0) { int l_ord_total_4 = OrdersTotal(); for (int l_pos_8 = l_ord_total_4 - 1; l_pos_8 >= 0; l_pos_8--) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == a_magic_0 && OrderSymbol() == Symbol()) if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, 3); } return (0); } int subGenerateMagicNumber(int ai_0, string as_4) { int li_12 = 0; if (as_4 == "EURUSD") li_12 = 1; else { if (as_4 == "GBPUSD") li_12 = 2; else { if (as_4 == "USDCHF") li_12 = 3; else { if (as_4 == "USDJPY") li_12 = 4; else { if (as_4 == "AUDUSD") li_12 = 5; else { if (as_4 == "USDCAD") li_12 = 6; else { if (as_4 == "NZDUSD") li_12 = 7; else { if (as_4 == "EURCHF") li_12 = 8; else { if (as_4 == "EURGBP") li_12 = 9; else { if (as_4 == "EURJPY") li_12 = 10; else { if (as_4 == "GBPCHF") li_12 = 11; else { if (as_4 == "GBPJPY") li_12 = 12; else { if (as_4 == "EURAUD") li_12 = 13; else { if (as_4 == "EURCAD") li_12 = 14; else { if (as_4 == "GBPAUD") li_12 = 15; else { if (as_4 == "GBPCAD") li_12 = 16; else { if (as_4 == "CADJPY") li_12 = 17; else { if (as_4 == "CHFJPY") li_12 = 18; else { if (as_4 == "AUDJPY") li_12 = 19; else { if (as_4 == "AUDCAD") li_12 = 20; else { if (as_4 == "USDSGD") li_12 = 21; else { if (as_4 == "USDNOK") li_12 = 22; else { if (as_4 == "USDSEK") li_12 = 23; else { if (as_4 == "USDDKK") li_12 = 24; else { if (as_4 == "USDRUB") li_12 = 25; else { if (as_4 == "AUDCHF") li_12 = 26; else { if (as_4 == "AUDNZD") li_12 = 27; else { if (as_4 == "AUDSGD") li_12 = 28; else { if (as_4 == "CHFSGD") li_12 = 29; else { if (as_4 == "EURNOK") li_12 = 30; else { if (as_4 == "EURSEK") li_12 = 31; else { if (as_4 == "EURNZD") li_12 = 32; else { if (as_4 == "EURSGD") li_12 = 33; else { if (as_4 == "GBPNZD") li_12 = 34; else { if (as_4 == "GBPSGD") li_12 = 35; else { if (as_4 == "NZDCAD") li_12 = 36; else { if (as_4 == "NZDCHF") li_12 = 37; else { if (as_4 == "NZDJPY") li_12 = 38; else { if (as_4 == "NZDSGD") li_12 = 39; else { if (as_4 == "SGDJPY") li_12 = 40; else { if (as_4 == "EURCCK") li_12 = 41; else { if (as_4 == "EURDKK") li_12 = 42; else { if (as_4 == "EURHUF") li_12 = 43; else { if (as_4 == "EURPLN") li_12 = 44; else { if (as_4 == "USDCCK") li_12 = 45; else { if (as_4 == "USDHKD") li_12 = 46; else { if (as_4 == "USDHUF") li_12 = 47; else { if (as_4 == "USDLVL") li_12 = 48; else { if (as_4 == "USDMXN") li_12 = 49; else { if (as_4 == "USDPLN") li_12 = 50; else { if (as_4 == "USDZAR") li_12 = 51; else { if (as_4 == "AUDDKK") li_12 = 52; else { if (as_4 == "AUDPLN") li_12 = 53; else { if (as_4 == "EURHKD") li_12 = 54; else { if (as_4 == "EURLVL") li_12 = 55; else { if (as_4 == "EURZAR") li_12 = 56; else { if (as_4 == "GBPDKK") li_12 = 57; else { if (as_4 == "GBPZAR") li_12 = 58; else { if (as_4 == "GBPSEK") li_12 = 59; else { if (as_4 == "GBPNOK") li_12 = 60; else { if (as_4 == "USDHRK") li_12 = 61; else { if (as_4 == "USDLTL") li_12 = 62; else { if (as_4 == "CADCHF") li_12 = 63; else li_12 = 64; } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } } if (li_12 < 10) ai_0 = 10 * ai_0; return (StrToInteger(StringConcatenate(ai_0, li_12))); }