extern double TakeProfit = 35.0; extern double Lots = 0.1; extern double InitialStop = 130.0; extern int MaxSpread = 4; extern bool StopNewTrades = FALSE; extern bool Avoid_NFP = TRUE; extern int offhour1 = 30; extern int offhour2 = 30; extern int offhour3 = 30; extern int offhour4 = 30; extern int offhour5 = 30; extern int offhour6 = 30; extern int offhour7 = 30; extern int offhour8 = 30; extern int offhour9 = 30; extern int offhour10 = 30; double g_pips_152 = 0.0; double gd_unused_160 = 0.0006; double gd_unused_168 = 0.0006; int gi_176 = 3; int gi_180 = 15; int gi_184 = 50; int gi_188 = 1; int gi_192 = 5; int gi_unused_196 = 0; bool gi_200 = TRUE; int gi_unused_204 = 0; int gi_unused_208 = 12; int gi_unused_212 = 0; int g_count_216 = 0; int g_pos_220 = 0; int g_slippage_224 = 3; int gi_unused_228 = 0; double g_price_232 = 0.0; double g_price_240 = 0.0; double g_ask_248 = 0.0; double g_bid_256 = 0.0; double g_lots_264 = 0.0; double g_lots_272 = 0.0; int g_cmd_280 = OP_BUY; int gi_284 = 0; int gi_unused_288 = 0; bool gi_292 = TRUE; double g_ord_open_price_296 = 0.0; int gi_304 = 0; double gd_308 = 0.0; int g_ticket_316 = 0; int gi_320 = 0; int gi_unused_324 = 0; double g_price_328 = 0.0; double g_ord_lots_336 = 0.0; double gd_unused_344 = 0.0; double gd_352 = 10.0; string gs_unused_360 = ""; string gs_368 = ""; int gi_unused_376; int gi_380; int init() { gi_unused_376 = Bars; if (gi_200) gi_380 = 0; else gi_380 = 1; return (0); } int deinit() { return (0); } int start() { g_lots_264 = Lots; gi_184 = 50.0 * Lots / 0.1; Comment("Profit target: ", gi_184); double l_iclose_0 = iClose(NULL, PERIOD_M15, gi_380 + 0); double l_ibands_8 = iBands(NULL, PERIOD_M15, 20, 2, 0, PRICE_CLOSE, MODE_LOWER, gi_380 + 0); double l_iclose_16 = iClose(NULL, PERIOD_M15, gi_380 + 0); double l_ibands_24 = iBands(NULL, PERIOD_M15, 20, 2, 0, PRICE_CLOSE, MODE_UPPER, gi_380 + 0); g_count_216 = 0; for (g_pos_220 = 0; g_pos_220 < OrdersTotal(); g_pos_220++) { OrderSelect(g_pos_220, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == 121212) g_count_216++; } if (gi_304 > g_count_216) { for (g_pos_220 = OrdersTotal(); g_pos_220 >= 0; g_pos_220--) { OrderSelect(g_pos_220, SELECT_BY_POS, MODE_TRADES); g_cmd_280 = OrderType(); if (OrderSymbol() == Symbol() && OrderMagicNumber() == 121212) { if (g_cmd_280 == OP_BUY) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), g_slippage_224, Blue); if (g_cmd_280 == OP_SELL) OrderClose(OrderTicket(), OrderLots(), OrderClosePrice(), g_slippage_224, Red); return (0); } } } gi_304 = g_count_216; if (g_count_216 >= gi_176) gi_292 = FALSE; else gi_292 = TRUE; if (g_ord_open_price_296 == 0.0) { for (g_pos_220 = 0; g_pos_220 < OrdersTotal(); g_pos_220++) { OrderSelect(g_pos_220, SELECT_BY_POS, MODE_TRADES); g_cmd_280 = OrderType(); if (OrderSymbol() == Symbol() && OrderMagicNumber() == 121212) { g_ord_open_price_296 = OrderOpenPrice(); if (g_cmd_280 == OP_BUY) gi_284 = 2; if (g_cmd_280 == OP_SELL) gi_284 = 1; } } } if (g_count_216 < 1) { gi_284 = 3; if (l_iclose_0 < l_ibands_8) gi_284 = 2; if (l_iclose_16 > l_ibands_24) gi_284 = 1; } for (g_pos_220 = OrdersTotal(); g_pos_220 >= 0; g_pos_220--) { OrderSelect(g_pos_220, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == 121212) { if (OrderType() == OP_SELL) { if (g_pips_152 > 0.0) { if (OrderOpenPrice() - Ask >= (g_pips_152 + gi_180) * Point) { if (OrderStopLoss() > Ask + Point * g_pips_152) { OrderModify(OrderTicket(), OrderOpenPrice(), Ask + Point * g_pips_152, OrderClosePrice() - TakeProfit * Point - g_pips_152 * Point, 800, Purple); return (0); } } } } if (OrderType() == OP_BUY) { if (g_pips_152 > 0.0) { if (Bid - OrderOpenPrice() >= (g_pips_152 + gi_180) * Point) { if (OrderStopLoss() < Bid - Point * g_pips_152) { OrderModify(OrderTicket(), OrderOpenPrice(), Bid - Point * g_pips_152, OrderClosePrice() + TakeProfit * Point + g_pips_152 * Point, 800, Yellow); return (0); } } } } } } gd_308 = 0; g_ticket_316 = 0; gi_320 = FALSE; g_price_328 = 0; g_ord_lots_336 = 0; for (g_pos_220 = 0; g_pos_220 < OrdersTotal(); g_pos_220++) { OrderSelect(g_pos_220, SELECT_BY_POS, MODE_TRADES); if (OrderSymbol() == Symbol() && OrderMagicNumber() == 121212) { g_ticket_316 = OrderTicket(); if (OrderType() == OP_BUY) gi_320 = FALSE; if (OrderType() == OP_SELL) gi_320 = TRUE; g_price_328 = OrderClosePrice(); g_ord_lots_336 = OrderLots(); if (gi_320 == FALSE) { if (OrderClosePrice() < OrderOpenPrice()) gd_308 -= (OrderOpenPrice() - OrderClosePrice()) * OrderLots() / Point; if (OrderClosePrice() > OrderOpenPrice()) gd_308 += (OrderClosePrice() - OrderOpenPrice()) * OrderLots() / Point; } if (gi_320 == TRUE) { if (OrderClosePrice() > OrderOpenPrice()) gd_308 -= (OrderClosePrice() - OrderOpenPrice()) * OrderLots() / Point; if (OrderClosePrice() < OrderOpenPrice()) gd_308 += (OrderOpenPrice() - OrderClosePrice()) * OrderLots() / Point; } } } gd_308 *= gd_352; gs_368 = "Profit: $" + DoubleToStr(gd_308, 2) + " +/-"; if (g_count_216 >= gi_176 - gi_192 && gi_188 == 1) { if (gd_308 >= gi_184) { OrderClose(g_ticket_316, g_ord_lots_336, g_price_328, g_slippage_224, Yellow); Print("closing 2"); gi_292 = FALSE; return (0); } } if (!IsTesting()) { if (gi_284 == 3) gs_unused_360 = "No conditions to open trades"; else gs_unused_360 = " "; } if (MarketInfo(Symbol(), MODE_SPREAD) > MaxSpread) return (0); if (StopNewTrades) return (0); if (Avoid_NFP && DayOfWeek() == 5 && Day() < 8) return (0); if (Hour() == offhour1) return (0); if (Hour() == offhour2) return (0); if (Hour() == offhour3) return (0); if (Hour() == offhour4) return (0); if (Hour() == offhour5) return (0); if (Hour() == offhour6) return (0); if (Hour() == offhour7) return (0); if (Hour() == offhour8) return (0); if (Hour() == offhour9) return (0); if (Hour() == offhour10) return (0); if (gi_284 == 1 && gi_292) { if (Bid - g_ord_open_price_296 >= gi_180 * Point || g_count_216 < 1) { g_bid_256 = Bid; g_ord_open_price_296 = 0; if (TakeProfit == 0.0) g_price_240 = 0; else g_price_240 = g_bid_256 - TakeProfit * Point; if (InitialStop == 0.0) g_price_232 = 0; else g_price_232 = g_bid_256 + InitialStop * Point; if (g_count_216 != 0) { g_lots_272 = g_lots_264; for (g_pos_220 = 1; g_pos_220 <= g_count_216; g_pos_220++) { if (gi_176 > 12) g_lots_272 = NormalizeDouble(2.0 * g_lots_272, 2); else g_lots_272 = NormalizeDouble(2.0 * g_lots_272, 2); } } else g_lots_272 = g_lots_264; if (g_lots_272 > 100.0) g_lots_272 = 100; OrderSend(Symbol(), OP_SELL, g_lots_272, g_bid_256, g_slippage_224, g_price_232, g_price_240, 0, 121212, 0, Red); return (0); } } if (gi_284 == 2 && gi_292) { if (g_ord_open_price_296 - Ask >= gi_180 * Point || g_count_216 < 1) { g_ask_248 = Ask; g_ord_open_price_296 = 0; if (TakeProfit == 0.0) g_price_240 = 0; else g_price_240 = g_ask_248 + TakeProfit * Point; if (InitialStop == 0.0) g_price_232 = 0; else g_price_232 = g_ask_248 - InitialStop * Point; if (g_count_216 != 0) { g_lots_272 = g_lots_264; for (g_pos_220 = 1; g_pos_220 <= g_count_216; g_pos_220++) { if (gi_176 > 12) g_lots_272 = NormalizeDouble(2.0 * g_lots_272, 2); else g_lots_272 = NormalizeDouble(2.0 * g_lots_272, 2); } } else g_lots_272 = g_lots_264; if (g_lots_272 > 100.0) g_lots_272 = 100; OrderSend(Symbol(), OP_BUY, g_lots_272, g_ask_248, g_slippage_224, g_price_232, g_price_240, 0, 121212, 0, Blue); return (0); } } return (0); }