
#property indicator_chart_window
extern int    font_size = 10;
extern color  ColorBull = DodgerBlue;
extern color  ColorBeer = Red;
extern string font_name = "Arial";
extern bool   Show_Only_larger_than_ATR = true;
extern int    ATRPeriod = 5;
extern double ATRMultiplier = 1;

extern bool SoundOn = true;
extern string SoundFile = "alert.wav";
extern bool AlertON=false;

//+------------------------------------------------------------------+
int start()
{
     datetime tc;
   double k=(WindowPriceMax()-WindowPriceMin())/20;
   for(int i=WindowFirstVisibleBar(); i>=0; i--)
   {
      double rs = (NormalizeDouble(Open[i],Digits)-NormalizeDouble(Close[i],Digits))/Point;
      double ATR = GetATRDaily(i)*ATRMultiplier;
      
      if ( Show_Only_larger_than_ATR && rs > ATR )
      {
      if (rs<0) {
           if ( i == 0)
           {
            tc = TimeCurrent();
           if (SoundOn) PlaySound(SoundFile);
           if (AlertON) Alert("Large BEAR candle","\n Time=",TimeToStr(tc,TIME_DATE)," ",TimeHour(tc),":",TimeMinute(tc),"\n Symbol=",Symbol()," Period=",Period());
          }
      
       drawtext(i, High[i]+k, DoubleToStr(rs*(-1)) + "/" + IntegerToString(ATR), ColorBull);
       }
       
      if (rs>0) 
      {
      drawtext(i, Low[i]-Point, DoubleToStr(rs,0)+ "/" + IntegerToString(ATR), ColorBeer);
            if  ( i == 0)
            {
             tc = TimeCurrent();
                if (SoundOn) PlaySound(SoundFile);
                if (AlertON) Alert("Large Bull candle","\n Date=",TimeToStr(tc,TIME_DATE)," ",TimeHour(tc),":",TimeMinute(tc),"\n Symbol=",Symbol()," Period=",Period());
            }
      }
     }
     
     if ( Show_Only_larger_than_ATR == false)
      {
       if (rs<0) drawtext(i, High[i]+k, DoubleToStr(rs*(-1),0), ColorBull);
      if (rs>0) drawtext(i, Low[i]-Point, DoubleToStr(rs,0), ColorBeer);
      
      
      }
   }
}
//+------------------------------------------------------------------+
int deinit()
{
   ObjectsDeleteAll(0,OBJ_TEXT);
   return(0);  
}
//+------------------------------------------------------------------+
int drawtext(int n, double Y1, string l,color c)
{
   string Name=TimeToStr(Time[n],TIME_DATE|TIME_MINUTES);
   ObjectDelete (Name);
   ObjectCreate (Name, OBJ_TEXT,0,Time[n],Y1,0,0,0,0);
   ObjectSetText(Name, l,font_size,font_name);
   ObjectSet    (Name, OBJPROP_COLOR, c);
}
//+------------------------------------------------------------------+

  
  //+------------------------------------------------------------------+
double GetATRDaily(int i)
  {
   
   //double adr= iATR(NULL, ATRTimeFrame, ATRPeriod, 1);
   //  "ADR " + DoubleToStr(MathRound((adr/Point)),0) + 
   //                        "  Today " + DoubleToStr(MathRound(((today_high-today_low)/Point)),0) ;
   //Should I show  (today range)/(ADR) ?
   datetime candletime = iTime(Symbol(),PERIOD_CURRENT,i);
   int index = iBarShift(Symbol(),PERIOD_D1,candletime);
   
   MqlRates rt;
   rt.high = iHigh(Symbol(),PERIOD_D1,index);
   rt.low  = iLow(Symbol(),PERIOD_D1,index);
   
   
                           
                           
   
   double point=getPoint(Symbol());
   double modifier=getModifier(Symbol());

   double adrdaily = iATR(Symbol(),PERIOD_D1,ATRPeriod, index);
  
   //double adrdaily       = MathRound(((rt.high-rt.low)/point*.1));
  
    return  adrdaily;
    
   
   
  }
  
    
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+

double getPoint(string symbol)
  {
   return MarketInfo(symbol,MODE_POINT);
  }
//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
double getModifier(string symbol)
  {
   int digits=(int)MarketInfo(symbol,MODE_DIGITS);
   double modifier=1;
   if(digits==3 || digits==5)
      modifier=10.0;
   return modifier;
  }  