//*
//* Two Days Open Close Lines
//* BlueRain
//* 10/1/2020

#property copyright "BlueRain"

#property indicator_chart_window

extern color YHL_LineColor = clrBlue;
extern color THL_LineColor = clrRed;
extern int   HL_LineWidth = 2;
extern int YHTH_PipDiff_Yposition = 30;
extern int YLTL_PipDiff_Yposition = -20;


extern int TimeZoneOfData= 0;

string LabelID = "TDOC_";

double Poin;

int YHTH_Yposition = 30;
int YLTL_Yposition = -20;


//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int init()
{

    if (Point==0.00001) Poin=0.0001;
   else {
      if (Point==0.001) Poin=0.01;
      else Poin=Point;
   }
   
   
	return(0);
}
//+------------------------------------------------------------------+
//| Custor indicator deinitialization function                       |
//+------------------------------------------------------------------+
int deinit()
{
   deleteObjects();
 
	return(0);
}

void deleteObjects()
{
   string lookFor       = LabelID;
   int    lookForLength = StringLen(lookFor);
   for (int i=ObjectsTotal()-1; i>=0; i--)
   {
      string objectName = ObjectName(i);
         if (StringSubstr(objectName,0,lookForLength) == lookFor) ObjectDelete(objectName);
   }
}


 
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int start()
{
   MqlRates rates[];
   int copied = CopyRates(Symbol(),PERIOD_D1,0,2,rates);

   if ( copied > 0)
   {
     //lines Open/Close 
    
    //yesterday
     DrawLine(LabelID + "d1openhigh", rates[0].time,Time[0],rates[0].high,rates[0].high,YHL_LineColor,HL_LineWidth,STYLE_SOLID);
     DrawLine(LabelID + "d1openlow", rates[0].time,Time[0],rates[0].low,rates[0].low,YHL_LineColor,HL_LineWidth,STYLE_SOLID);
    
    //today
     DrawLine(LabelID + "dopenhigh", rates[1].time,Time[0],rates[1].high,rates[1].high,THL_LineColor,HL_LineWidth,STYLE_SOLID);
     DrawLine(LabelID + "dopenlow", rates[1].time,Time[0],rates[1].low,rates[1].low,THL_LineColor,HL_LineWidth,STYLE_SOLID);
      
     //Vertical Line
     
  

     DrawVLine(LabelID + "d2openvline", rates[1].time,clrYellow,1,STYLE_DOT);
     DrawVLine(LabelID + "d1openvline", rates[0].time,clrYellow,1,STYLE_DOT);
     
     
      //draw price
    //  DrawPrice(string name, datetime time1, double price1, color col)
      

      //today
      DrawPrice(LabelID + "dopenprice",Time[0],rates[1].high,clrYellow,10,"TH" + " (" + DoubleToStr(rates[1].high,Digits) + ")");
      DrawPrice(LabelID + "dcloseprice",Time[0],rates[1].low,clrYellow,10,"TL" + " (" + DoubleToStr(rates[1].low,Digits) + ")");
      
      //yesterday
      DrawPrice(LabelID + "d1openprice",Time[0],rates[0].high,clrYellow,10,"YH"+ " (" + DoubleToStr(rates[0].high,Digits) + ")");
      DrawPrice(LabelID + "d1closeprice",Time[0],rates[0].low,clrYellow,10,"YL"+ " (" + DoubleToStr(rates[0].low,Digits) + ")");
      
      
      
     //pip diff
      string pips ;
     
      pips = DoubleToStr( (rates[1].high - rates[0].high) / Poin,2);
      

      DrawPipDiff(LabelID + "d1Hpipdiff",rates[1].time,rates[0].high,clrYellow,10,"YHTH PipDiff: " + pips,YHTH_Yposition);
     
     pips = DoubleToStr(  (rates[1].low - rates[0].low) / Poin,2);

     DrawPipDiff(LabelID + "d1Lpipdiff",rates[1].time,rates[0].low,clrYellow,10,"YLTL Pip Diff:" + pips, YLTL_Yposition );
   
     
   }
   
   
   //DailyOpen(0,lastbar);
   
   return (0);
}



void DrawPriceValues(string name, double price,color textcolor, int fontsize  )
{
   
  if (ObjectFind(name) ) ObjectDelete(name);
  
  ObjectCreate(name, OBJ_TEXT, 0, Time[0],price);
  ObjectSet(name, OBJPROP_ANGLE, 0);
  
  ObjectSetText(name,DoubleToStr(price,2) ,fontsize, "Corbel", textcolor);

}





//+------------------------------------------------------------------+
//| Draws a pips distance for SL or TP.                              |
//+------------------------------------------------------------------+
void DrawPrice(string name, datetime time1, double price1, color col, int fontSize, string text)
{
  
   int x, y;

   
	// Needed only for y, x is derived from the chart width.
   ChartTimePriceToXY(0, 0, time1, price1, x, y);
   DrawLabel(name,x,y-10,text,fontSize,"Arial",col,DoubleToStr(price1,Digits));
   
   
   
}


void DrawPipDiff(string name, datetime time1, double price1, color col, int fontSize, string text, int Yposition)
{
  
   int x, y;

   
	// Needed only for y, x is derived from the chart width.
   ChartTimePriceToXY(0, 0, time1, price1, x, y);
   DrawLabel(name,x,y-Yposition,text,fontSize,"Arial",col,DoubleToStr(price1,Digits));
   
   
   
}




void DrawLabel(string name,int x,int y,string label,int size=9,string font="Arial",color clr=DimGray,string tooltip="")
  {
 
   if (ObjectFind(name)) ObjectDelete(name);
   ObjectCreate(name,OBJ_LABEL,0,0,0);
   ObjectSetText(name,label,size,font,clr);
   ObjectSet(name,OBJPROP_CORNER,0);
   ObjectSet(name,OBJPROP_XDISTANCE,x);
   ObjectSet(name,OBJPROP_YDISTANCE,y);
   ObjectSetString(0,name,OBJPROP_TOOLTIP,tooltip);
//--- justify text
//ObjectSet(name, OBJPROP_ANCHOR, 0);
//ObjectSetString(0, name, OBJPROP_TOOLTIP, tooltip);
//ObjectSet(name, OBJPROP_SELECTABLE, 0);
//---
  }
  
  
//+------------------------------------------------------------------+
//|  Custom indicator initialization function                        |
//+------------------------------------------------------------------+
void DrawVLine(string name, datetime Time1, color lcolor, int lwidth,ENUM_LINE_STYLE linestyle)
{
   
  
   ObjectCreate   (name,            OBJ_VLINE, 0, Time1,0);//, dValue);
   ObjectSet      (name,            OBJPROP_STYLE, linestyle);
   ObjectSet      (name,            OBJPROP_COLOR, lcolor); 

            
   
   
}


void DrawLine(string name, datetime Time1, datetime Time2, double Price1, double Price2,color lcolor, int lwidth,ENUM_LINE_STYLE linestyle)
{
  
          ObjectDelete(name);
            
          ObjectCreate(name,OBJ_TREND,0,Time1,0,Time2,0);
                      
          ObjectSet(name,OBJPROP_COLOR,lcolor);
          
          if (linestyle == STYLE_SOLID)
           ObjectSet(name,OBJPROP_WIDTH,lwidth);
          
          ObjectSet(name,OBJPROP_STYLE,linestyle);
         
          ObjectSet(name,OBJPROP_RAY,false);
              
          ObjectSet(name,OBJPROP_PRICE1,Price1);
          ObjectSet(name,OBJPROP_PRICE2,Price2);
                   

}  

