Код:
//===================================================================== extern int Start1 = 10; extern int Start2 = 14; extern int EOD = 24; extern int FridayClosing = 23; extern bool FirstSessionOnly = FALSE; extern int Length = 4; extern int Pips = 5; extern int StopLoss = 50; extern int BreakEven = 30; extern int TrailingStop = 0; extern int LossPips = 0; extern int TakeProfit = 80; extern double Lots = 0.1; extern bool MM = TRUE; extern int LotsPercent = 10; //===================================================================== int gi_140; //===================================================================== int init() { gi_140 = StringGetChar(Symbol(), 0) + 77706 + StringGetChar(Symbol(), 1) << 1 + 3 * StringGetChar(Symbol(), 3) + StringGetChar(Symbol(), 4) << 2 + 10000 * Period(); HideTestIndicators(TRUE); return (0); } //===================================================================== int start() { double ld_0; string ls_8; if (MM) { if (LotsPercent > 0) Lots = NormalizeDouble(MathCeil(AccountFreeMargin() / 10000.0 * LotsPercent) / 10.0, 1); else Lots = ld_0; } if (EOD >= 24) EOD = 0; if (FridayClosing == 0) FridayClosing = 24; string ls_16 = "IDS_" + Symbol(); if (Hour() == Start1 && Minute() < 10) SetOrders(ls_16, 1); if (Hour() == Start2 && Minute() < 10 && !FirstSessionOnly) SetOrders(ls_16, 2); for (int $i = OrdersTotal() - 1; $i >= 0; $i--) { OrderSelect($i, SELECT_BY_POS); if (OrderComment() == ls_16) { if (Hour() == EOD || (DayOfWeek() >= 5 && Hour() == FridayClosing - 1 && Minute() >= 50)) { switch (OrderType()) { case OP_BUY: OrderClose(OrderTicket(), OrderLots(), Bid, 3, Red); break; case OP_SELL: OrderClose(OrderTicket(), OrderLots(), Ask, 3, Red); break; default: OrderDelete(OrderTicket()); } } else { if (LossPips > 0) { if (OrderType() == OP_BUY) if (OrderOpenPrice() - Bid >= LossPips * Point) OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), OrderOpenPrice(), 0, Green); if (OrderType() == OP_SELL) if (Ask - OrderOpenPrice() >= LossPips * Point) OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss(), OrderOpenPrice(), 0, Green); } if (TrailingStop == 0) { if (OrderType() == OP_BUY) if (High[0] - OrderOpenPrice() >= BreakEven * Point && OrderStopLoss() < OrderOpenPrice()) OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), 0, Green); if (OrderType() == OP_SELL) if (OrderOpenPrice() - Low[0] >= BreakEven * Point && OrderStopLoss() > OrderOpenPrice()) OrderModify(OrderTicket(), OrderOpenPrice(), OrderOpenPrice(), OrderTakeProfit(), 0, Green); } else { if (OrderType() == OP_BUY) if (High[0] - OrderStopLoss() >= (StopLoss + TrailingStop) * Point) OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss() + TrailingStop * Point, OrderTakeProfit(), 0, Green); if (OrderType() == OP_SELL) if (OrderStopLoss() - Low[0] >= (StopLoss + TrailingStop) * Point) OrderModify(OrderTicket(), OrderOpenPrice(), OrderStopLoss() - TrailingStop * Point, OrderTakeProfit(), 0, Green); } } } } return (0); } //===================================================================== void SetOrders(string a_comment_0, int a_magic_8) { int l_ticket_12; int l_count_16 = 0; int l_count_20 = 0; double ld_24 = iHigh(NULL, PERIOD_H1, iHighest(NULL, PERIOD_H1, MODE_HIGH, Length, 1)) + Pips * Point; double ld_32 = iLow(NULL, PERIOD_H1, iLowest(NULL, PERIOD_H1, MODE_LOW, Length, 1)) - Pips * Point; double l_price_40 = MathMax(ld_24 - StopLoss * Point, ld_32); double l_price_48 = MathMin(ld_32 + StopLoss * Point, ld_24); double l_price_56 = ld_24 + TakeProfit * Point; double l_price_64 = ld_32 - TakeProfit * Point; for (int l_pos_72 = 0; l_pos_72 < OrdersTotal(); l_pos_72++) { OrderSelect(l_pos_72, SELECT_BY_POS, MODE_TRADES); if (OrderComment() == a_comment_0 && OrderMagicNumber() == a_magic_8) { if (OrderType() == OP_BUYSTOP || OrderType() == OP_BUY) l_count_16++; if (OrderType() == OP_SELLSTOP || OrderType() == OP_SELL) l_count_20++; } } if (l_count_16 == 0) { l_ticket_12 = OrderSend(Symbol(), OP_BUYSTOP, Lots, ld_24, 3, l_price_40, l_price_56, a_comment_0, a_magic_8, 0, Green); if (l_ticket_12 < 0 && GetLastError() == 130/* INVALID_STOPS */) l_ticket_12 = OrderSend(Symbol(), OP_BUY, Lots, Ask, 3, l_price_40, l_price_56, a_comment_0, a_magic_8, 0, Green); } if (l_count_20 == 0) { l_ticket_12 = OrderSend(Symbol(), OP_SELLSTOP, Lots, ld_32, 3, l_price_48, l_price_64, a_comment_0, a_magic_8, 0, Green); if (l_ticket_12 < 0 && GetLastError() == 130/* INVALID_STOPS */) l_ticket_12 = OrderSend(Symbol(), OP_SELL, Lots, Bid, 3, l_price_48, l_price_64, a_comment_0, a_magic_8, 0, Green); } }
1. Код выкладываю как есть, без правки.
2. В коде могут быть ошибки (наверное).
3. Сообщите результаты (тесты или ...)
Отредактировано Andy_Kon (2008-12-30 17:22:51)