*/extern double lTakeProfit = 40.0;extern double sTakeProfit = 40.0;extern double lTrailingStop = 20.0;extern double sTrailingStop = 10.0;extern color clOpenBuy = Blue;extern color clCloseBuy = Aqua;extern color clOpenSell = Red;extern color clCloseSell = Violet;extern color clModiBuy = Blue;extern color clModiSell = Red;extern string Name_Expert = "escape";extern int Slippage = 1;extern bool UseSound = TRUE;extern string NameFileSound = "Alert.wav";extern double Lots = 0.01;extern int bi = 2;void deinit() { Comment("");}int start() { if (Bars < 100) { Print("bars less than 100"); return (0); } if (lTakeProfit < 1.0) { Print("TakeProfit less than 1"); return (0); } if (sTakeProfit < 1.0) { Print("TakeProfit less than 1"); return (0); } double l_iclose_0 = iClose(NULL, PERIOD_M5, 0); double l_ima_8 = iMA(NULL, PERIOD_M5, 5, 0, MODE_SMA, PRICE_MEDIAN, 1); double l_iclose_16 = iClose(NULL, PERIOD_M5, 0); double l_ima_24 = iMA(NULL, PERIOD_M5, 4, 0, MODE_SMA, PRICE_MEDIAN, 1); if (AccountFreeMargin() < 1000.0 * Lots) { Print("We have no money. Free Margin = ", AccountFreeMargin()); return (0); } if (!ExistPositions()) { if (l_iclose_0 < l_ima_8) { OpenBuy(); return (0); } if (l_iclose_16 > l_ima_24) { OpenSell(); return (0); } } TrailingPositionsBuy(lTrailingStop); TrailingPositionsSell(sTrailingStop); return (0);}bool ExistPositions() { for (int l_pos_0 = bi; l_pos_0 < OrdersTotal(); l_pos_0++) { if (OrderSelect(l_pos_0, SELECT_BY_POS, MODE_TRADES)) if (OrderSymbol() == Symbol()) return (TRUE); } return (FALSE);}void TrailingPositionsBuy(int ai_0) { for (int l_pos_4 = bi; l_pos_4 < OrdersTotal(); l_pos_4++) { if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == Symbol()) { if (OrderType() == OP_BUY) { if (Bid - OrderOpenPrice() > ai_0 * Point) if (OrderStopLoss() < Bid - ai_0 * Point) ModifyStopLoss(Bid - ai_0 * Point); } } } }}void TrailingPositionsSell(int ai_0) { for (int l_pos_4 = bi; l_pos_4 < OrdersTotal(); l_pos_4++) { if (OrderSelect(l_pos_4, SELECT_BY_POS, MODE_TRADES)) { if (OrderSymbol() == Symbol()) { if (OrderType() == OP_SELL) { if (OrderOpenPrice() - Ask > ai_0 * Point) if (OrderStopLoss() > Ask + ai_0 * Point || OrderStopLoss() == 0.0) ModifyStopLoss(Ask + ai_0 * Point); } } } }}void ModifyStopLoss(double a_price_0) { int l_bool_8 = OrderModify(OrderTicket(), OrderOpenPrice(), a_price_0, OrderTakeProfit(), 0, CLR_NONE); if (l_bool_8 && UseSound) PlaySound(NameFileSound);}void OpenBuy() { double l_lots_0 = GetSizeLot(); double l_price_8 = 0; double l_price_16 = GetTakeProfitBuy(); string l_comment_24 = GetCommentForOrder(); OrderSend(Symbol(), OP_BUY, l_lots_0, Ask, Slippage, l_price_8, l_price_16, l_comment_24, 0, 0, clOpenBuy); if (UseSound) PlaySound(NameFileSound);}void OpenSell() { double l_lots_0 = GetSizeLot(); double l_price_8 = 0; double l_price_16 = GetTakeProfitSell(); string l_comment_24 = GetCommentForOrder(); OrderSend(Symbol(), OP_SELL, l_lots_0, Bid, Slippage, l_price_8, l_price_16, l_comment_24, 0, 0, clOpenSell); if (UseSound) PlaySound(NameFileSound);}string GetCommentForOrder() { return (Name_Expert);}double GetSizeLot() { return (Lots);}double GetTakeProfitBuy() { return (Ask + lTakeProfit * Point);}double GetTakeProfitSell() { return (Bid - sTakeProfit * Point);}