
//+------------------------------------------------------------------+
//|                                                   mn MA % Move   |
//+------------------------------------------------------------------+

#property  copyright "Mn"
#property  link      ""
#property indicator_separate_window
#property indicator_buffers 2
#property indicator_color1 Blue  
#property indicator_color2 Red  

extern int mPrd    = 50;
extern int mMethod = 1;    // 0=SMA, 1=EMA, 2=SmMA, 3= LWMA
extern int mPrice  = 0;    // 0=Close, 1=Open, 2=High, 3=Low, 4=Median
extern double mPercentMove = 1.0;

double MaMove[], MaMoveDown[];

//+------------------------------------------------------------------+
int init()
{
   SetIndexBuffer(0, MaMove);
   SetIndexStyle(0,DRAW_HISTOGRAM, 0, 2, Blue); 
   SetIndexLabel(0, NULL);
 
   SetIndexBuffer(1, MaMoveDown);
   SetIndexStyle(1,DRAW_HISTOGRAM, 0, 2, Red); 
   SetIndexLabel(1, NULL);
   
   mPercentMove = mPercentMove /100;
   return (0);
}

//+------------------------------------------------------------------+
int deinit()
{
   return (0);
}

//+------------------------------------------------------------------+
int start()
{
   double mMa = 0.0;
   datetime mAlertTime;
   
   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--)
   {
     mMa = iMA(NULL, 0, mPrd, 0, mMethod, mPrice, i);
      
     if(Close[i] <= mMa + Close[i] * mPercentMove && Close[i] >= mMa - Close[i] * mPercentMove)
       {
         MaMove[i] = 0;
         MaMoveDown[i] = 0;
       } 
     else 
       if(Close[i] >= mMa + Close[i] * mPercentMove)
        {
          MaMove[i] = 1;
          MaMoveDown[i] = 0;
        }
       else
        if(Close[i] <= mMa - Close[i] * mPercentMove)
         {
           MaMoveDown[i] = 1; 
           MaMove[i] = 0;     
         }
     }

   return (0);
}

//+------------------------------------------------------------------+

