TrailingRevers

 

Я конечно не спец, но как прикрутить к этому советнику реверс, чтоб переворачивать позицию при СЛ и БУ один раз?

//+-------------------------------------------------------------------------------------------------------------------+
//|                                                 трейлинг стоп лосс                                                |
void T_SL() {
  int i=0;
  for(i=0; i<OrdersTotal(); i++) {
    if(!(OrderSelect(i, SELECT_BY_POS, MODE_TRADES))) continue;
    if(OrderSymbol() != Symbol()) continue;       

    if(OrderType()==OP_BUY) {
      if(NormalizeDouble(Bid-OrderOpenPrice(),Digits)>NormalizeDouble(TrailingStop*Point,Digits)) {
        if(NormalizeDouble(OrderStopLoss(),Digits)<NormalizeDouble(Bid-(TrailingStop+TrailingStep-1)*Point,Digits))
          OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Bid-TrailingStop*Point,Digits), OrderTakeProfit(), 0, CLR_NONE);
      } //end if(NormalizeDouble(Bid-OrderOpenPrice(),Digits)>NormalizeDouble(TrailingStop*Point,Digits))
    } //end if(OrderType()==OP_BUY)

    if(OrderType()==OP_SELL) {
      if(NormalizeDouble(OrderOpenPrice()-Ask,Digits)>NormalizeDouble(TrailingStop*Point,Digits)) {
        if(NormalizeDouble(OrderStopLoss(),Digits)>NormalizeDouble(Ask+(TrailingStop+TrailingStep-1)*Point,Digits))
          OrderModify(OrderTicket(), OrderOpenPrice(), NormalizeDouble(Ask+TrailingStop*Point,Digits), OrderTakeProfit(), 0, CLR_NONE);
      } //end if(NormalizeDouble(OrderOpenPrice()-Ask,Digits)>NormalizeDouble(TrailingStop*Point,Digits))
    } //end if(OrderType()==OP_SELL)
  } //end for(i=0; i<OrdersTotal(); i++)
} //end void T_SL()
//|                                                 трейлинг стоп лосс                                                |
//+-------------------------------------------------------------------------------------------------------------------+

//+-------------------------------------------------------------------------------------------------------------------+
//|                                                   главная функция                                                 |
void start() {
  double price = 0.0;
  if((Hour()==Hour_To_Open) && (Minute()==Minute_To_Open)) { //если настало время открытия сделок
    price = NormalizeDouble(Bid,Digits);
    for (int i=0; i<OrdersTotal(); i++){   
      if (OrderSelect(i,SELECT_BY_POS,MODE_TRADES)==true){
         if (OrderSymbol()==Symbol()){
            tip = OrderType();
            Lots = OrderLots();return;}}}
   if (Lots==0) return;
   if (tip==0) OrderSend(Symbol(),OP_SELL,Lots,Bid,3,NormalizeDouble(Ask + SL*Point,Digits),
                                    NormalizeDouble(Bid - TP*Point,Digits)," ",777,Blue);
   if (tip==1) OrderSend(Symbol(),OP_BUY ,Lots,Ask,3,NormalizeDouble(Bid - SL*Point,Digits),
                                    NormalizeDouble(Ask + TP*Point,Digits)," ",777,Blue);
  } //end if((Hour()==Hour_To_Open) && (Minute()==Minute_To_Open))
  
  T_SL();
  return;
} //end void start()
//|                                                   главная функция                                                 |
//+-------------------------------------------------------------------------------------------------------------------+
Вот скрипт реверса...Правда он наверно просто все переворачивает...

 

//+------------------------------------------------------------------+
//| Реверс                                                           |

void revers() {
  double Lots;
  int    op;
  for (int i=OrdersTotal()-1; i>=0; i--) {
    if (OrderSelect(i, SELECT_BY_POS, MODE_TRADES)) {
      if (OrderSymbol()==Symbol()) {
        op=OrderType();
        if (op==OP_BUY) {
          Lots=OrderLots();
          OrderClose(OrderTicket(),OrderLots(),Bid,7,CLR_NONE);
          OrderSend(Symbol(),OP_SELL,Lots,Bid,7,0,0,"Reverse",0,0,CLR_NONE);
        }
        if (op==OP_SELL) {
          Lots=OrderLots();
          OrderClose(OrderTicket(),OrderLots(),Ask,7,CLR_NONE);
          OrderSend(Symbol(),OP_BUY,Lots,Ask,7,0,0,"Reverse",0,0,CLR_NONE);
        }
      }
    }
  }
}
//+------------------------------------------------------------------+