//+------------------------------------------------------------------+
//|                                            Draw BAR_HILOZONE.mq4 |
//|                                                                  |
//|                                                                  |
//+------------------------------------------------------------------+
#property copyright ""
#property link      ""


extern int Factor = 10;
extern int SL = 30;
extern bool Show_Label = false;
extern bool Show_Buy_Sell_Lines = false;
extern color topcolor=Magenta;
extern color botcolor=LimeGreen;
extern color innercolor=OliveDrab;
extern color textcolor=Snow;

//+------------------------------------------------------------------+
//| script program start function                                    |
//+------------------------------------------------------------------+
int start()
  {
//----

datetime time=WindowTimeOnDropped();
double price=WindowPriceOnDropped();

int time_shift=iBarShift(Symbol(),0,time,true);

double Open_Price=Open[time_shift];
double Close_Price=Close[time_shift];
double High_Price=High[time_shift+1];
double Low_Price=Low[time_shift+1];

int Dir;

if(Open_Price<Close_Price) {Dir = 1; }
if(Open_Price>Close_Price) {Dir = -1; }
if(Open_Price==Close_Price) {Dir = 0; }

datetime thefuture=Time[0]+31536000;
datetime nextbar=iTime(Symbol(),0,time_shift-1);

if(Digits==3 || Digits==5)
double vPoint = Point*10; 
   else 
      vPoint = Point;
      
string pipscounted;      
if(Dir == 0 || Dir == -1)
 {      
 pipscounted = DoubleToStr((Open_Price-Close_Price)/vPoint,0);
 }
 
if(Dir == 1)
 {      
 pipscounted = DoubleToStr((Close_Price-Open_Price)/vPoint,0);
 } 
 
// string topline="BAR_HILOZONE"+TimeLocal()+"a";
// string botline="BAR_HILOZONE"+TimeLocal()+"b";
string innerline=pipscounted+" Pips "+time;

string period;
if(Period() == 43200) {period = "MN";} 
if(Period() == 10080) {period = "W1";} 
if(Period() == 1440) {period = "D1";}
if(Period() == 240) {period = "H4";}
if(Period() == 60) {period = "H1";}   
if(Period() == 30) {period = "M30";} 
if(Period() == 15) {period = "M15";} 
if(Period() == 5) {period = "M5";} 
if(Period() == 1) {period = "M1";} 

// ObjectCreate(topline,OBJ_TREND,0,time,high_time,nextbar,high_time);
// ObjectCreate(botline,OBJ_TREND,0,time,low_time,nextbar,low_time);
if(Dir == 0 || Dir == -1)
 {
ObjectCreate(innerline,OBJ_RECTANGLE,0,time-Period()*60,High_Price,thefuture,Close_Price);
 }
 
if(Dir == 1)
 {
ObjectCreate(innerline,OBJ_RECTANGLE,0,time-Period()*60,Low_Price,thefuture,Close_Price);
 }
  
// ObjectSet(topline,OBJPROP_COLOR,topcolor);
// ObjectSet(botline,OBJPROP_COLOR,botcolor);
ObjectSet(innerline,OBJPROP_COLOR,innercolor);
ObjectSet(innerline,OBJPROP_BACK,true);
double buy,sell;

if(Dir == 0 || Dir == -1)
 {
sell = Open_Price+3*Point*Factor-SL*Point*Factor;
buy = Close_Price-3*Point*Factor+SL*Point*Factor;
 }

if(Dir == 1)
 {
sell = Close_Price+3*Point*Factor-SL*Point*Factor;
buy = Open_Price-3*Point*Factor+SL*Point*Factor;
 }
if(Show_Label==true)
 {
ObjectSetText(innerline,period+" "+pipscounted+" Pips"+" Sell/Buy@"+DoubleToStr(sell,Digits)+" Buy/Sell@"+DoubleToStr(buy,Digits),9,"Berlin Sans FB",textcolor);
 }

if(Show_Buy_Sell_Lines==true)
 {
if(StrToInteger(pipscounted)>=1.5*SL*Factor)
 { 
ObjectCreate("Sell_Line"+time,OBJ_TREND,0,time,sell,nextbar,sell);
ObjectCreate("Buy_Line"+time,OBJ_TREND,0,time,buy,nextbar,buy);
ObjectSet("Sell_Line"+time,OBJPROP_COLOR,topcolor);
ObjectSet("Buy_Line"+time,OBJPROP_COLOR,botcolor);
ObjectSet("Sell_Line"+time,OBJPROP_STYLE,1);
ObjectSet("Buy_Line"+time,OBJPROP_STYLE,1);
 }

ObjectCreate("Mid_Line"+time,OBJ_TREND,0,time,(Open_Price+Close_Price)/2,nextbar,(Open_Price+Close_Price)/2);
ObjectSet("Mid_Line"+time,OBJPROP_COLOR,Snow);
ObjectSet("Mid_Line"+time,OBJPROP_STYLE,2);
  }
//----
   return(0);
  }
//+------------------------------------------------------------------+