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

extern int TF = PERIOD_H1;
extern int dDay = 0;

extern int nomln = 0;

int init()
{
   return(0);
}

int deinit()
{
   return(0);
}

int start()
{
   // 1 - BUY 2 - SELL
   // double fnAwesome(int TFloc, int shift)

   double LowestPrice = iLow(NULL,PERIOD_W1,0);
   int total, cnt;
   
   nomln++;
   double TrendLineBeginTime = Time[0];
   
   // 5
   int AW = fnAwesome(TF);
   if(AW == 2)
   {
      ObjectCreate("AW"+nomln,OBJ_ARROW,0,Time[0],LowestPrice-0.0048,0,0,0,0);
      ObjectSet("AW"+nomln, OBJPROP_ARROWCODE, 110);
      ObjectSet("AW"+nomln, OBJPROP_COLOR , Blue);

      total = OrdersTotal();
      for(cnt=0;cnt<total;cnt++)
      {  
         OrderSelect(cnt, SELECT_BY_POS, MODE_TRADES);         
         if(OrderType()==OP_SELL)
         {
            OrderClose(OrderTicket(), OrderLots(), Ask, 3, Yellow);
         }
      }
      
      if(OrdersTotal() == 0) OrderSend(Symbol(),OP_BUY,1,Ask,3,0,0,"",4444,0,Blue);     
   }
   if(AW == 1)
   {
      ObjectCreate("AW"+nomln,OBJ_ARROW,0,Time[0],LowestPrice-0.0048,0,0,0,0);
      ObjectSet("AW"+nomln, OBJPROP_ARROWCODE, 110);
      ObjectSet("AW"+nomln, OBJPROP_COLOR , Red);

      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(OrdersTotal() == 0) OrderSend(Symbol(),OP_SELL,1,Bid,3,0,0,"",4444,0,Red);      
   }
 
   return(0);
}

//렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁렁
// Indicator's procs

// 5. Awesome
// 1 - BUY
// 2 - SELL
int fnAwesome(int TFloc, int shift = 0)
{
   double Awe = iAO(NULL, TFloc, shift);
   double Awe1 = iAO(NULL, TFloc, shift - 1);
   
   if((Awe1 < Awe) && (MathAbs(Awe1 - Awe) > 0.003)) return(1);
   if((Awe1 > Awe) && (MathAbs(Awe1 - Awe) > 0.003)) return(2);
}


