//+------------------------------------------------------------------+
//|                                             V_Line_Close_MTF.mq4 |
//|                                         Copyright @ BestTraderEv |
//|                        https://www.forexfactory.com/besttraderev |
//+------------------------------------------------------------------+
#property copyright "Copyright @ BestTraderEv"
#property link      "https://www.forexfactory.com/besttraderev"
#property version   "1.00"
#property strict
#property indicator_chart_window

input ENUM_TIMEFRAMES                   Tf                     = PERIOD_CURRENT;
input int                               V_Line_i               = 14;
input color                             V_Line_Color           = clrRed;
input ENUM_LINE_STYLE                   V_Line_Style           = STYLE_DOT;
input int                               V_Line_Width           = 0;
input bool                              Plot_Close             = true;
input color                             Close_Line_Color       = clrRed;
input ENUM_LINE_STYLE                   Close_Line_Style       = STYLE_DOT;
input int                               Close_Line_Width       = 0;
input bool                              Lines_To_Back          = true;
//+------------------------------------------------------------------+
//| Custom indicator initialization function                         |
//+------------------------------------------------------------------+
int OnInit()
  {
//--- indicator buffers mapping
 ObjectDelete(0,as_string(Tf)+"-Time_vLine-"+(string)V_Line_i);
 ObjectDelete(0,as_string(Tf)+"-Time_vLine-Close"+(string)V_Line_i);
   
//---
   return(INIT_SUCCEEDED);
  }
//+------------------------------------------------------------------+
//| Custom indicator iteration function                              |
//+------------------------------------------------------------------+
int OnCalculate(const int rates_total,
                const int prev_calculated,
                const datetime &time[],
                const double &open[],
                const double &high[],
                const double &low[],
                const double &close[],
                const long &tick_volume[],
                const long &volume[],
                const int &spread[])
  {
//---
         string sTf = as_string(Tf);
         if (ObjectFind(0,sTf+"-Time_vLine-"+(string)V_Line_i)<0)
         {
            ObjectCreate(0, sTf+"-Time_vLine-"+(string)V_Line_i, OBJ_VLINE, 0, iTime(_Symbol,Tf,V_Line_i),0);
            ObjectSetInteger(0, sTf+"-Time_vLine-"+(string)V_Line_i, OBJPROP_COLOR, V_Line_Color );
            ObjectSetInteger(0, sTf+"-Time_vLine-"+(string)V_Line_i, OBJPROP_STYLE, V_Line_Style );
            ObjectSetInteger(0, sTf+"-Time_vLine-"+(string)V_Line_i, OBJPROP_WIDTH, V_Line_Width );
            ObjectSetInteger(0, sTf+"-Time_vLine-"+(string)V_Line_i, OBJPROP_BACK, true );
            if(Plot_Close)
             {
             HLINE(sTf+"-Time_vLine-Close"+(string)V_Line_i,iClose(_Symbol,Tf,V_Line_i),iTime(_Symbol,Tf,V_Line_i),Time[0]+3*_Period*60,Close_Line_Color,Close_Line_Style,Close_Line_Width);
             }
         }
   
//--- return value of prev_calculated for next call
   return(rates_total);
  }
//+------------------------------------------------------------------+
void HLINE(string name,double dprice,datetime dt1,datetime dt2,color paint,int style,int width) 
   {
      ObjectCreate(0,name, OBJ_TREND, 0, 0, 0);
      ObjectSetDouble(0,name, OBJPROP_PRICE1, dprice);
      ObjectSetDouble(0,name, OBJPROP_PRICE2, dprice);
      ObjectSetInteger(0,name, OBJPROP_TIME1, dt1);
      ObjectSetInteger(0,name, OBJPROP_TIME2, dt2);
      ObjectSetInteger(0,name, OBJPROP_COLOR, paint);
      ObjectSetInteger(0,name, OBJPROP_STYLE, style);
      ObjectSetInteger(0,name, OBJPROP_WIDTH, width);
      ObjectSetInteger(0,name, OBJPROP_BACK, Lines_To_Back);
      ObjectSetInteger(0,name, OBJPROP_RAY, false);
      ObjectSetInteger(0,name, OBJPROP_SELECTED, false);
      ObjectSetInteger(0,name, OBJPROP_SELECTABLE, false);
   }
//-------------------------------------------------------------------+
void OnDeinit(const int reason)
 {
 ObjectDelete(0,as_string(Tf)+"-Time_vLine-"+(string)V_Line_i);
 ObjectDelete(0,as_string(Tf)+"-Time_vLine-Close"+(string)V_Line_i);
 }
//-------------------------------------------------------------------+
string   as_string(ENUM_TIMEFRAMES period){
   if(period == PERIOD_CURRENT)  period   = (ENUM_TIMEFRAMES) _Period;
   string   period_xxx  = EnumToString(period);                // PERIOD_XXX
   return StringSubstr(period_xxx, 7);                         // XXX
}
//-------------------------------------------------------------------+
