//+------------------------------------------------------------------+
//|                                               Average Range .mq4 |
//|                                         Copyright © 2008, by cja |
//|                                      http://cjatradingtools.com/ |
//+------------------------------------------------------------------+
#property copyright "Copyright © 2008, cjatradingtools.com"
#property link      "http://cjatradingtools.com/"

#property indicator_chart_window
extern int Magic_num = 12345;
extern int Av_1  = 0;
extern int Av_2  = 1;
extern int Av_3  = 5;
extern int Av_4  = 10;
extern int Av_5  = 20;
extern int Av_6  = 30;
extern color Title_col    = DarkOrange;
extern color Label_col    = Gray;
extern color Av_col       = Red;
extern color Total_col    = Silver;
extern color Total_Av_col = Red;

extern int   Shift_UP_DN = 1;// Adjusts Signal Display Up & Down 
extern int   Adjust_Side_to_side  = 1;// Adjusts Signal Display from side to side
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
//---- indicators
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
//----
   DeleteLabels();
//----
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
  {
   int    counted_bars=IndicatorCounted();
//----

    int AV1=0,AV2=0,AV3=0,AV4=0,AV5=0,AV6=0,RAvg;
    int i=0;

   AV1 =  (iHigh(NULL,1440,0)-iLow(NULL,1440,0))/Point;
   
   AV2 =  (iHigh(NULL,1440,1)-iLow(NULL,1440,1))/Point;
   
   for(i=1;i<=Av_3;i++)
   AV3 =  AV3 +  (iHigh(NULL,1440,i)-iLow(NULL,1440,i))/Point;
  
   for(i=1;i<=Av_4;i++)
   AV4 =  AV4 +  (iHigh(NULL,1440,i)-iLow(NULL,1440,i))/Point;
   
   for(i=1;i<=Av_5;i++)    
   AV5 = AV5 +  (iHigh(NULL,1440,i)-iLow(NULL,1440,i))/Point;
   
   for(i=1;i<=Av_6;i++)
   AV6 =  AV6  +  (iHigh(NULL,1440,i)-iLow(NULL,1440,i))/Point;
      
   AV3 = AV3/Av_3;
   AV4 = AV4/Av_4;
   AV5 = AV5/Av_5;
   AV6 = AV6/Av_6;
   RAvg  =  (AV2+AV3+AV4+AV5+AV6)/5; 
   
   CreateAverage( "AV"+Magic_num,15+ Shift_UP_DN,10+ Adjust_Side_to_side );
   ObjectSetText("AV"+Magic_num,"Daily Range",8,"Arial Bold",DarkOrange); 
   
   CreateAverage( "AV1"+Magic_num,22+ Shift_UP_DN,10+ Adjust_Side_to_side );
   ObjectSetText("AV1"+Magic_num,"-----------------",8,"Arial Bold",Silver); 
   
   
   CreateAverage( "AV2"+Magic_num,32+ Shift_UP_DN,40+ Adjust_Side_to_side );
   ObjectSetText("AV2"+Magic_num,"Today", 8,"Arial Bold",LimeGreen); 
     
   CreateAverage( "AV3"+Magic_num,32+ Shift_UP_DN,10+ Adjust_Side_to_side );
   ObjectSetText("AV3"+Magic_num,DoubleToStr(AV1 ,0), 8,"Arial Bold",Red); 
   
   CreateAverage( "AV4"+Magic_num,44+ Shift_UP_DN,40+ Adjust_Side_to_side );
   ObjectSetText("AV4"+Magic_num,""+Av_2+" Day", 8,"Arial Bold",Gray); 
     
   CreateAverage( "AV5"+Magic_num,44+ Shift_UP_DN,10+ Adjust_Side_to_side );
   ObjectSetText("AV5"+Magic_num,DoubleToStr(AV2 ,0), 8,"Arial Bold",Red); 
   
   CreateAverage( "AV6"+Magic_num,56+ Shift_UP_DN,40+ Adjust_Side_to_side );
   ObjectSetText("AV6"+Magic_num,""+Av_3+" Days", 8,"Arial Bold",Gray); 
     
   CreateAverage( "AV7"+Magic_num,56+ Shift_UP_DN,10+ Adjust_Side_to_side );
   ObjectSetText("AV7"+Magic_num,DoubleToStr(AV3 ,0), 8,"Arial Bold",Red); 
   
   CreateAverage( "AV8"+Magic_num,100+ Shift_UP_DN,60+ Adjust_Side_to_side );
   ObjectSetText("AV8"+Magic_num,""+Av_4+" Days", 14,"Arial Bold",Gray); 
     
   CreateAverage( "AV9"+Magic_num,100+ Shift_UP_DN,10+ Adjust_Side_to_side );
   ObjectSetText("AV9"+Magic_num,DoubleToStr(AV4 ,0), 16,"Arial Bold",Red); 
   
    CreateAverage( "AV8"+Magic_num,68+ Shift_UP_DN,40+ Adjust_Side_to_side );
   ObjectSetText("AV8"+Magic_num,""+Av_4+" Days", 8,"Arial Bold",Gray); 
     
   CreateAverage( "AV9"+Magic_num,68+ Shift_UP_DN,10+ Adjust_Side_to_side );
   ObjectSetText("AV9"+Magic_num,DoubleToStr(AV4 ,0), 8,"Arial Bold",Red); 
   
   CreateAverage( "AV10"+Magic_num,80+ Shift_UP_DN,40+ Adjust_Side_to_side );
   ObjectSetText("AV10"+Magic_num,""+Av_5+" Days", 8,"Arial Bold",Gray); 
     
   CreateAverage( "AV11"+Magic_num,80+ Shift_UP_DN,10+ Adjust_Side_to_side );
   ObjectSetText("AV11"+Magic_num,DoubleToStr(AV5 ,0), 8,"Arial Bold",Red); 
   
   CreateAverage( "AV12"+Magic_num,92+ Shift_UP_DN,40+ Adjust_Side_to_side );
   ObjectSetText("AV12"+Magic_num,""+Av_6+" Days", 8,"Arial Bold",Gray); 
     
   CreateAverage( "AV13"+Magic_num,92+ Shift_UP_DN,10+ Adjust_Side_to_side );
   ObjectSetText("AV13"+Magic_num,DoubleToStr(AV6 ,0), 8,"Arial Bold",Red); 
   
   CreateAverage( "AV14"+Magic_num,108+ Shift_UP_DN,40+ Adjust_Side_to_side );
   ObjectSetText("AV14"+Magic_num,"Total Av", 8,"Arial Bold",DarkViolet); 
  
   CreateAverage( "AV15"+Magic_num,108+ Shift_UP_DN,10+ Adjust_Side_to_side );
   ObjectSetText("AV15"+Magic_num,DoubleToStr(RAvg ,0), 8,"Arial Bold",Red); 
   
   CreateAverage( "AV16"+Magic_num,99+ Shift_UP_DN,10+ Adjust_Side_to_side );
   ObjectSetText("AV16"+Magic_num,"-----------------",8,"Arial Bold",Silver); 
   
   CreateAverage( "AV17"+Magic_num,115+ Shift_UP_DN,10+ Adjust_Side_to_side );
   ObjectSetText("AV17"+Magic_num,"-----------------",8,"Arial Bold",Silver); 
   
   
     
   
//----
   return(0);
  }
  
  
