#property indicator_chart_window
#property indicator_buffers 1
#property indicator_color1 Red

extern double prox=100;
extern int maperiod=10;



double ma_value[];
double mainbuffer[];

int init(){
IndicatorBuffers(2);
SetIndexStyle(0,DRAW_LINE);
SetIndexBuffer(0,mainbuffer);
SetIndexBuffer(1,ma_value);
return(0);}

int start(){
   int counted_bars=IndicatorCounted();
      if (counted_bars<0) return(-1);
      if (counted_bars>0) counted_bars--;
          int limit = MathMin(Bars-counted_bars,Bars-1);

   for(int i=limit; i>=0; i--)
{
   ma_value[i]= iMA(NULL,0,maperiod,0,MODE_EMA,PRICE_CLOSE,i);
      double diff = ma_value[i]-Close[i] ;
      if(MathAbs(diff)<=(double)prox*_Point)
            mainbuffer[i]=ma_value[i];
      else  mainbuffer[i]=EMPTY_VALUE;            
   }
   return(0);
}











