//+------------------------------------------------------------------+
//|                                          Momentum Candles v1.mq4 |
//|                                                              cja |
//+------------------------------------------------------------------+

#property indicator_chart_window
#property indicator_buffers 2
#property indicator_color1 Aqua
#property indicator_color2 Aqua
#property indicator_width1 3
#property indicator_width2 3

extern int candle_pipvalue = 0;
extern int hilow_pipvalue  = 15;

extern bool WaitForCandleClose = true;
extern bool SoundAlert = true;

int IndexOffset = 0;
datetime LastAlertTime;
double buffer1[];
double buffer2[];


double myPoint;
   double SetPoint() 
   { double mPoint; 
   if (Digits < 5) 
   mPoint = 0.001; 
   else
   mPoint = 0.00001; 
   return(mPoint); 
   } 

int init() {
   if (WaitForCandleClose)
   {
      IndexOffset = 0;
   }
   else
   {
      IndexOffset = 1;
   }
   myPoint = SetPoint();
   IndicatorBuffers(2);
   SetIndexBuffer(0, buffer1);     
   SetIndexStyle(0, DRAW_HISTOGRAM);   
   SetIndexBuffer(1, buffer2);     
   SetIndexStyle(1, DRAW_HISTOGRAM);  
   IndicatorShortName("Small Candle");
   return(0);
}
int deinit() { Comment(""); return(0);}
     
int start() {
   int counted_bars=IndicatorCounted();
   if(counted_bars < 0) 
       return(-1);
   if(counted_bars > 0) 
       counted_bars--;
       
   int limit = Bars - counted_bars;     
   for(int i = limit; i >= 0; i--) {

      int shift = iBarShift(Symbol(), 0, Time[i], true);     
      buffer2[i] = 0;
      buffer1[i] = 0;      
      double close = iClose(Symbol(),0,shift);
      double open  = iOpen(Symbol(),0,shift);
      double high  = iHigh(Symbol(),0,shift);
      double low   = iLow(Symbol(),0,shift);
         
      if(open > close && (open-close)>=candle_pipvalue*myPoint && (high-low)<=hilow_pipvalue*myPoint) {
         buffer2[i] = close;      
         buffer1[i] = open; 
                          {
            if (SoundAlert && LastAlertTime < Time[0])
            {
               Alert(Symbol()+" Small Candle ");
               LastAlertTime = Time[0];
            }
         }
      }
      if(open < close && (close-open)>=candle_pipvalue*myPoint && (high-low)<=hilow_pipvalue*myPoint) {       
         buffer2[i] = close;
         buffer1[i] = open;   
                          {
            if (SoundAlert && LastAlertTime < Time[0])
            {
               Alert(Symbol()+" Small Candle ");
               LastAlertTime = Time[0];
            }
         }            
      }
    } 
   return(0);
 }

