//+------------------------------------------------------------------+
//|                                                      ОТЛОЖКИ.mq4 |
//+------------------------------------------------------------------+
extern double StopLoss     = 100; //Стоплосс ордера  
extern double TakeProfit   = 150; //Тейкпрофит ордера
extern double TrailingStop = 100; // трал 
extern int    Delta        = 100; //Расстояние от цены для установки ордера
extern double LOT          = 0.1; //Объём позиции
extern int    Magic        =2;
//+------------------------------------------------------------------+
//| expert start function                                            |
//+------------------------------------------------------------------+
int start()
  {
  if (TrailingStop!=0) Trailing(); 
  
   //ИНДИКАТОР RSI 
   double RSI0=iRSI(NULL,0,5,PRICE_CLOSE,0);
   double RSI1=iRSI(NULL,0,5,PRICE_CLOSE,1);
  
   int b,s,p,res; 
   double BuyPrice=Ask+Delta*Point; 
   double SellPrice=Bid-Delta*Point;
   
   for (int i=0; i<OrdersTotal(); i++)
    {
     if (OrderSelect(i, SELECT_BY_POS)==true)
      {  
        if (OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) p++;
        if (OrderType()==OP_BUYSTOP) b++;
        if (OrderType()==OP_SELLSTOP) s++;        
      }   
    }
      double SL,TP;
//---- buy stop
   if(RSI0>50&&RSI1<50) 
     {
           
      res=OrderSend(Symbol(),OP_BUYSTOP,LOT,BuyPrice,0,BuyPrice-StopLoss*Point,BuyPrice+TakeProfit*Point,"ОТЛОЖКИ",Magic,OP_SELLSTOP,Blue);
     }        
//---- sell stop  
   if(RSI0<50&&RSI1>50) 
     {
      res=OrderSend(Symbol(),OP_SELLSTOP,LOT,SellPrice,0,SellPrice+StopLoss*Point,SellPrice-TakeProfit*Point,"ОТЛОЖКИ",Magic,OP_BUYSTOP,Red );
     }
//---- buy stop делете
      if(RSI0<50&&RSI1>50)
    {
     OrderDelete( OrderTicket());
     
    }
//---- sell stop делете
      if(RSI0>50&&RSI1<50)
    {
     OrderDelete( OrderTicket());
     
    }
//----
   return(0);
  }
//--------------------------------------------------------------------
//---------ФУНКЦИЯ ТРАЛА----------------------------------------------
//--------------------------------------------------------------------
void Trailing()
{
   for(int i=0; i<OrdersTotal(); i++) 
     {
      if(OrderSelect(i,SELECT_BY_POS,MODE_TRADES))
      if(OrderSymbol()==Symbol()||OrderMagicNumber()==Magic)
       if(OrderType()==OP_BUY)
         {
          if(TrailingStop>0)  
            {                 
              if(Bid-OrderOpenPrice()>TrailingStop)
               {
                 if(OrderStopLoss()<Bid-TrailingStop)
                  {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Bid-TrailingStop,OrderTakeProfit(),0,Green);
                  }
               }
            }
         }
         
        if(OrderType()==OP_SELL)
         {
           if(TrailingStop>0)  
            {                 
              if((OrderOpenPrice()-Ask)>TrailingStop)
               {
                 if((OrderStopLoss()>(Ask+TrailingStop)) || (OrderStopLoss()==0))
                  {
                     OrderModify(OrderTicket(),OrderOpenPrice(),Ask+TrailingStop,OrderTakeProfit(),0,Red);
                  }
               }
            }
         }   
   }
}
//+------------------------------------------------------------------------------------+
//+------------------------------------------------------------------------------------+--------------------------------------------------------------------+ 
  сов открывает ордера пачками а надо всего 1 при пересечении индикатора.
  сов открывает ордера пачками а надо всего 1 при пересечении индикатора.
					        										int start()
  {
  if (TrailingStop!=0) Trailing(); 
  
   //ИНДИКАТОР RSI 
   double RSI0=iRSI(NULL,0,14,PRICE_CLOSE,0);
   double RSI1=iRSI(NULL,0,14,PRICE_CLOSE,1);
   
   int b,s,p,res; 
   double BuyPrice=Ask+Delta*Point; 
   double SellPrice=Bid-Delta*Point;
   
   for (int i=0; i<OrdersTotal(); i++)
    {
     if (OrderSelect(i, SELECT_BY_POS)==true)
      {  
        if (OrderSymbol()!=Symbol() || OrderMagicNumber()!=Magic) continue;
        if (OrderType()==OP_BUY || OrderType()==OP_SELL) p++;
        if (OrderType()==OP_BUYSTOP) b++;
        if (OrderType()==OP_SELLSTOP) s++;        
      }   
    }
      double SL,TP;
//---- buy stop делете
      if(RSI0<50&&RSI1>50)
    {
     OrderDelete(OP_BUYSTOP);
     
    }
//---- sell stop делете
      if(RSI0>50&&RSI1<50)
    {
     OrderDelete(OP_SELLSTOP);
     
    }
//---- buy stop
   if(RSI0>50&&RSI1<50) //&& Hour()==StartHour Close[1]-Open[1]>0  &&p<1 && b<1
     {
           
      res=OrderSend(Symbol(),OP_BUYSTOP,LOT,BuyPrice,0,BuyPrice-StopLoss*Point,BuyPrice+TakeProfit*Point,"ОТЛОЖКИ",Magic,OP_SELLSTOP,Blue);
     }        
//---- sell stop  
   if(RSI0<50&&RSI1>50) // && Hour()==StartHourOpen[1]-Close[1]>0  && p<1 && s<1
     {
      res=OrderSend(Symbol(),OP_SELLSTOP,LOT,SellPrice,0,SellPrice+StopLoss*Point,SellPrice-TakeProfit*Point,"ОТЛОЖКИ",Magic,OP_BUYSTOP,Red );
     }   
//----
   return(0);
  }
div15