//+------------------------------------------------------------------+
//|                                                    Dadas_HL_Bar_CandlesCandles.mq4 |
//+------------------------------------------------------------------+
#property copyright " "
#property link      " "

#property indicator_chart_window

int TFBar       = 0;
extern int NumberOfBars = 200;
extern bool bBarsCounted = false;
int Start_At = 1;
extern color ColorUp     = DodgerBlue;
extern color ColorDown     = LimeGreen;
extern color ColorNeutral = DarkKhaki;
extern color ColorCurCandle = DarkKhaki;
extern bool bRay = false;
extern bool bBack = false;
extern int iWidth = 5;
extern bool bInverse = false;
extern bool Show_Signal = true;
extern color Signal_Color_Up = Blue;
extern color Signal_Color_Down = Red;
extern bool Show_InsideBar = false;
extern bool Show_OutsideBar = false;
extern bool Show_Lead_Lines = true;
extern int Lead_Lines_Tf =0;
extern color Lead_Lines_Color = clrKhaki;
extern int Lead_Lines_Width = 0;
extern int Lead_Lines_Style =2;



  int shb,Shift;
  double   ph,pl,po,pc; 
  datetime to,t1; 
  color Color,Color_Signal,PrevColor;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
void init() {
  int i;
  if(bBarsCounted) NumberOfBars=Bars;
  for (i=0; i<NumberOfBars; i++) {
    ObjectDelete("BodyTF"+TFBar+"Bar"+i);

  }
  for (i=Start_At; i<NumberOfBars; i++) {
    ObjectCreate("BodyTF"+TFBar+"Bar"+i, OBJ_TREND, 0, 0,0, 0,0);
    ObjectCreate("BodyTF"+TFBar+"Bar"+0, OBJ_TREND, 0, 0,0, 0,0);
  }
    ObjectCreate("Lead_Line_Top"+Lead_Lines_Tf+"Bar", OBJ_TREND, 0, 0,0, 0,0);
    ObjectCreate("Lead_Line_Bot"+Lead_Lines_Tf+"Bar", OBJ_TREND, 0, 0,0, 0,0);
   
}

//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
void deinit() {

  for (int i=0; i<NumberOfBars; i++) {
    ObjectDelete("BodyTF"+TFBar+"Bar"+i);
  }
    ObjectDelete("Lead_Line_Top"+Lead_Lines_Tf+"Bar");
    ObjectDelete("Lead_Line_Bot"+Lead_Lines_Tf+"Bar");
  
}

