Код:
extern string Comm = "Calculated time of first channel"; extern int sChannel = 1; extern int dChannel = 8; extern string Comm2 = "Calculated time of second channel"; extern int sChannel1 = 8; extern int dChannel1 = 14; extern int Pips = 5; extern int TakeProfit = 148; extern int StopLoss = 28; extern int Slippage = 3; extern int TralStep = 4; extern int TimeClose = 0; extern int LotsWayChoice = 1; extern double Lots = 0.1; extern int LotsPercent = 10; extern int MM_Delta = 1000; extern int MAGIC = 4567; extern string Comm3 = "ScalperGuru System"; bool gi_164 = TRUE; int gi_168 = 0; bool gi_172 = FALSE; bool gi_176 = FALSE; int gi_unused_180; int g_ticket_184 = 0; //------------------------------------------------------------------------------ int init() { gi_unused_180 = 0; return (0); } //------------------------------------------------------------------------------ int start() { int l_pos_8 = 0; if (Period() != PERIOD_H1) { Alert("Timeframe Н1"); return (0); } int l_ord_total_12 = GetOrdersCount(); if (l_ord_total_12 < 0) return (0); if (l_ord_total_12 == 0) { if (AccountFreeMargin() < 1500.0 * Lots) { Alert("Not enough money on deposit"); return (0); } gi_168 = FALSE; gi_172 = FALSE; gi_176 = FALSE; } double ld_16 = 0.0; double ld_24 = 0.0; double l_price_32 = 0.0; double l_price_40 = 0.0; if (gi_168 == FALSE && gi_172 == FALSE) { if (TimeHour(TimeCurrent()) + TimeClose == dChannel && sChannel > -1) { ld_16 = NormalizeDouble(High[iHighest(Symbol(), Period(), MODE_HIGH, dChannel - sChannel + 1, 0)], Digits); ld_24 = NormalizeDouble(Low[iLowest(Symbol(), Period(), MODE_LOW, dChannel - sChannel + 1, 0)], Digits); g_ticket_184 = OrderSend(Symbol(), OP_BUYSTOP, GetSizeLot(), ld_16 + Pips * Point, Slippage, 0, 0, "", MAGIC, 0, Red); if (OrderSelect(g_ticket_184, SELECT_BY_TICKET) == TRUE) { if (StopLoss > 0) l_price_32 = OrderOpenPrice() - StopLoss * Point; if (TakeProfit > 0) l_price_40 = OrderOpenPrice() + TakeProfit * Point; OrderModify(OrderTicket(), OrderOpenPrice(), l_price_32, l_price_40, 0, Green); g_ticket_184 = OrderSend(Symbol(), OP_SELLSTOP, GetSizeLot(), ld_24 - Pips * Point, Slippage, 0, 0, "", MAGIC, 0, Red); if (OrderSelect(g_ticket_184, SELECT_BY_TICKET) == TRUE) { if (StopLoss > 0) l_price_32 = OrderOpenPrice() + StopLoss * Point; if (TakeProfit > 0) l_price_40 = OrderOpenPrice() - TakeProfit * Point; OrderModify(OrderTicket(), OrderOpenPrice(), l_price_32, l_price_40, 0, Green); } } gi_172 = TRUE; gi_168 = TRUE; } } if (TimeHour(TimeCurrent()) + TimeClose == dChannel1 && sChannel1 > -1) { if (gi_176 == FALSE) { l_ord_total_12 = OrdersTotal(); for (l_pos_8 = l_ord_total_12 - 1; l_pos_8 >= 0; l_pos_8--) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == MAGIC) if (OrderType() != OP_BUY && OrderType() != OP_SELL) OrderDelete(OrderTicket()); } ld_16 = NormalizeDouble(High[iHighest(Symbol(), Period(), MODE_HIGH, dChannel1 - sChannel1 + 1, 0)], Digits); ld_24 = NormalizeDouble(Low[iLowest(Symbol(), Period(), MODE_LOW, dChannel1 - sChannel1 + 1, 0)], Digits); g_ticket_184 = OrderSend(Symbol(), OP_BUYSTOP, GetSizeLot(), ld_16 + Pips * Point, Slippage, 0, 0, "", MAGIC, 0, Red); if (OrderSelect(g_ticket_184, SELECT_BY_TICKET) == TRUE) { if (StopLoss > 0) l_price_32 = OrderOpenPrice() - StopLoss * Point; if (TakeProfit > 0) l_price_40 = OrderOpenPrice() + TakeProfit * Point; OrderModify(OrderTicket(), OrderOpenPrice(), l_price_32, l_price_40, 0, Green); g_ticket_184 = OrderSend(Symbol(), OP_SELLSTOP, GetSizeLot(), ld_24 - Pips * Point, Slippage, 0, 0, "", MAGIC, 0, Red); if (OrderSelect(g_ticket_184, SELECT_BY_TICKET) == TRUE) { if (StopLoss > 0) l_price_32 = OrderOpenPrice() + StopLoss * Point; if (TakeProfit > 0) l_price_40 = OrderOpenPrice() - TakeProfit * Point; OrderModify(OrderTicket(), OrderOpenPrice(), l_price_32, l_price_40, 0, Green); } } gi_176 = TRUE; } } if (TralStep > 0 && StopLoss > 0) { l_ord_total_12 = OrdersTotal(); for (l_pos_8 = l_ord_total_12 - 1; l_pos_8 >= 0; l_pos_8--) { OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == MAGIC) { if (OrderType() == OP_BUY) if (Bid - OrderStopLoss() > (StopLoss + TralStep) * Point) OrderModify(OrderTicket(), OrderOpenPrice(), Bid - StopLoss * Point, OrderTakeProfit(), 0, Green); if (OrderType() == OP_SELL) if (OrderStopLoss() - Ask > (StopLoss + TralStep) * Point) OrderModify(OrderTicket(), OrderOpenPrice(), Ask + StopLoss * Point, OrderTakeProfit(), 0, Green); } } } if (TimeHour(TimeCurrent()) == 0) CloseAll(); return (0); } //------------------------------------------------------------------------------ void CloseAll() { int l_ord_total_0 = OrdersTotal(); for (int l_pos_4 = l_ord_total_0 - 1; l_pos_4 >= 0; l_pos_4--) { OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES); if (OrderMagicNumber() == MAGIC) { if (OrderType() == OP_BUY) OrderClose(OrderTicket(), OrderLots(), Bid, Slippage, Blue); else { if (OrderType() == OP_SELL) OrderClose(OrderTicket(), OrderLots(), Ask, Slippage, Blue); else OrderDelete(OrderTicket()); } } } gi_172 = FALSE; gi_176 = FALSE; } //------------------------------------------------------------------------------ int GetOrdersCount() { int l_count_0 = 0; int l_ord_total_4 = OrdersTotal(); for (int l_pos_8 = 0; l_pos_8 < l_ord_total_4; l_pos_8++) { if (OrderSelect(l_pos_8, SELECT_BY_POS, MODE_TRADES) == FALSE) return (-1); if (OrderMagicNumber() == MAGIC) l_count_0++; } return (l_count_0); } //------------------------------------------------------------------------------ double GetSizeLot() { double ld_0; int li_8; if (LotsWayChoice == 0) ld_0 = Lots; if (LotsWayChoice == 1) ld_0 = MathCeil(AccountFreeMargin() / 10000.0 * LotsPercent) / 10.0; if (LotsWayChoice == 2) { li_8 = MathRound(AccountFreeMargin() / MM_Delta); ld_0 = li_8 * Lots; } if (ld_0 < MarketInfo(Symbol(), MODE_MINLOT)) ld_0 = MarketInfo(Symbol(), MODE_MINLOT); if (ld_0 > MarketInfo(Symbol(), MODE_MAXLOT)) ld_0 = MarketInfo(Symbol(), MODE_MAXLOT); return (NormalizeDouble(ld_0, 1)); }
1. Код выкладываю как есть, без правки.
2. В коде могут быть ошибки (наверное).
3. Сообщите результаты (тесты или ...)
Отредактировано Andy_Kon (2008-12-30 17:23:23)