//+------------------------------------------------------------------+
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
// 
#property copyright ""
#property link      ""

#property indicator_chart_window
#property indicator_buffers    2
#property indicator_color1     DodgerBlue
#property indicator_color2     Red

#property indicator_width1     1
#property indicator_width2     1



  


double buffer1[];
double buffer2[];
double buffer3[];

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

int init()
{
      IndicatorBuffers(3); 
      SetIndexStyle(0,DRAW_ARROW);  SetIndexArrow(0, 241); SetIndexEmptyValue(0, EMPTY_VALUE);
      SetIndexStyle(1,DRAW_ARROW);  SetIndexArrow(1, 242); SetIndexEmptyValue(1, EMPTY_VALUE);

   
   SetIndexBuffer(0,buffer1);
   SetIndexBuffer(1,buffer2);
   SetIndexBuffer(2,buffer3);

//   IndicatorShortName(" " );  
//   SetIndexLabel(0," ");



   return(0);
}
int deinit()
{
   return(0);
}

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+



int start()
{
   int counted_bars=IndicatorCounted();
   int limit,i;
   
   if(counted_bars<0) return(-1);
   if(counted_bars>0) counted_bars--;
           limit=Bars-counted_bars;


   for(i=limit; i>=0; i--)
   {
    
         double       ao0=iAO(NULL,0,i);
         double       ao1=iAO(NULL,0,i+1);
         double       ac0=iAC(NULL,0,i);
         double       ac1=iAC(NULL,0,i+1);
       
         bool acaoup=0,acaodn=0;
         
            if (ao0>ao1 &&ac0>ac1)acaoup=1;
            if (ao0<ao1 &&ac0<ac1)acaodn=1;
            
            

   //  double  atr =1.5* iATR(NULL,0,20,i);
  
      double stdiv0  = 2*iStdDev(NULL,0,20,0,0,0,i); 
      double stdiv1  = 2*iStdDev(NULL,0,20,0,0,0,i+1); 
   
         bool stdvup=0;
         
            if (stdiv0>stdiv1)stdvup=1;    //&&stdiv0>atr
 
 
            
            
            buffer1[i]  = EMPTY_VALUE;     buffer2[i]  = EMPTY_VALUE;

    
         if (acaoup && stdvup)buffer3[i]  = 1;
         else
         if (acaodn && stdvup)buffer3[i]  =-1;
             
         else                 buffer3[i]  = buffer3[i+1];




     if (buffer3[i]== 1 && buffer3[i+1]!= 1) buffer1[i] = Low[i];
     if (buffer3[i]==-1 && buffer3[i+1]!=-1) buffer2[i] = High[i];

   
   
   
   
   
  }
   
   return(0);
}


