extern double TakeProfit = 20.0; extern double Lots = 0.1; extern double StopLoss = 1000.0; extern double TrailingStop = 0.2; extern int MaxTrades = 10; extern int Pips = 25; extern int SecureProfit = 2; extern int AccountProtection = 0; extern int AllSymbolsProtect = 0; extern int OrderstoProtect = 30; extern int ReverseCondition = 0; extern int StartYear = 2007; extern int StartMonth = 7; extern int EndYear = 2009; extern int EndMonth = 12; extern int mm = 0; extern int risk = 5; extern int AccountisNormal = 0; extern int MagicNumber = 123777; extern int Manual = 0; extern int OpenOrdersBasedOn = 0; extern int TimeZone = 16; int g_count_180 = 0; int gi_unused_184 = 0; int g_slippage_188 = 5; double g_price_192 = 0.0; double g_price_200 = 0.0; double g_ask_208 = 0.0; double g_bid_216 = 0.0; double gd_224 = 0.0; double g_lots_232 = 0.0; int g_cmd_240 = OP_BUY; int gi_244 = 0; bool gi_248 = TRUE; double g_ord_open_price_252 = 0.0; int gi_260 = 0; double gd_264 = 0.0; int g_ticket_272 = 0; int gi_276 = 0; double g_price_280 = 0.0; double g_ord_lots_288 = 0.0; double gd_unused_296 = 0.0; double gd_304 = 0.0; bool gi_unused_312 = FALSE; string gs_316 = ""; double gd_324 = 0.0; double gd_unused_332 = 0.0; double gd_unused_340 = 0.0; int init() { return (0); } int deinit() { return (0); } int start() { int l_pos_0 = 0; if (AccountisNormal == 1) { if (mm != 0) gd_224 = MathCeil(AccountBalance() * risk / 10000.0); else gd_224 = Lots; } else { if (mm != 0) gd_224 = MathCeil(AccountBalance() * risk / 10000.0) / 10.0; else gd_224 = Lots; } if (gd_224 > 100.0) gd_224 = 100; g_count_180 = 0; for (l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++) { OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) g_count_180++; } if (g_count_180 < 1) { if (TimeYear(TimeCurrent()) < StartYear) return (0); if (TimeMonth(TimeCurrent()) < StartMonth) return (0); if (TimeYear(TimeCurrent()) > EndYear) return (0); if (TimeMonth(TimeCurrent()) > EndMonth) return (0); } if (Symbol() == "EURUSD") gd_304 = 10.0; if (Symbol() == "GBPUSD") gd_304 = 10.0; if (Symbol() == "USDJPY") gd_304 = 9.715; if (Symbol() == "USDCHF") gd_304 = 8.7; if (gd_304 == 0.0) gd_304 = 5; if (gi_260 > g_count_180) { for (l_pos_0 = OrdersTotal() - 1; l_pos_0 >= 0; l_pos_0--) { OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES); g_cmd_240 = OrderType(); if ((OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) || AllSymbolsProtect == 1) { if (g_cmd_240 == OP_BUY) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), g_slippage_188, Blue); if (g_cmd_240 == OP_SELL) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), g_slippage_188, Red); return (0); } } } gi_260 = g_count_180; if (g_count_180 >= MaxTrades) gi_248 = FALSE; else gi_248 = TRUE; if (g_ord_open_price_252 == 0.0) { for (l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++) { OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES); g_cmd_240 = OrderType(); if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { g_ord_open_price_252 = OrderOpenPrice(); if (g_cmd_240 == OP_BUY) gi_244 = 2; if (g_cmd_240 == OP_SELL) gi_244 = 1; } } } if (g_count_180 < 1 && Manual == 0) { switch (OpenOrdersBasedOn) { case 0: gi_244 = OpenOrdersBasedOnMACD(); break; case 1: gi_244 = OpenOrdersBasedOnPivot(); break; case 2: gi_244 = OpenOrdersBasedOnSupRes(); break; default: gi_244 = OpenOrdersBasedOnMACD(); } if (ReverseCondition == 1) { if (gi_244 == 1) gi_244 = 2; else if (gi_244 == 2) gi_244 = 1; } } for (l_pos_0 = OrdersTotal(); l_pos_0 >= 0; l_pos_0--) { OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { Print("Ticket ", OrderTicket(), " modified."); if (OrderType() == OP_SELL) { if (TrailingStop > 0.0) { if (OrderOpenPrice() - Ask >= TrailingStop * Point + Pips * Point) { if (OrderStopLoss() > Ask + Point * TrailingStop || OrderStopLoss() == 0.0) { OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * TrailingStop, OrderClosePrice() - TakeProfit * Point - TrailingStop * Point, 0, Purple); return (0); } } } } if (OrderType() == OP_BUY) { if (TrailingStop > 0.0) { if (Bid - OrderOpenPrice() >= TrailingStop * Point + Pips * Point) { if (OrderStopLoss() < Bid - Point * TrailingStop) { OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * TrailingStop, OrderClosePrice() + TakeProfit * Point + TrailingStop * Point, 0, Yellow); return (0); } } } } } } if (g_count_180 >= MaxTrades - OrderstoProtect && AccountProtection == 1) { gd_264 = 0; g_ticket_272 = 0; gi_276 = FALSE; g_price_280 = 0; g_ord_lots_288 = 0; for (l_pos_0 = 0; l_pos_0 < OrdersTotal(); l_pos_0++) { OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNumber) { g_ticket_272 = OrderTicket(); if (OrderType() == OP_BUY) gi_276 = FALSE; if (OrderType() == OP_SELL) gi_276 = TRUE; g_price_280 = OrderClosePrice(); g_ord_lots_288 = OrderLots(); if (gi_276 == FALSE) { if (OrderClosePrice() < OrderOpenPrice()) gd_264 -= (OrderOpenPrice() - OrderClosePrice()) * OrderLots() / Point; if (OrderClosePrice() > OrderOpenPrice()) gd_264 += (OrderClosePrice() - OrderOpenPrice()) * OrderLots() / Point; } if (gi_276 == TRUE) { if (OrderClosePrice() > OrderOpenPrice()) gd_264 -= (OrderClosePrice() - OrderOpenPrice()) * OrderLots() / Point; if (OrderClosePrice() < OrderOpenPrice()) gd_264 += (OrderOpenPrice() - OrderClosePrice()) * OrderLots() / Point; } } } gd_264 *= gd_304; if (AllSymbolsProtect == 1) gd_324 = AccountBalance(); else gd_324 = SecureProfit; if (gd_264 >= gd_324) { OrderClose(g_ticket_272, g_ord_lots_288, g_price_280, g_slippage_188, Yellow); gi_248 = FALSE; return (0); } } if (!IsTesting()) { if (gi_244 == 3) gs_316 = "No conditions to open trades"; else gs_316 = " "; Comment("LastPrice=", g_ord_open_price_252, " Previous open orders=", gi_260, "\nContinue opening=", gi_248, " OrderType=", gi_244, "\nLots=", gd_224, "\n", gs_316); } if (gi_244 == 1 && gi_248) { if (Bid - g_ord_open_price_252 >= Pips * Point || g_count_180 < 1) { g_bid_216 = Bid; g_ord_open_price_252 = 0; if (TakeProfit == 0.0) g_price_200 = 0; else g_price_200 = g_bid_216 - TakeProfit * Point; if (StopLoss == 0.0) g_price_192 = 0; else g_price_192 = g_bid_216 + StopLoss * Point; if (g_count_180 != 0) { g_lots_232 = gd_224; for (l_pos_0 = 1; l_pos_0 <= g_count_180; l_pos_0++) { if (MaxTrades > 12) g_lots_232 = NormalizeDouble(1.5 * g_lots_232, 2); else g_lots_232 = NormalizeDouble(2.0 * g_lots_232, 2); } } else g_lots_232 = gd_224; if (g_lots_232 > 100.0) g_lots_232 = 100; OrderSend(Symbol(), OP_SELL, g_lots_232, g_bid_216, g_slippage_188, g_price_192, g_price_200, "DLM" + MagicNumber, MagicNumber, 0, Red); return (0); } } if (gi_244 == 2 && gi_248) { if (g_ord_open_price_252 - Ask >= Pips * Point || g_count_180 < 1) { g_ask_208 = Ask; g_ord_open_price_252 = 0; if (TakeProfit == 0.0) g_price_200 = 0; else g_price_200 = g_ask_208 + TakeProfit * Point; if (StopLoss == 0.0) g_price_192 = 0; else g_price_192 = g_ask_208 - StopLoss * Point; if (g_count_180 != 0) { g_lots_232 = gd_224; for (l_pos_0 = 1; l_pos_0 <= g_count_180; l_pos_0++) { if (MaxTrades > 12) g_lots_232 = NormalizeDouble(1.5 * g_lots_232, 2); else g_lots_232 = NormalizeDouble(2.0 * g_lots_232, 2); } } else g_lots_232 = gd_224; if (g_lots_232 > 100.0) g_lots_232 = 100; OrderSend(Symbol(), OP_BUY, g_lots_232, g_ask_208, g_slippage_188, g_price_192, g_price_200, "DLM" + MagicNumber, MagicNumber, 0, Blue); return (0); } } return (0); } int OpenOrdersBasedOnMACD() { int li_ret_0 = 3; if (iMACD(NULL, 0, 14, 26, 9, PRICE_CLOSE, MODE_MAIN, 0) > iMACD(NULL, 0, 14, 26, 9, PRICE_CLOSE, MODE_MAIN, 1)) li_ret_0 = 2; if (iMACD(NULL, 0, 14, 26, 9, PRICE_CLOSE, MODE_MAIN, 0) < iMACD(NULL, 0, 14, 26, 9, PRICE_CLOSE, MODE_MAIN, 1)) li_ret_0 = 1; return (li_ret_0); } int OpenOrdersBasedOnPivot() { int li_ret_0 = 3; double l_icustom_4 = 0; l_icustom_4 = iCustom(Symbol(), 0, "Pivot Lines TimeZone", TimeZone, 1, 0, 0, 0, 0); if (Close[0] > l_icustom_4) li_ret_0 = 2; if (Close[0] < l_icustom_4) li_ret_0 = 1; return (li_ret_0); } int OpenOrdersBasedOnSupRes() { int li_ret_0 = 3; double l_icustom_4 = 0; double l_icustom_12 = 0; l_icustom_4 = iCustom(Symbol(), 0, "Support and Resistance", 0, 0); l_icustom_12 = iCustom(Symbol(), 0, "Support and Resistance", 1, 0); if (Close[0] == l_icustom_12) li_ret_0 = 1; if (Close[0] == l_icustom_4) li_ret_0 = 2; return (li_ret_0); }