#property copyright "Copyright © 2008, cjatradingtools.com"
#property link      "http://cjatradingtools.com/"
#property indicator_chart_window

extern int Period  = 20;
extern double multiplier = 1.0;
extern int Font_size = 10;
extern color Title_col = White;
extern color Label_col = Tomato;
extern int   Shift_X = 10;
extern int   Shift_Y = 10;
extern int Corner = 1;

int deinit()
  {
   DeleteLabels();
   return(0);
  }

int start()
  { 
   int AV=0; 
   int i=0;   
   for(i=1;i<=Period;i++)
   AV =  AV +  (iHigh(NULL,Period(),i)-iLow(NULL,Period(),i))/Point/10;        
   AV = AV/Period;
   
   int a,b;
   if (Corner==1 || Corner==3) {a=Shift_X+Font_size*7; b=Shift_X;}
   if (Corner==0 || Corner==2) {a=Shift_X; b=Shift_X+Font_size*7;}
  
   CreateAverage( "AV1",10+Shift_Y, a);
   ObjectSetText("AV1","ATR" + "" "(" + Period +")" + " =", Font_size,"Arial Bold",Title_col);      
   CreateAverage( "AV2",10+Shift_Y, b);
   ObjectSetText("AV2",DoubleToStr(AV*multiplier,0)+" (x"+DoubleToStr(multiplier,1)+")", Font_size,"Arial Bold",Label_col); 
   
   return(0);
  }
   
int CreateAverage( string n, int Shift_Y, int Shift_X ) 
  {
   ObjectCreate( n, OBJ_LABEL,0, 0, 0 );
   ObjectSet( n, OBJPROP_CORNER, Corner );
   ObjectSet( n, OBJPROP_XDISTANCE,Shift_X);
   ObjectSet( n, OBJPROP_YDISTANCE,Shift_Y);
   ObjectSet( n, OBJPROP_BACK, false );
  }
   
void DeleteLabels()
  {   
   ObjectDelete("AV1");ObjectDelete("AV2");   
  }
