#property copyright "Copyright ©2007 Forex on Autopilot" #property link "http://ForexAutopilot.com" #include extern int MagicNum = 136567; extern double Lot = 0.1; extern int step1 = 20; extern int step2 = 30; extern int step3 = 40; extern int step4 = 50; extern int step5 = 40; extern int TimeOutMinute = 20; extern int TimeOutHour = 18; extern int CloseAfterMinutes = 15; extern int StopLoss1 = 3; extern int StopLoss2 = 10; extern int TakeProfit1 = 10; extern int TakeProfit2 = 110; extern double TrailingStop1 = 10.0; extern double TrailingStop2 = 30.0; extern int slippage = 2; bool gi_156; int g_datetime_160; int start() { double l_ask_0; double l_ask_8; int l_ord_total_20; if (Bars < 100 || IsTradeAllowed() == FALSE) return; TrailStop(Symbol(), MagicNum, TrailingStop1, TrailingStop2); if (CalculateCurrentOrders() < 1 && Hour() == TimeOutHour && Minute() >= TimeOutMinute && Minute() <= TimeOutMinute + 2) { l_ask_0 = Ask; l_ask_8 = Ask; g_datetime_160 = TimeCurrent(); gi_156 = FALSE; while (!gi_156) { while (!IsTradeAllowed()) Sleep(5000); gi_156 = OrderSend(Symbol(), OP_BUYSTOP, Lot, l_ask_0 + step1 * Point, 3, l_ask_0 + step1 * Point - StopLoss1 * Point, l_ask_0 + step1 * Point + TakeProfit1 * Point, "5o", MagicNum, 0, Blue); if (!gi_156) Print("Error opening BUYSTOP order : ", ErrorDescription(GetLastError())); } gi_156 = FALSE; while (!gi_156) { while (!IsTradeAllowed()) Sleep(5000); gi_156 = OrderSend(Symbol(), OP_BUYSTOP, Lot, l_ask_0 + step2 * Point, 3, l_ask_0 + step2 * Point - StopLoss1 * Point, l_ask_0 + step2 * Point + TakeProfit1 * Point, "5o", MagicNum, 0, Blue); if (!gi_156) Print("Error opening BUYSTOP order : ", ErrorDescription(GetLastError())); } gi_156 = FALSE; while (!gi_156) { while (!IsTradeAllowed()) Sleep(5000); gi_156 = OrderSend(Symbol(), OP_BUYSTOP, Lot, l_ask_0 + step3 * Point, 3, l_ask_0 + step3 * Point - StopLoss1 * Point, l_ask_0 + step3 * Point + TakeProfit1 * Point, "5o", MagicNum, 0, Blue); if (!gi_156) Print("Error opening BUYSTOP order : ", ErrorDescription(GetLastError())); } gi_156 = FALSE; while (!gi_156) { while (!IsTradeAllowed()) Sleep(5000); gi_156 = OrderSend(Symbol(), OP_BUYSTOP, Lot, l_ask_0 + step4 * Point, 3, l_ask_0 + step4 * Point - StopLoss1 * Point, l_ask_0 + step4 * Point + TakeProfit1 * Point, "5o", MagicNum, 0, Blue); if (!gi_156) Print("Error opening BUYSTOP order : ", ErrorDescription(GetLastError())); } gi_156 = FALSE; while (!gi_156) { while (!IsTradeAllowed()) Sleep(5000); gi_156 = OrderSend(Symbol(), OP_BUYSTOP, Lot, l_ask_0 + step5 * Point, 3, l_ask_0 + step5 * Point - StopLoss2 * Point, l_ask_0 + step5 * Point + TakeProfit2 * Point, "spec5o", MagicNum, 0, Blue); if (!gi_156) Print("Error opening BUYSTOP order : ", ErrorDescription(GetLastError())); } gi_156 = FALSE; while (!gi_156) { while (!IsTradeAllowed()) Sleep(5000); gi_156 = OrderSend(Symbol(), OP_SELLSTOP, Lot, l_ask_8 - step1 * Point, 3, l_ask_8 - step1 * Point + StopLoss1 * Point, l_ask_8 - step1 * Point - TakeProfit1 * Point, "5o", MagicNum, 0, Blue); if (!gi_156) Print("Error opening SELLSTOP order : ", ErrorDescription(GetLastError())); } gi_156 = FALSE; while (!gi_156) { while (!IsTradeAllowed()) Sleep(5000); gi_156 = OrderSend(Symbol(), OP_SELLSTOP, Lot, l_ask_8 - step2 * Point, 3, l_ask_8 - step2 * Point + StopLoss1 * Point, l_ask_8 - step2 * Point - TakeProfit1 * Point, "5o", MagicNum, 0, Blue); if (!gi_156) Print("Error opening SELLSTOP order : ", ErrorDescription(GetLastError())); } gi_156 = FALSE; while (!gi_156) { while (!IsTradeAllowed()) Sleep(5000); gi_156 = OrderSend(Symbol(), OP_SELLSTOP, Lot, l_ask_8 - step3 * Point, 3, l_ask_8 - step3 * Point + StopLoss1 * Point, l_ask_8 - step3 * Point - TakeProfit1 * Point, "5o", MagicNum, 0, Blue); if (!gi_156) Print("Error opening SELLSTOP order : ", ErrorDescription(GetLastError())); } gi_156 = FALSE; while (!gi_156) { while (!IsTradeAllowed()) Sleep(5000); gi_156 = OrderSend(Symbol(), OP_SELLSTOP, Lot, l_ask_8 - step4 * Point, 3, l_ask_8 - step4 * Point + StopLoss1 * Point, l_ask_8 - step4 * Point - TakeProfit1 * Point, "5o", MagicNum, 0, Blue); if (!gi_156) Print("Error opening SELLSTOP order : ", ErrorDescription(GetLastError())); } gi_156 = FALSE; while (!gi_156) { while (!IsTradeAllowed()) Sleep(5000); gi_156 = OrderSend(Symbol(), OP_SELLSTOP, Lot, l_ask_8 - step5 * Point, 3, l_ask_8 - step5 * Point + StopLoss2 * Point, l_ask_8 - step5 * Point - TakeProfit2 * Point, "spec5o", MagicNum, 0, Blue); if (!gi_156) Print("Error opening SELLSTOP order : ", ErrorDescription(GetLastError())); } } if ((TimeCurrent() - g_datetime_160) / 60 >= CloseAfterMinutes) { l_ord_total_20 = OrdersTotal(); for (int l_pos_16 = 0; l_pos_16 < l_ord_total_20; l_pos_16++) { if (OrderSelect(l_pos_16, SELECT_BY_POS, MODE_TRADES) == FALSE) break; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNum) { if (OrderType() == OP_BUY) { gi_156 = FALSE; while (!gi_156) { while (!IsTradeAllowed()) Sleep(5000); RefreshRates(); gi_156 = OrderClose(OrderTicket(), OrderLots(), Bid, slippage, Blue); if (!gi_156) Print("Error closing BUY order : ", ErrorDescription(GetLastError())); } } if (OrderType() == OP_SELL) { gi_156 = FALSE; while (!gi_156) { while (!IsTradeAllowed()) Sleep(5000); RefreshRates(); gi_156 = OrderClose(OrderTicket(), OrderLots(), Ask, slippage, Blue); if (!gi_156) Print("Error closing SELL order : ", ErrorDescription(GetLastError())); } } if (OrderType() == OP_BUYSTOP || OrderType() == OP_SELLSTOP) { gi_156 = FALSE; while (!gi_156) { while (!IsTradeAllowed()) Sleep(5000); gi_156 = OrderDelete(OrderTicket()); if (!gi_156) Print("Error deleting STOP order : ", ErrorDescription(GetLastError())); } } } } } return (0); } int CalculateCurrentOrders() { int li_ret_0; for (int l_pos_4 = 0; l_pos_4 < OrdersTotal(); l_pos_4++) { if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES) == FALSE) break; if (OrderSymbol() == Symbol() && OrderMagicNumber() == MagicNum) li_ret_0++; } return (li_ret_0); } void TrailStop(string a_symbol_0, int a_magic_8, double a_pips_12, double a_pips_20) { double l_price_28; if (a_pips_12 > 2.0 && a_pips_20 > 2.0) { for (int l_pos_36 = 0; l_pos_36 < OrdersTotal(); l_pos_36++) { if (OrderSelect(l_pos_36, SELECT_BY_POS) != FALSE) { if (OrderSymbol() != a_symbol_0 || OrderMagicNumber() != a_magic_8) continue; if (StringSubstr(OrderComment(), 0, 6) == "spec5o") { if (OrderType() == OP_BUY) { RefreshRates(); l_price_28 = Bid - a_pips_20 * Point; if (l_price_28 > OrderStopLoss()) { OrderModify(OrderTicket(), OrderOpenPrice(), l_price_28, OrderTakeProfit(), 0, White); Sleep(5000); } } if (OrderType() == OP_SELL) { RefreshRates(); l_price_28 = Ask + a_pips_20 * Point; if (l_price_28 < OrderStopLoss()) { OrderModify(OrderTicket(), OrderOpenPrice(), l_price_28, OrderTakeProfit(), 0, Gold); Sleep(5000); } } } else { if (OrderType() == OP_BUY) { RefreshRates(); l_price_28 = Bid - a_pips_12 * Point; if (l_price_28 > OrderStopLoss()) { OrderModify(OrderTicket(), OrderOpenPrice(), l_price_28, OrderTakeProfit(), 0, White); Sleep(5000); } } if (OrderType() == OP_SELL) { RefreshRates(); l_price_28 = Ask + a_pips_12 * Point; if (l_price_28 < OrderStopLoss()) { OrderModify(OrderTicket(), OrderOpenPrice(), l_price_28, OrderTakeProfit(), 0, Gold); Sleep(5000); } } } } } } }