//+------------------------------------------------------------------+
//|                                                   LineAtTime.mq4 |
//|                                      Copyright 2018, nicholishen |
//|                                          http://forexfactory.com |
//+------------------------------------------------------------------+
#property copyright "Copyright 2018, nicholishen"
#property link      "http://forexfactory.com"
#property version   "1.00"
#property strict
#property indicator_chart_window
#include <ChartObjects\ChartObjectsLines.mqh>
//--- input parameters
input string   InpTime  = "9:30";         //Today's time to begin line plot
input color    InpColor = clrWhiteSmoke; //Line color
//+------------------------------------------------------------------+
//| 
//+------------------------------------------------------------------+
class CTimeLine 
{  
protected:
   CChartObjectHLine       m_price_line;
   CChartObjectVLine       m_time_line;
public:
   bool Create()
   {
      if(!ChartSetInteger(0,CHART_SHOW_OBJECT_DESCR,true))
         return false;
      if(!m_price_line.Create(0,"__price_line__",0,0.0))
         return false;
      if(!m_time_line.Create(0,"__time_line__",0,(datetime)0))
         return false;
      m_price_line   .Color(InpColor);
      m_time_line    .Color(InpColor);
      m_price_line   .Style(STYLE_DOT);
      m_time_line    .Style(STYLE_DOT);
      m_price_line   .Description(StringFormat("Open price @ %s (Server Time)",InpTime));
      m_time_line    .Description("");
      return true;
   }
   void Refresh()
   {
      static datetime last_update = 0;
      if(!(last_update==0 || TimeCurrent() - last_update >= PeriodSeconds(PERIOD_D1)))
         return;
      datetime time = StringToTime(InpTime);
      if(time > TimeCurrent())
         time -= PeriodSeconds(PERIOD_D1);
      double price = iOpen(_Symbol,PERIOD_M1,iBarShift(_Symbol,PERIOD_M1,time));
      m_price_line.Price(0,price);
      m_time_line.Time(0,time);
      last_update = time;
   }
};
//+------------------------------------------------------------------+
CTimeLine g_line;
//+------------------------------------------------------------------+
//| 
//+------------------------------------------------------------------+
int OnInit()
{
   if(!g_line.Create())
      return INIT_FAILED;
   return(INIT_SUCCEEDED);
}
//+------------------------------------------------------------------+
//| 
//+------------------------------------------------------------------+
int start()
{
   g_line.Refresh();
   return 0;
}
//+------------------------------------------------------------------+
