//coded by sangmane
#property indicator_separate_window
#property indicator_buffers 1
#property indicator_color1 DodgerBlue
#property indicator_minimum 0
//---- input parameters
extern int MaPeriod=50;
//---- buffers
double Buffer[];
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
   IndicatorDigits(Digits+1);
//---- indicator line
   SetIndexStyle(0,DRAW_LINE);
   SetIndexBuffer(0,Buffer);
//----
   return(0);
  }

int start()
  {
   int i,limit, counted_bars=IndicatorCounted();
   if(counted_bars>0) counted_bars--;
   limit=Bars-counted_bars;
   for(i=limit; i>=0; i--)
     {
      double ma=iMA(NULL,0,MaPeriod,0,MODE_EMA,PRICE_CLOSE,i);
      double xma=iMA(NULL,0,MaPeriod,0,MODE_EMA,PRICE_CLOSE,i+1);
      if((Close[i]-ma)*(Close[i+1]-xma)<0) Buffer[i] = 0;
      else  Buffer[i] = Buffer[i+1]+1;
     }
   return(0);
  }
//+------------------------------------------------------------------+