#property copyright "Drew Nya"
#property link      "joinme@yandex.ru"

extern int       NPer = 5;
extern int       TP = 5;
extern int       iLot = 1;

extern int       TFrame = PERIOD_M15;

int init()
  {
      return(0);
  }

int deinit()
  {
      return(0);
  }

int start()
  {
      double maxNPrice = 0;
      double minNPrice = 0;
      double MA;
      int    total,cnt;
      int    i;
      
      minNPrice = Close[5];
      
      for(i=1; i<=NPer;i++)
      {
         if(maxNPrice < iClose(NULL, TFrame, i)) maxNPrice = iClose(NULL, TFrame, i);
      }
      for(i=1; i<=NPer;i++)
      {
         if(minNPrice > iClose(NULL, TFrame, i)) minNPrice = iClose(NULL, TFrame, i);
      }
      
      if((Hour() >= 10) && (Hour() <= 18))
      {
         if(OrdersTotal() == 0)
         {
            if(Close[0] > maxNPrice) OrderSend(Symbol(),OP_BUY,iLot,Ask,3,0,Ask+0.0010,"",2,0,Blue);
         }
         if(OrdersTotal() == 0)
         {
            if(Close[0] < minNPrice) OrderSend(Symbol(),OP_SELL,iLot,Bid,3,0,Bid-0.0010,"",1,0,Red);
         }
      }
      

      // close
      int prof;
      total = OrdersTotal();
      for(cnt=0;cnt<total;cnt++)
      {  
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);         
         
         prof = OrderProfit() / 10;
         if(OrderType()==OP_BUY)
         {
            if(prof >= TP)
            {
               OrderClose(OrderTicket(), OrderLots(), Bid, 3, Yellow);   
            }
         }
         if(OrderType()==OP_SELL)
         {
            if(prof >= TP)
            {
               OrderClose(OrderTicket(), OrderLots(), Ask, 3, Red);
            }
         }
      }


      double Frc = iForce(NULL,TFrame,5,MODE_SMA,PRICE_CLOSE,0);
      
      total = OrdersTotal();
      for(cnt=0;cnt<total;cnt++)
      {  
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);         
         if((OrderType()==OP_BUY) && (Frc < -2))
         {
            OrderClose(OrderTicket(), OrderLots(), Bid, 3, Yellow);   
         }
         if((OrderType()==OP_SELL) && (Frc > 2))
         {
            OrderClose(OrderTicket(), OrderLots(), Ask, 3, Red);
         }
      }


      return(0);
  }