int CreateAverage( string n, int Shift_UP_DN, int Adjust_Side_to_side ) {
   ObjectCreate( n, OBJ_LABEL,0, 0, 0 );
   ObjectSet( n, OBJPROP_CORNER, 1 );
   ObjectSet( n, OBJPROP_XDISTANCE,Adjust_Side_to_side );
   ObjectSet( n, OBJPROP_YDISTANCE,Shift_UP_DN);
   ObjectSet( n, OBJPROP_BACK, false );
   }
   
   void DeleteLabels(){
   
   ObjectDelete("AV"+Magic_num); ObjectDelete("AV1"+Magic_num);ObjectDelete("AV2"+Magic_num);
   ObjectDelete("AV3"+Magic_num);ObjectDelete("AV4"+Magic_num);ObjectDelete("AV5"+Magic_num);
   ObjectDelete("AV6"+Magic_num);ObjectDelete("AV7"+Magic_num);ObjectDelete("AV8"+Magic_num);
   ObjectDelete("AV9"+Magic_num);ObjectDelete("AV10"+Magic_num);ObjectDelete("AV11"+Magic_num);
   ObjectDelete("AV12"+Magic_num);ObjectDelete("AV13"+Magic_num);ObjectDelete("AV14"+Magic_num);
   ObjectDelete("AV15"+Magic_num);ObjectDelete("AV16"+Magic_num);ObjectDelete("AV17"+Magic_num);
   }
//+------------------------------------------------------------------+