//+------------------------------------------------------------------+ 
//|   _TRO_NB_SR_HiLo                                                | 
//|                                                                  | 
//|   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.therumpledone.com/" 

//---- indicator settings 
#property indicator_chart_window
#property indicator_buffers 0


//---- indicator parameters  
 

extern int win            = 0 ;
extern int CORNER         = 0 ;
extern int price.x.offset = 0 ;//250
extern int price.y.offset = 200 ;//-160


extern double   price        = 0 ;
extern int      tolerance    = 0 ;

extern int   Chart_Period    = 0;
extern int   myBars          = 480 ; // 1920 
extern color Up_color    = Lime;
extern color Eq_color    = Yellow;
extern color Dn_color    = Red;
extern color Price_color = Blue;

extern color highColor = LightSteelBlue ;
extern color lowColor  = LightSteelBlue ;

color ClOpColor ;

string tLabel01, tLabel02, tLabel03, tLabel04 ;

double open   ;    
double close    ; 

double high, low, pcthigh, pctlow, pricehigh, pricelow ; 

//+------------------------------------------------------------------+
color fColor( double i, double j)
{
color rColor ;

    if ( i > j ) rColor = Up_color; 
    else {
    if ( i < j )  rColor = Dn_color; 
    else rColor = Eq_color; }
return ( rColor );
}
 

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

int init() 
  { 

  if(Chart_Period == 0) { Chart_Period = Period() ; }

tLabel01 = "SRHL29" + Chart_Period + myBars + Symbol();
tLabel02 = "SRHL30" + Chart_Period + myBars + Symbol();
tLabel03 = "SRHL31" + Chart_Period + myBars + Symbol();
tLabel04 = "SRHL32" + Chart_Period + myBars + Symbol();

//ObjectsDeleteAll();
   return(0); 
  } 

//+------------------------------------------------------------------+ 
int deinit() 
{ 
ObjectsDeleteAll(0,OBJ_TEXT);
ObjectsDeleteAll(0,OBJ_ARROW);
ObjectsDeleteAll(0,OBJ_LABEL);      
}  

//+------------------------------------------------------------------+ 
int start() 
  { 
  
int limit; 

open   = iOpen(NULL,Chart_Period,0) ;  

if( price == 0) { close = iClose(NULL,Chart_Period,0) ; ClOpColor = fColor( close, open ) ; } 
else            { close = price ; ClOpColor = Price_color ;} 



pricehigh = close + ( tolerance * Point );
pricelow  = close - ( tolerance * Point );

high = 0 ;
low = 0 ;

   for(int i=1; i<=myBars; i++) 
   { 

double highi = iHigh(NULL,Chart_Period,i) ; 
double lowi  = iLow(NULL,Chart_Period,i) ;  
 
     if( highi >= pricelow && highi <= pricehigh ) {high = high  + 1  ; }
     if( lowi  >= pricelow && lowi  <= pricehigh ) {low  = low  + 1  ; }
   } 


pcthigh = ( high / myBars ) * 100 ;
pctlow = ( low / myBars ) * 100 ;

string tpcthigh = DoubleToStr(pcthigh, 2 ) + "%" ;
string tpctlow  = DoubleToStr(pctlow, 2 ) + "%" ;

string tPeriod = " "+TimeFrameToString( Chart_Period ) ;


 

string thigh =  DoubleToStr(high, 0 ) + "/" + myBars + " high " + tpcthigh ;
string tlow  =  DoubleToStr(low, 0 ) + "/" + myBars + " low " + tpctlow ;
                     
   ObjectCreate(tLabel01, OBJ_LABEL, win, 0, 0); 
   ObjectSetText(tLabel01,thigh, 15, "Arial Bold", highColor );
   ObjectSet(tLabel01, OBJPROP_CORNER, CORNER);
   ObjectSet(tLabel01, OBJPROP_XDISTANCE, 0+price.x.offset);
   ObjectSet(tLabel01, OBJPROP_YDISTANCE, 37+price.y.offset);
   
  
   
   ObjectCreate(tLabel02, OBJ_LABEL, win, 0, 0); 
   ObjectSetText(tLabel02,tlow, 15, "Arial Bold", lowColor );
   ObjectSet(tLabel02, OBJPROP_CORNER, CORNER);
   ObjectSet(tLabel02, OBJPROP_XDISTANCE, 0+price.x.offset);
   ObjectSet(tLabel02, OBJPROP_YDISTANCE, 100+price.y.offset); 
                                        
   ObjectCreate(tLabel03, OBJ_LABEL, win, 0, 0);
   ObjectSetText(tLabel03,DoubleToStr(close, Digits ) +tPeriod , 30, "Arial Bold", ClOpColor );
   ObjectSet(tLabel03, OBJPROP_CORNER, CORNER);
   ObjectSet(tLabel03, OBJPROP_XDISTANCE, 0+price.x.offset); // 765
   ObjectSet(tLabel03, OBJPROP_YDISTANCE, 60+price.y.offset); 
          
string sTolerance = "Tolerance +/- " + tolerance + " Pips" ;         
          
   ObjectCreate(tLabel04, OBJ_LABEL, win, 0, 0); 
   ObjectSetText(tLabel04, sTolerance , 10, "Arial Bold", Price_color );
   ObjectSet(tLabel04, OBJPROP_CORNER, CORNER);
   ObjectSet(tLabel04, OBJPROP_XDISTANCE, 0+price.x.offset);
   ObjectSet(tLabel04, OBJPROP_YDISTANCE, 120+price.y.offset); 
   WindowRedraw();    
 
//} 


   return(0); 
} 

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

 
string TimeFrameToString(int tf)
{
   string tfs;
   switch(tf) {
      case PERIOD_M1:  tfs="M1"  ; break;
      case PERIOD_M5:  tfs="M5"  ; break;
      case PERIOD_M15: tfs="M15" ; break;
      case PERIOD_M30: tfs="M30" ; break;
      case PERIOD_H1:  tfs="H1"  ; break;
      case PERIOD_H4:  tfs="H4"  ; break;
      case PERIOD_D1:  tfs="D1"  ; break;
      case PERIOD_W1:  tfs="W1"  ; break;
      case PERIOD_MN1: tfs="MN";
   }
   return(tfs);
}