//+------------------------------------------------------------------+
//|             _TRO_HL_Boxes                                        |
//|                                                                  | 
//|   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/" 

#property indicator_chart_window 

#property indicator_buffers 6

#property indicator_color1 Lime 
#property indicator_color2 Red
#property indicator_color3 Yellow 
#property indicator_color4 Lime
#property indicator_color5 Red
#property indicator_color6 Yellow 

// indicators parameters

extern bool show.lines = false ;
extern bool show.boxes = true ;

extern int       myBoxWidth  = 3;
extern int       myPeriod    = 60 ;

//---- buffers
double P1Buffer[];
double P2Buffer[];
double P3Buffer[];
double P4Buffer[];
double P5Buffer[];
double P6Buffer[];

int myStyle  = 2 ;


string   symbol, period ;
string   tObjName01 , tObjName02 , tObjName03, tObjName04 ;

//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
  {
  
   symbol = Symbol();
   period = Period(); 
     
//---- name for indicator window

   string myIndName = "TRO_HLB";
   IndicatorShortName(myIndName);
   
if(show.lines)
{   
   SetIndexBuffer(0, P1Buffer);
   SetIndexBuffer(1, P2Buffer);
   SetIndexBuffer(2, P3Buffer);
   SetIndexBuffer(3, P4Buffer);
   SetIndexBuffer(4, P5Buffer);
   SetIndexBuffer(5, P6Buffer);
 
//----

SetIndexArrow(0, 246); 
SetIndexArrow(1, 248); 
SetIndexArrow(2, 240); 
SetIndexArrow(3, 246); 
SetIndexArrow(4, 248); 
SetIndexArrow(5, 240); 

   SetIndexStyle(0, DRAW_ARROW, myStyle, 1);
   SetIndexStyle(1, DRAW_ARROW, myStyle, 1);   
   SetIndexStyle(2, DRAW_ARROW, myStyle, 1);
   SetIndexStyle(3, DRAW_ARROW, myStyle, 1);
   SetIndexStyle(4, DRAW_ARROW, myStyle, 1);
   SetIndexStyle(5, DRAW_ARROW, myStyle, 1);  
   
   // setting the indicator values, which will be invisible on the chart
   SetIndexEmptyValue(0,0); 
   SetIndexEmptyValue(1,0);
   SetIndexEmptyValue(2,0);
   SetIndexEmptyValue(3,0); 
   SetIndexEmptyValue(4,0); 
   SetIndexEmptyValue(5,0);
}
   

   

   tObjName01 = myIndName+ symbol + period + "01";
   tObjName02 = myIndName+ symbol + period + "02";
   tObjName03 = myIndName+ symbol + period + "03";
   tObjName04 = myIndName+ symbol + period + "04";   
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
  {
   
   
   return(0);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+

int start()
{
  if(show.lines) {DoLines() ; }
  if(show.boxes) {DoBoxes() ; } 
  
 
return(0);

}

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

void DoBoxes()
{

double high0, high1, low0, low1 ;

high0 = iHigh(NULL,myPeriod,0) ;
high1 = iHigh(NULL,myPeriod,1) ;
low0  = iLow(NULL,myPeriod,0) ;
low1  = iLow(NULL,myPeriod,1) ;

    if (ObjectFind(tObjName01) != 0)
      {
          ObjectCreate(tObjName01,OBJ_ARROW,0,Time[0],high0);
          ObjectSet(tObjName01,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
          ObjectSet(tObjName01,OBJPROP_COLOR,Lime);  
          ObjectSet(tObjName01,OBJPROP_WIDTH,myBoxWidth);  
      } 
      else
      {
         ObjectMove(tObjName01,0,Time[0],high0);
         ObjectSet(tObjName01,OBJPROP_COLOR,Lime);  
      }


    if (ObjectFind(tObjName02) != 0)
      {
          ObjectCreate(tObjName02,OBJ_ARROW,0,Time[0],high1);
          ObjectSet(tObjName02,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
          ObjectSet(tObjName02,OBJPROP_COLOR,Green);  
          ObjectSet(tObjName02,OBJPROP_WIDTH,myBoxWidth);  
      } 
      else
      {
         ObjectMove(tObjName02,0,Time[0],high1);
         ObjectSet(tObjName02,OBJPROP_COLOR,Green);  
      }

    if (ObjectFind(tObjName03) != 0)
      {
          ObjectCreate(tObjName03,OBJ_ARROW,0,Time[0],low0);
          ObjectSet(tObjName03,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
          ObjectSet(tObjName03,OBJPROP_COLOR,Red);  
          ObjectSet(tObjName03,OBJPROP_WIDTH,myBoxWidth);  
      } 
      else
      {
         ObjectMove(tObjName03,0,Time[0],low0);
         ObjectSet(tObjName03,OBJPROP_COLOR,Red);  
      }
 

    if (ObjectFind(tObjName04) != 0)
      {
          ObjectCreate(tObjName04,OBJ_ARROW,0,Time[0],low1);
          ObjectSet(tObjName04,OBJPROP_ARROWCODE,SYMBOL_RIGHTPRICE);
          ObjectSet(tObjName04,OBJPROP_COLOR,FireBrick);  
          ObjectSet(tObjName04,OBJPROP_WIDTH,myBoxWidth);  
      } 
      else
      {
         ObjectMove(tObjName04,0,Time[0],low1);
         ObjectSet(tObjName04,OBJPROP_COLOR,FireBrick);  
      }
           
  return(0);

}

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

void DoLines()
{

  int j,total=OrdersTotal();
   for(j=0;j<total;j++)
   {
    OrderSelect(j, SELECT_BY_POS, MODE_TRADES);
   }
   
 
  
   int i, dayi, counted_bars = IndicatorCounted();
//---- check for possible errors
   if(counted_bars < 0) 
       return(-1);
//---- last counted bar will be recounted
   if(counted_bars > 0) 
       counted_bars--;  
   int limit = Bars - counted_bars;
//----   
   for(i = limit - 1; i >= 0; i--)
     {
        //---- Tricolor indicator code 

        double trend=High[i] - High[i+1]; 
    
        if( trend>0 )     
          {
            P1Buffer[i]=High[i]; 
            P2Buffer[i]=0;      
            P3Buffer[i]=0;
          }
        else
          {
            if(trend<0)
              {
                P1Buffer[i]=0;
                P2Buffer[i]=High[i]; 
                P3Buffer[i]=0;
              }
            else 
              {
                P1Buffer[i]=0;
                P2Buffer[i]=0;
                P3Buffer[i]=High[i];
              }
          }    
        //---- 
	
        //---- Tricolor indicator code 

        double trendLo=Low[i] - Low[i+1]; 
    
        if( trendLo>0 )     
          {
            P4Buffer[i]=Low[i]; 
            P5Buffer[i]=0;      
            P6Buffer[i]=0;
          }
        else
          {
            if(trendLo<0)
              {
                P4Buffer[i]=0;
                P5Buffer[i]=Low[i]; 
                P6Buffer[i]=0;
              }
            else 
              {
                P4Buffer[i]=0;
                P5Buffer[i]=0;
                P6Buffer[i]=Low[i];
              }
          }    
        //----  

   }
   
   return(0);  
}