
//+------------------------------------------------------------------+ 
//|        _TRO_RANGE_STATS                                          | 
//|                                                                  | 
//|   Copyright © 2008, Avery T. Horton, Jr. aka TheRumpledOne       |
//|                                                                  |
//|   PO BOX 43575, TUCSON, AZ 85733                                 |
//|                                                                  |
//|   GIFTS AND DONATIONS ACCEPTED                                   | 
//|                                                                  |  
//|   therumpledone@gmail.com                                        |  
//+------------------------------------------------------------------+ 

#property  copyright "Copyright © 2008, Avery T. Horton, Jr. aka TRO" 
#property  link      "http://www.therumpldone.com/" 

#property indicator_separate_window
//---- input parameters

extern int win = 1;
extern int price.x.offset= 0 ;//250
extern int price.y.offset= 0 ;//-190

extern string myFont      = "Arial bold" ;
extern int    myFontSize  = 8 ;
extern color  myScoreColor = Snow ;


extern int   MaxBars         = 960;

//+------------------------------------------------------------------+


double open_price, high_price, low_price ;



int      totalLabels;
string   labelNames;
int      corner;
int      window; 
string   shortName ;


double H_L[24] ;
double H_O[24] ;
double O_L[24] ;


int PL ; // index to PL arrays 

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+

int init()
  {
  
   corner     = 0;
   shortName  = MakeUniqueName("Range Stats ","");
   labelNames = shortName;
   IndicatorShortName(shortName);
   totalLabels     = 0;
      
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {


   while (totalLabels>0) { ObjectDelete(StringConcatenate(labelNames,totalLabels)); totalLabels--;}
  

   return(0);
  }
  
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
  {
  
  
  
  
   window      = WindowFind(shortName);
   int m,n;
   int i,k;
   double point = Point ;
      
   for( i=0; i < MaxBars  ; i++) 
   {

   
     PL = TimeHour(Time[i]) ;
        
     open_price = iOpen(NULL,PERIOD_H1,i);  
     high_price = iHigh(NULL,PERIOD_H1,i); 
     low_price  = iLow(NULL,PERIOD_H1,i); 

      H_L[PL] = H_L[PL] + ( high_price - low_price  )  ;
      H_O[PL] = H_O[PL] + ( high_price - open_price )  ;
      O_L[PL] = O_L[PL] + ( open_price - low_price  )  ;
      
 } 

   for( i=0; i < 24  ; i++)  
   {
      H_L[i] = ( H_L[i] / 24 / point) ;
      H_O[i] = ( H_O[i] / 24 / point) ;
      O_L[i] = ( O_L[i] / 24 / point) ;
   }   
     
//+------------------------------------------------------------------+ 

string tAlert = "BUY ZONE" ;
string tStop  = " " ;

//+----------- SCOREBOARD ---------------------------------+  

n=20 ;

setObject(next(), "Bars "+ MaxBars  ,price.x.offset, price.y.offset+n    , myScoreColor ,myFont, myFontSize);
setObject(next(), "High-Low"  ,price.x.offset, price.y.offset+n*2  , myScoreColor ,myFont, myFontSize);
setObject(next(), "High-Open" ,price.x.offset, price.y.offset+n*3  , myScoreColor ,myFont, myFontSize);
setObject(next(), "Open-Low " ,price.x.offset, price.y.offset+n*4  , myScoreColor ,myFont, myFontSize);

for (i=0,m=50; i < 24; i++, m+=30){

setObject(next(), i+"00 "  ,price.x.offset+m, price.y.offset+n  , myScoreColor ,myFont, myFontSize);
setObject(next(), "  "+DoubleToStr(H_L[i],1 ) ,price.x.offset+m, price.y.offset+n*2 , myScoreColor ,myFont, myFontSize);           
setObject(next(), "  "+DoubleToStr(H_O[i],1 ) ,price.x.offset+m, price.y.offset+n*3 , myScoreColor ,myFont, myFontSize);           
setObject(next(), "  "+DoubleToStr(O_L[i],1 ) ,price.x.offset+m, price.y.offset+n*4 , myScoreColor ,myFont, myFontSize);           
   WindowRedraw();  
   
} // for (i=0
 
//+------------------------------------------------------------------+  

  

   return(0);
  }
  
//+------------------------------------------------------------------+
//+                                                                  +
//+------------------------------------------------------------------+

void setObject(string name,string text,int x,int y,color theColor, string font = "Arial",int size=10,int angle=0)
{
   string labelName = StringConcatenate(labelNames,name);

      if (ObjectFind(labelName) == -1)
          {
//             ObjectCreate(labelName,OBJ_LABEL,window,0,0);
             ObjectCreate(labelName,OBJ_LABEL,win,0,0);            
             
             ObjectSet(labelName,OBJPROP_CORNER,corner);
             if (angle != 0)
                  ObjectSet(labelName,OBJPROP_ANGLE,angle);
          }               
       ObjectSet(labelName,OBJPROP_XDISTANCE,x);
       ObjectSet(labelName,OBJPROP_YDISTANCE,y);
       ObjectSetText(labelName,text,size,font,theColor);
       
}

//+------------------------------------------------------------------+
//| Custom functions and procedures                                  |
//+------------------------------------------------------------------+

string next() { totalLabels++; return(totalLabels); }  

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
 
string MakeUniqueName(string first, string rest)
{
   string result = first+(MathRand()%1001)+rest;

   while (WindowFind(result)> 0)
          result = first+(MathRand()%1001)+rest;
   return(result);
}