//+------------------------------------------------------------------+
//|                                            Draw BAR_HILOZONE.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property show_inputs

extern bool Show_Zones = true;
extern bool Single_Zone = true;
extern bool Show_Lines = false;
extern color Top_Colors = clrSpringGreen;
extern color Bottom_Colors = clrRed;
extern color Top_Zone_Color = clrLightGray;
extern color Bottom_Zone_Color = clrSienna;
extern int   OffsetRight = 9;

int Tf = 0;
double Factor = 10;
color opencolor,closecolor;

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
  
//----
datetime time=WindowTimeOnDropped();
double price=WindowPriceOnDropped();

int time_shift=iBarShift(Symbol(),Tf,time,false);

time=iTime(NULL,Tf,time_shift);
double high_time=iHigh(NULL,Tf,time_shift);
double low_time=iLow(NULL,Tf,time_shift);

datetime thefuture=time+OffsetRight*_Period*60;
datetime nextbar=iTime(Symbol(),0,time_shift-1);
string   sTime=TimeToString(time,TIME_DATE|TIME_MINUTES);

      
if(Show_Zones)
 {
if(!Single_Zone)
ObjectCreate("HILOBAR_Zone_"+sTime,OBJ_RECTANGLE,0,time,high_time,thefuture,(high_time+low_time)/2);
else
if(Single_Zone)
ObjectCreate("HILOBAR_Zone_"+sTime,OBJ_RECTANGLE,0,time,high_time,thefuture,low_time);
ObjectSet("HILOBAR_Zone_"+sTime,OBJPROP_COLOR,Top_Zone_Color);
ObjectSet("HILOBAR_Zone_"+sTime,OBJPROP_BACK,true);
ObjectSet("HILOBAR_Zone_"+sTime,OBJPROP_SELECTED,true);

if(!Single_Zone)
ObjectCreate("HILOBAR_Zone1_"+sTime,OBJ_RECTANGLE,0,time,(high_time+low_time)/2,thefuture,low_time);
ObjectSet("HILOBAR_Zone1_"+sTime,OBJPROP_COLOR,Bottom_Zone_Color);
ObjectSet("HILOBAR_Zone1_"+sTime,OBJPROP_BACK,true);
ObjectSet("HILOBAR_Zone1_"+sTime,OBJPROP_SELECTED,true);
 }

if(Show_Lines)
 {
if(Close[time_shift]>Open[time_shift])
 {
 opencolor=Bottom_Colors;
 closecolor=Top_Colors;
HLINE("HILOBAR_Open_"+sTime,Open[time_shift],time,thefuture,opencolor,0,0,false);
HLINE("HILOBAR_Close_"+sTime,Close[time_shift],time,thefuture,closecolor,0,0,false);
HLINE("HILOBAR_High_"+sTime,High[time_shift],time,thefuture,closecolor,0,0,false);
HLINE("HILOBAR_Low_"+sTime,Low[time_shift],time,thefuture,opencolor,0,0,false);
 }
if(Close[time_shift]<Open[time_shift])
 {
 opencolor=Top_Colors;
 closecolor=Bottom_Colors;
HLINE("HILOBAR_Open_"+sTime,Open[time_shift],time,thefuture,opencolor,0,0,false);
HLINE("HILOBAR_Close_"+sTime,Close[time_shift],time,thefuture,closecolor,0,0,false);
HLINE("HILOBAR_High_"+sTime,High[time_shift],time,thefuture,opencolor,0,0,false);
HLINE("HILOBAR_Low_"+sTime,Low[time_shift],time,thefuture,closecolor,0,0,false);
 }
 }

//----
   return(0);
  }
//+------------------------------------------------------------------+
void HLINE(string name,double price,datetime timeBegin,datetime timeEnd,color paint,int style,int width,bool RayRight) 
   {
      ObjectCreate(name, OBJ_TREND, 0, timeBegin, price, timeEnd, price );
      ObjectSet(name, OBJPROP_COLOR, paint);
      ObjectSet(name, OBJPROP_STYLE, style);
      ObjectSet(name, OBJPROP_WIDTH, width);
      ObjectSet(name, OBJPROP_RAY_RIGHT, RayRight);
      ObjectSet(name, OBJPROP_BACK, false);
      ObjectSet(name, OBJPROP_SELECTABLE, true);
      ObjectSet(name, OBJPROP_SELECTED, true);

   }
//+------------------------------------------------------------------+