//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start() {

    shb=0;
  if(IsNewBar())
   {
    while (shb<NumberOfBars) 
    {
      to = iTime(Symbol(), TFBar, shb);
      ph = iHigh(Symbol(), TFBar, shb);
      pl = iLow(Symbol(), TFBar, shb);
      po = iOpen(Symbol(), TFBar, shb);
      pc = iClose(Symbol(), TFBar, shb);
             
  if(bInverse) {
        pl = iHigh(Symbol(), TFBar, shb); 
        ph = iLow(Symbol(), TFBar, shb); 
    }
  
  Color=ColorNeutral;
  if(iLow(Symbol(), TFBar, shb)>iLow(Symbol(), TFBar, shb+1)) {Color = ColorUp; PrevColor=ColorUp;}
  if(iHigh(Symbol(), TFBar, shb)<iHigh(Symbol(), TFBar, shb+1)) {Color = ColorDown; PrevColor=ColorDown;}   
  if(iLow(Symbol(), TFBar, shb)>=iLow(Symbol(), TFBar, shb+1)&&iHigh(Symbol(), TFBar, shb)<=iHigh(Symbol(), TFBar, shb+1)) 
    {
    Color=PrevColor;
    if(Show_InsideBar) {Color=ColorNeutral;}
    }
  if(iLow(Symbol(), TFBar, shb)<=iLow(Symbol(), TFBar, shb+1)&&iHigh(Symbol(), TFBar, shb)>=iHigh(Symbol(), TFBar, shb+1))  
    {
    if(pc>po&&ph>iHigh(Symbol(), TFBar, shb+1)) Color=ColorUp;
    if(pc<po&&pl<iLow(Symbol(), TFBar, shb+1)) Color=ColorDown;    
    }

   
    
      ObjectSet("BodyTF"+TFBar+"Bar"+shb, OBJPROP_TIME1, to);  
      ObjectSet("BodyTF"+TFBar+"Bar"+shb, OBJPROP_PRICE1, ph);
      ObjectSet("BodyTF"+TFBar+"Bar"+shb, OBJPROP_TIME2, to); 
      ObjectSet("BodyTF"+TFBar+"Bar"+shb, OBJPROP_PRICE2, pl);
      
      ObjectSet("BodyTF"+TFBar+"Bar"+shb, OBJPROP_COLOR, Color);
     
        ObjectSet("BodyTF"+TFBar+"Bar"+shb, OBJPROP_STYLE, STYLE_SOLID);
        ObjectSet("BodyTF"+TFBar+"Bar"+shb, OBJPROP_WIDTH, iWidth);        
        ObjectSet("BodyTF"+TFBar+"Bar"+shb, OBJPROP_BACK, bBack);

        ObjectSet("BodyTF"+TFBar+"Bar"+shb, OBJPROP_RAY, bRay);      
        ObjectSet("BodyTF"+TFBar+"Bar"+shb, OBJPROP_SELECTABLE, false); 

         
      shb++;
     }       
      
 } 
      to = iTime(Symbol(), TFBar, 0);
      ph = iHigh(Symbol(), TFBar, 0);
      pl = iLow(Symbol(), TFBar, 0);
      po = iOpen(Symbol(), TFBar, 0);
      pc = iClose(Symbol(), TFBar, 0);

  Color=ColorCurCandle;
  if(iLow(Symbol(), TFBar, 0)>iLow(Symbol(), TFBar, 1)) Color = ColorCurCandle;
  if(iHigh(Symbol(), TFBar, 0)<iHigh(Symbol(), TFBar, 1)) Color = ColorCurCandle;   
  if(iLow(Symbol(), TFBar, 0)>=iLow(Symbol(), TFBar, 1)&&iHigh(Symbol(), TFBar, 0)<=iHigh(Symbol(), TFBar, 1)) Color=ColorCurCandle;
  if(iLow(Symbol(), TFBar, 0)<=iLow(Symbol(), TFBar, 1)&&iHigh(Symbol(), TFBar, 0)>=iHigh(Symbol(), TFBar, 1))  
    {
    if(pc>po&&ph>iHigh(Symbol(), TFBar, 1)) Color=ColorCurCandle;
    if(pc<po&&pl<iLow(Symbol(), TFBar, 1)) Color=ColorCurCandle;    
    } 
            
      ObjectSet("BodyTF"+TFBar+"Bar"+0, OBJPROP_TIME1, to);  
      ObjectSet("BodyTF"+TFBar+"Bar"+0, OBJPROP_PRICE1, ph);
      ObjectSet("BodyTF"+TFBar+"Bar"+0, OBJPROP_TIME2, to); 
      ObjectSet("BodyTF"+TFBar+"Bar"+0, OBJPROP_PRICE2, pl);
      ObjectSet("BodyTF"+TFBar+"Bar"+0, OBJPROP_COLOR, Color);
      
        ObjectSet("BodyTF"+TFBar+"Bar"+0, OBJPROP_STYLE, STYLE_SOLID);
        ObjectSet("BodyTF"+TFBar+"Bar"+0, OBJPROP_WIDTH, iWidth);        
        ObjectSet("BodyTF"+TFBar+"Bar"+0, OBJPROP_BACK, bBack);

        ObjectSet("BodyTF"+TFBar+"Bar"+0, OBJPROP_RAY, bRay);      
        ObjectSet("BodyTF"+TFBar+"Bar"+0, OBJPROP_SELECTABLE, false); 
        
if(Show_Signal)
 {
  
   for(shb=Start_At; shb<NumberOfBars; shb++)
     {
                  
      Shift = shb+1;   
  if(iLow(Symbol(), TFBar, shb)>iLow(Symbol(), TFBar, shb+1)
     &&iLow(Symbol(), TFBar, shb+1)<iLow(Symbol(), TFBar, shb+2)
     &&iHigh(Symbol(), TFBar, shb)<iHigh(Symbol(), TFBar, shb+1)
    ) 
    {
    Color_Signal = Signal_Color_Up;
      ObjectSet("BodyTF"+TFBar+"Bar"+Shift, OBJPROP_COLOR, Color_Signal);     
    }
  if(iHigh(Symbol(), TFBar, shb)<iHigh(Symbol(), TFBar, shb+1)
     &&iHigh(Symbol(), TFBar, shb+1)>iHigh(Symbol(), TFBar, shb+2)
     &&iLow(Symbol(), TFBar, shb)>iLow(Symbol(), TFBar, shb+1)    
    )
    {
    Color_Signal = Signal_Color_Down;
      ObjectSet("BodyTF"+TFBar+"Bar"+Shift, OBJPROP_COLOR, Color_Signal);     
    }

   
    }  
    
//---- OutsideBar section 
   for(shb=Start_At; shb<NumberOfBars; shb++)
     {
  
      po = iOpen(Symbol(), TFBar, shb);
      pc = iClose(Symbol(), TFBar, shb);
      pl = iLow(Symbol(), TFBar, shb);
      ph = iHigh(Symbol(), TFBar, shb);
      to = iTime(Symbol(), TFBar, shb);
      t1 = iTime(Symbol(), TFBar, shb)+iTime(NULL,PERIOD_D1,0)+1440*60;
         
 if(Show_OutsideBar)
  { 
 
  if(ph>iHigh(Symbol(), TFBar, shb+1)&&pl<iLow(Symbol(), TFBar, shb+1))  
  {
    if(pc>po) 
     {
     Color_Signal=Signal_Color_Up;
     
      ObjectSet("BodyTF"+TFBar+"Bar"+shb, OBJPROP_COLOR, Color_Signal);
                    
     }
     
    if(pc<po) 
     {
    Color_Signal=Signal_Color_Down;    
   
      ObjectSet("BodyTF"+TFBar+"Bar"+shb, OBJPROP_COLOR, Color_Signal);
   
     }
    }    
  }    
   } 
//----    
 } 
 
