#property copyright "DREW"
#property link      "joinme@yandex.ru"

int TFbig = PERIOD_D1;
int TF = PERIOD_H1;

int init()
{
   return(0);
}

int deinit()
{
   return(0);
}

int start()
{
   int TH = TimeHour(iTime(NULL,TF,0));
   if(TH == 0 || TH == 4 || TH == 20) return(0);


   int total,cnt;
   total = OrdersTotal();
   for(cnt=0;cnt<total;cnt++)
   {  
      OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);         
      if(OrderType()==OP_BUY)
      {
         OrderClose(OrderTicket(), OrderLots(), Bid, 3, Yellow);
      }
      if(OrderType()==OP_SELL)
      {
         OrderClose(OrderTicket(), OrderLots(), Ask, 3, Yellow);
      }
   }


   double WPR,SAR;

   WPR = iWPR(NULL,TFbig,8,0);
   SAR = iSAR(NULL,TFbig,0.01,0.2,0);
   
   if(SAR < iClose(NULL,TFbig,0))
   {
      if(WPR > -50)
      {
         if((TH == 8 || TH == 12 || TH == 16) && (TimeMinute(iTime(NULL,TF,0)) == 0))
         {
            if(OrdersTotal() == 0)
            {
               OrderSend(Symbol(),OP_BUY,1,Ask,3,0,0,"",14774,0,Blue);
            }
         }
      }      
      if(WPR < -50)
      {
         if((TH == 8 || TH == 12 || TH == 16) && (TimeMinute(iTime(NULL,TF,0)) == 0))
         {
            if(OrdersTotal() == 0)
            {
               //OrderSend(Symbol(),OP_BUY,1,Ask,3,0,Ask+0.0010,"",14774,0,Blue);
               //OrderSend(Symbol(),OP_SELL,1,Bid,3,0,Bid-0.0010,"",14774,0,Red);
            }
         }
      }
   }

   if(SAR > iClose(NULL,TFbig,0))
   {
      if(WPR > -50)
      {
         if((TH == 8 || TH == 12 || TH == 16) && (TimeMinute(iTime(NULL,TF,0)) == 0))
         {
            if(OrdersTotal() == 0)
            {
               //OrderSend(Symbol(),OP_BUY,1,Ask,3,0,Ask+0.0010,"",14774,0,Blue);
               //OrderSend(Symbol(),OP_SELL,1,Bid,3,0,Bid-0.0010,"",14774,0,Red);
            }
         }
      }      
      if(WPR < -50)
      {
         if((TH == 8 || TH == 12 || TH == 16) && (TimeMinute(iTime(NULL,TF,0)) == 0))
         {
            if(OrdersTotal() == 0)
            {
               OrderSend(Symbol(),OP_SELL,1,Bid,3,0,0,"",14774,0,Red);
            }
         }
      }
   }

   return(0);
}



