//+------------------------------------------------------------------+
//|                                                AAR-indicator.mq4 |
//+------------------------------------------------------------------+
#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Lime
#property indicator_color2 OrangeRed
#property indicator_width1 1
#property indicator_width2 1

extern int  JawsPeriod=13;
extern int  JawsShift=8;
extern int  TeethPeriod=8;
extern int  TeethShift=5;
extern int  LipsPeriod=5;
extern int  LipsShift=3;
extern int  TypeMA=MODE_SMMA;
extern int  TypePrice=PRICE_MEDIAN;

//---- buffers
double OscBufferBuy[];
double OscBufferSell[];
//------------
int init()
  {
   SetIndexStyle(0,DRAW_ARROW);
   SetIndexBuffer(0,OscBufferBuy);
   SetIndexArrow(0,233);
   SetIndexStyle(1,DRAW_ARROW);
   SetIndexBuffer(1,OscBufferSell);
   SetIndexArrow(1,234);

   IndicatorShortName("m_AAR+");
   return(0);
  }
//+------------------------------------------------------------------+
int deinit()
  {
   return(0);
  }
//+------------------------------------------------------------------+
int start()
  {
   int counted_bars=IndicatorCounted();
   int limit;
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;

   int trend=0;
   int razvorot=0;
   double delta=0;

   for(int i=0; i<limit; i++)
     {
      double jaw=iAlligator(NULL,0,JawsPeriod,JawsShift,TeethPeriod,TeethShift,LipsPeriod,LipsShift,TypeMA,TypePrice,MODE_GATORJAW,i);
      double lips=iAlligator(NULL,0,JawsPeriod,JawsShift,TeethPeriod,TeethShift,LipsPeriod,LipsShift,TypeMA,TypePrice,MODE_GATORLIPS,i);
      double high1=iHigh(NULL,0,i+1);
      double low1=iLow(NULL,0,i+1);
      double close1=iClose(NULL,0,i+1);
      double close0=iClose(NULL,0,i);

      OscBufferBuy[i]=0;
      OscBufferSell[i]=0;

      if(lips>jaw)trend=1;
      if(lips<jaw)trend=-1;

      if(close1>(high1+low1)/2.0)razvorot=1;
      if(close1<(high1+low1)/2.0)razvorot=-1;

      if(trend==1)delta=close0-lips;
      if(trend==-1)delta=lips-close0;

      if(close0<lips&&trend==-1&&razvorot==1&&close0>high1) OscBufferBuy[i]=Low[i]-(10*Point);
      if(close0>lips&&trend==1&&razvorot==-1&&close0<low1) OscBufferSell[i]=High[i]+(10*Point);
     }
   return(0);
  }
//+------------------------------------------------------------------+
