//+------------------------------------------------------------------+
//|                                                 Original by Amir |
//|                      modded my mn to give alert                  |
//+------------------------------------------------------------------+
#property copyright ""

#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Green
#property indicator_color2 Red

extern double       BoxSize = 1.5;

double ExtMapBuffer1[];
double ExtMapBuffer2[];
   int KirUp=0;
   int KirDn=0;
   int kr=0;
   int no=0;

//+------------------------------------------------------------------+
int init()
  {
   if(Digits == 3 || Digits == 5)
     BoxSize *= 10;

   SetIndexStyle(0, DRAW_HISTOGRAM);
   SetIndexBuffer(0, ExtMapBuffer1);
   SetIndexLabel(0, "XOUP");
   SetIndexStyle(1, DRAW_HISTOGRAM);
   SetIndexBuffer(1, ExtMapBuffer2);
   SetIndexLabel(1, "XODOWN");
   IndicatorDigits(0);
   IndicatorShortName("I-XO-A-H");

   return(0);
  }

//+------------------------------------------------------------------+
int deinit()
  {
   
   return(0);
  }

//+------------------------------------------------------------------+
int start()
  {
   int CurrentBar;
   double Hi, Lo;
   int    counted_bars=IndicatorCounted();
   static int mTime;

   for(int i = 0; i <= Bars; i++)
   {
      CurrentBar = Bars -i;
      
      if (Close[CurrentBar] > (Hi + BoxSize * Point))
      {
         Hi = Close[CurrentBar];
         Lo = Close[CurrentBar] - BoxSize * Point;
         kr += 1;
         no = 0;   
      }
      
      if (Close[CurrentBar] < (Lo - BoxSize * Point))
      {
         Lo = Close[CurrentBar];
         Hi = Close[CurrentBar] + BoxSize * Point;
         no -= 1;
         kr = 0;
      }

      ExtMapBuffer1[CurrentBar] = kr;
      ExtMapBuffer2[CurrentBar] = no;
      
      if(Time[0] > mTime)
        {
            if((ExtMapBuffer1[1] == 1) && ExtMapBuffer1[2] == 0)
              Alert(Symbol(), "  UP ");
            if((ExtMapBuffer2[1] < 0) && ExtMapBuffer2[2] >= 0)
              Alert(Symbol(), "  DOWN");
            mTime = Time[0];
        }
      
   }

   return(0);
  }
//+------------------------------------------------------------------+