if(Show_Lead_Lines)
  {
      ObjectSet("Lead_Line_Top"+Lead_Lines_Tf+"Bar", OBJPROP_COLOR, Lead_Lines_Color);
      ObjectSet("Lead_Line_Top"+Lead_Lines_Tf+"Bar", OBJPROP_PRICE1, iHigh(NULL,Lead_Lines_Tf,0));      
      ObjectSet("Lead_Line_Top"+Lead_Lines_Tf+"Bar", OBJPROP_PRICE2,  iHigh(NULL,Lead_Lines_Tf,0));      
      ObjectSet("Lead_Line_Top"+Lead_Lines_Tf+"Bar", OBJPROP_TIME1, iTime(NULL,Lead_Lines_Tf,0));      
      ObjectSet("Lead_Line_Top"+Lead_Lines_Tf+"Bar", OBJPROP_TIME2, iTime(NULL,Lead_Lines_Tf,0)+Lead_Lines_Tf*60);      
      ObjectSet("Lead_Line_Top"+Lead_Lines_Tf+"Bar", OBJPROP_STYLE, Lead_Lines_Style);      
      ObjectSet("Lead_Line_Top"+Lead_Lines_Tf+"Bar", OBJPROP_WIDTH, Lead_Lines_Width);      
      ObjectSet("Lead_Line_Top"+Lead_Lines_Tf+"Bar", OBJPROP_RAY, false);
      ObjectSet("Lead_Line_Top"+Lead_Lines_Tf+"Bar", OBJPROP_BACK, true);             
      ObjectSet("Lead_Line_Top"+Lead_Lines_Tf+"Bar", OBJPROP_SELECTABLE, false);      
    
      ObjectSet("Lead_Line_Bot"+Lead_Lines_Tf+"Bar", OBJPROP_COLOR, Lead_Lines_Color);
      ObjectSet("Lead_Line_Bot"+Lead_Lines_Tf+"Bar", OBJPROP_PRICE1, iLow(NULL,Lead_Lines_Tf,0));      
      ObjectSet("Lead_Line_Bot"+Lead_Lines_Tf+"Bar", OBJPROP_PRICE2,  iLow(NULL,Lead_Lines_Tf,0));      
      ObjectSet("Lead_Line_Bot"+Lead_Lines_Tf+"Bar", OBJPROP_TIME1, iTime(NULL,Lead_Lines_Tf,0));      
      ObjectSet("Lead_Line_Bot"+Lead_Lines_Tf+"Bar", OBJPROP_TIME2, iTime(NULL,Lead_Lines_Tf,0)+Lead_Lines_Tf*60);      
      ObjectSet("Lead_Line_Bot"+Lead_Lines_Tf+"Bar", OBJPROP_STYLE, Lead_Lines_Style);      
      ObjectSet("Lead_Line_Bot"+Lead_Lines_Tf+"Bar", OBJPROP_WIDTH, Lead_Lines_Width);      
      ObjectSet("Lead_Line_Bot"+Lead_Lines_Tf+"Bar", OBJPROP_RAY, false);
      ObjectSet("Lead_Line_Bot"+Lead_Lines_Tf+"Bar", OBJPROP_BACK, true);             
      ObjectSet("Lead_Line_Bot"+Lead_Lines_Tf+"Bar", OBJPROP_SELECTABLE, false);     
      
  }        
 
  return(0);
}
//+------------------------------------------------------------------+
bool IsNewBar()
{ 
  static datetime Trend_Candle_prevTime1 = -1;
  
  if(Trend_Candle_prevTime1 != Time[6])
  { 
   Trend_Candle_prevTime1 = Time[6]; 
       
   return(true);  
  } 

  return(false); 
}
//+------------------------------------------------------------------+