//+------------------------------------------------------------------+
//|                                                                  |
//|                                          TAN Arrows
//+------------------------------------------------------------------+
#property copyright ""
#property link       ""
#property indicator_chart_window
#property indicator_buffers 4
#property indicator_color1 clrGreen
#property indicator_color2 clrCornflowerBlue
#property indicator_color3 clrCornflowerBlue
#property indicator_color4 clrGreen
// #property indicator_color5 Magenta  
// #property indicator_color6 Lime

#property strict
//----
extern string Bollinger_Band_Settings;
extern int period = 20;
extern int Deviations = 2;
extern string AppliedOptions ="0=Close, 1=Open, 2=High";
extern string AppliedOptions2 ="3=Low, 4=Typical, 5=Weighted Close";
extern int AppliedTo = 4;
extern int Shift = 0;
extern bool ShowBands=true;
extern bool SoundAlert=TRUE;
extern bool SendEmail=false;
extern bool Sendnotification=false;



//----
double upper[];
double lower[];
double downArrow[];
double upArrow[];


   
datetime prevtime1=0;

//----
int OnInit()
  {
   SetIndexBuffer(0,upper);
   SetIndexStyle( 0,DRAW_LINE);
   SetIndexLabel( 0,"UpperAbove Bollinger Band");
//----
   SetIndexBuffer(1,lower);
   SetIndexStyle( 1,DRAW_LINE);
   SetIndexLabel( 1,"Lower Bollinger Band");
//----
   SetIndexBuffer(2,downArrow);
   SetIndexArrow (2,234);
   SetIndexStyle( 2,DRAW_ARROW,EMPTY,3,clrMagenta);
   SetIndexLabel(2,"Bollinge Band Upper Re-Entry");
//----
   SetIndexBuffer(3,upArrow);
   SetIndexStyle( 3,DRAW_ARROW,EMPTY,3,clrLime);
   SetIndexArrow (3,233);
   SetIndexLabel(3,"Bollinge Band Lower Re-Entry");
   
   
//      
//    SetIndexDrawBegin(0,0);
//    SetIndexDrawBegin(1,0);
//    
//    
//  upper[0]=EMPTY_VALUE;
//  lower[0]=EMPTY_VALUE;

   
   
   return(INIT_SUCCEEDED);
  }
//----
int OnCalculate (const int rates_total,      // size of input time series
                 const int prev_calculated,  // bars handled in previous call
                 const datetime& time[],     // Time
                 const double& open[],       // Open
                 const double& high[],       // High
                 const double& low[],        // Low
                 const double& close[],      // Close
                 const long& tick_volume[],  // Tick Volume
                 const long& volume[],       // Real Volume
                 const int& spread[])         // Spread

{
   int counted_bars=0;
   if(counted_bars>0) counted_bars--;
   int limit=Bars-counted_bars-1;
   Comment(limit);
   for(int i = 0;i<limit;i++){
      double UPAbove    =iCustom(NULL,0,"TANDraw",period,0,i);
      double LOBelow    =iCustom(NULL,0,"TANDraw",period,1,i);
 


 if(ShowBands){
 upper[i]=UPAbove;
 lower[i]=LOBelow;
 }
   
 if(Close[i+1] > UPAbove){
 downArrow[i]= High[i]; 
 
if(prevtime2 != Time[1]) {
prevtime2 = Time[1];
if(i==1 && SoundAlert)Alert("Sell Signal");
  }
 }
else if(Close[i+1] < LOBelow){
  upArrow[i]= Low[i];
  
if(prevtime2 != Time[1]) {
prevtime2 = Time[1];
if(i==1 && SoundAlert)Alert("Buy Signal");
 }
 }
 }//end of for loop
   
   return(rates_total);
}
//+------------------------------------------------------------------+
