A code for the ADR filter to trade only during good volatility :

Extern :

Code:
extern int MinimumADR        = 80;
Before init :

Code:
int    LastBars0=0;

bool ExcludeSundayData=true;
int ATR1_Prd=5,ATR2_Prd=25;
double RoomLimitRatio=0.2;
After start :

Code:
int Bars0=Bars;
   if(Bars0>LastBars0){

      int atr1,atr2;
      atr1=MathRound(iATR(NULL,0,ATR1_Prd,1)/point);
      atr2=MathRound(iATR(NULL,0,ATR2_Prd,1)/point);

      int n=1;
      static int adr1,adr5,adr10,adr20,adr;
      double s=0.0;
      for(int m=1;m<=20;m++){
         while(ExcludeSundayData && TimeDayOfWeek(iTime(NULL,PERIOD_D1,n))==0)n++;
         s=s+(iHigh(NULL,PERIOD_D1,n)-iLow(NULL,PERIOD_D1,n))/point;
         if(m==1)adr1=MathRound(s);
         if(m==5)adr5=MathRound(s/5);
         if(m==10)adr10=MathRound(s/10);
         if(m==20)adr20=MathRound(s/20);
         n++;  
      }  
      adr=MathRound((adr1+adr5+adr10+adr20)/4.0);
      LastBars0=Bars0;
   }
In entry conditions :

Code:
adr>=MinimumADR