//+------------------------------------------------------------------+ 
//|      _TRO_RANGE_SB                                               | 
//|                                                                  | 
//|   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 color myScoreColor = Snow ;

extern string    session_name = "";


//+------------------------------------------------------------------+


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 ","");
   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 ;
      
//   if( TimeHour(Time[0] ) != TimeHour(Time[1]) )      {   }
   
     PL = TimeHour(Time[0]) ;
        
     open_price = iOpen(NULL,PERIOD_H1,0);  
     high_price = iHigh(NULL,PERIOD_H1,0); 
     low_price  = iLow(NULL,PERIOD_H1,0); 

      H_L[PL] = ( high_price - low_price  ) / point ;
      H_O[PL] = ( high_price - open_price ) / point ;
      O_L[PL] = ( open_price - low_price  ) / point ;
     
//+------------------------------------------------------------------+ 

string tAlert = "BUY ZONE" ;
string tStop  = " " ;

//+----------- SCOREBOARD ---------------------------------+  

n=20 ;

setObject(next(), "Range   "  ,price.x.offset, price.y.offset+n    , myScoreColor ,"Arial bold", 8);
setObject(next(), "High-Low"  ,price.x.offset, price.y.offset+n*2  , myScoreColor ,"Arial bold", 8);
setObject(next(), "High-Open" ,price.x.offset, price.y.offset+n*3  , myScoreColor ,"Arial bold", 8);
setObject(next(), "Open-Low " ,price.x.offset, price.y.offset+n*4  , myScoreColor ,"Arial bold", 8);

for (i=0,m=50; i < 24; i++, m+=30){

setObject(next(), i+"00 "  ,price.x.offset+m, price.y.offset+n  , myScoreColor ,"Arial bold", 8);
setObject(next(), "  "+DoubleToStr(H_L[i],0 ) ,price.x.offset+m, price.y.offset+n*2 , myScoreColor ,"Arial bold", 8);           
setObject(next(), "  "+DoubleToStr(H_O[i],0 ) ,price.x.offset+m, price.y.offset+n*3 , myScoreColor ,"Arial bold", 8);           
setObject(next(), "  "+DoubleToStr(O_L[i],0 ) ,price.x.offset+m, price.y.offset+n*4 , myScoreColor ,"Arial bold", 8);           

} // for (i=0
 
//+------------------------------------------------------------------+  

   WindowRedraw();    

   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);
}