#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 double Multiplier2 = 1.0;
extern int Font_size = 10;
extern color Title_color = White;
extern color Label_color = Tomato;
extern int   Shift_X = 10;
extern int   Shift_Y = 0;
extern int Corner = 1;

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

int start()
  { 
   int AV=0; 
   int i=0;   
   for(i=1;i<=Period;i++)
   
   if (Symbol()=="XAUUSD")
   {AV =  AV +  (iHigh(NULL,Period(),i)-iLow(NULL,Period(),i))/Point/100;} 
   else
   {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-10; b=Shift_X;}
   if (Corner==0 || Corner==2) {a=Shift_X; b=Shift_X+Font_size*7;}
  
   CreateAverage( "AV1",30+Shift_Y, a);
   ObjectSetText("AV1","ATR" + "(" + Period +")" + " =", Font_size,"Arial Bold",Title_color);      
   CreateAverage( "AV2",30+Shift_Y, b);
   ObjectSetText("AV2",DoubleToStr(AV*Multiplier,0)+" (x"+DoubleToStr(Multiplier,1)+")", Font_size,"Arial Bold",Label_color); 
   
   CreateAverage( "AV3",10+Shift_Y, a);
   ObjectSetText("AV3","ATR" + "(" + Period +")" + " =", Font_size,"Arial Bold",Title_color);      
   CreateAverage( "AV4",10+Shift_Y, b);
   ObjectSetText("AV4",DoubleToStr(AV*Multiplier2,0)+" (x"+DoubleToStr(Multiplier2,1)+")", Font_size,"Arial Bold",Label_color);
   
   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"); ObjectDelete("AV3");ObjectDelete("AV4");    
  }
