//+------------------------------------------------------------------+
//|                                            Draw BAR_HILOZONE.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""
#property show_inputs

extern bool Show_Zones = false;
extern color Top_Colors = clrSpringGreen;
extern color Bottom_Colors = clrRed;

int Tf = 0;
double Factor = 10;
color opencolor=clrDarkGray,closecolor=clrDarkGray;

//+------------------------------------------------------------------+
//| 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=iTime(Symbol(),PERIOD_D1,0)+1440*60;
datetime nextbar=iTime(Symbol(),0,time_shift-1);
string   sTime=TimeToString(time,TIME_DATE|TIME_MINUTES);

if(Digits==3 || Digits==5)
double vPoint = Point*10; 
   else 
      vPoint = Point;
      
if(Show_Zones)
 {
ObjectCreate("HILOBAR_Zone_"+sTime,OBJ_RECTANGLE,0,time,high_time,thefuture,(high_time+low_time)/2);
ObjectSet("HILOBAR_Zone_"+sTime,OBJPROP_COLOR,clrLightGray);
ObjectSet("HILOBAR_Zone_"+sTime,OBJPROP_BACK,true);
ObjectSet("HILOBAR_Zone_"+sTime,OBJPROP_SELECTED,true);

ObjectCreate("HILOBAR_Zone1_"+sTime,OBJ_RECTANGLE,0,time,(high_time+low_time)/2,thefuture,low_time);
ObjectSet("HILOBAR_Zone1_"+sTime,OBJPROP_COLOR,clrSienna);
ObjectSet("HILOBAR_Zone1_"+sTime,OBJPROP_BACK,true);
ObjectSet("HILOBAR_Zone1_"+sTime,OBJPROP_SELECTED,true);
 }
 
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);

   }
//+------------------------------------------------------------------+