Draw Vertical Line to Future Time

 

I can draw a vertical line from past date into current date but how to draw a vertical line into future date?
I've been tried with this code but nothing happen:

extern int FutureBars=100;
extern int BarsLimit=1000;

for(int i=BarsLimit; i>=0; i--)
{
    datetime dailyTimefuture=Time[0]+FutureBars*Period()*60;

    MqlDateTime dt_structfuture;

    TimeToStruct(dailyTimefuture, dt_structfuture);
    
    if(dt_structfuture.day < 14) continue;
    if(dt_structfuture.day >= 14)
    {
            dt_structfuture.day = 14;
            dailyTimefuture = Time[iBarShift(_Symbol, PERIOD_CURRENT, StructToTime(dt_structfuture))];
    }

    string namefuture=TimeToStr(dailyTimefuture)+" Time_Vertical_Line_Future";

    if(ObjectFind(0,namefuture)<0)
    {
            if(!ObjectCreate(0,namefuture,OBJ_VLINE,0,dailyTimefuture,0))
            Print("Fail to draw the line ERROR CODE : ",GetLastError());
            ObjectSet(namefuture,OBJPROP_WIDTH,widthLine);
            ObjectSet(namefuture,OBJPROP_COLOR,colorLineQuarter);
            ObjectSet(namefuture,OBJPROP_BACK,true);
    }
}

Can someone suggest the changes?
Thanks for your help!

Draw Vertical Line on Spesific Date Every Month
Draw Vertical Line on Spesific Date Every Month
  • 2018.06.12
  • www.mql5.com
Hello, I am trying to write an indicator to draw vertical line every spesific date on each month, example: draw vertical line every date: 14 Januar...
 
Panjianom Adi Pratomo:

This's continue from this thread: https://www.mql5.com/en/forum/256040
From that thread it can draw vertical line from past date into current date but it can not draw to future date.
I've been tried with this code but nothing happen:

Can someone suggest the changes?
Thanks for your help!

https://docs.mql4.com/constants/objectconstants/enum_object/obj_cycles

OBJ_CYCLES - Object Types - Objects Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
OBJ_CYCLES - Object Types - Objects Constants - Standard Constants, Enumerations and Structures - MQL4 Reference
  • docs.mql4.com
The following script creates and moves cycle lines on the chart. Special functions have been developed to create and change graphical object's properties. You can use these functions "as is" in your own applications. //| Create cycle lines                                               |               time1=0,           ...
 

Like this.


#property strict
#property indicator_chart_window
#include <ChartObjects\ChartObjectsLines.mqh>
#include <Arrays\List.mqh>

input int InpNumBars=100;
CList lines;
//+------------------------------------------------------------------+
int OnInit()
{
   for(int i=1;i<InpNumBars+1;i++)
   {
      CChartObjectVLine *line = new CChartObjectVLine();
      line.Create(
         ChartID(),                          //this chart
         "line_"+string(i),                  //unique name
         0,                                  //no sub-window
         Time[0] + i * PeriodSeconds(_Period)//time in the future
      );
      lines.Add(line);
   }
   return INIT_SUCCEEDED;
}
//+------------------------------------------------------------------+
int start(){ return 0; }
 
nicholi shen:

Like this.


Thank you nicholi shen, I will try it.

 
nicholi shen:

Like this.

Time[0] + i * PeriodSeconds(_Period)//time in the future

your line always "moving".
I don't know if that is OP intention?

 
Mohamad Zulhairi Baba:

your line always "moving".
I don't know if that is OP intention?

OP needs to implement his own logic, I'm just here to demonstrate how to draw objects in the future. 

 
Thank you Mohamad Zulhairi & Nicholi Shen for the information.
Btw I am open for another solution rather than my logic.
 

Here's the update code but still nothing happen.

extern int FutureBars=100;

for(int i=1; i<FutureBars+1; i++)
{
    datetime dailyTimefuture=iTime(Symbol(), PERIOD_D1, Time[0] + i * PeriodSeconds(_Period));

    MqlDateTime dt_structfuture;

    TimeToStruct(dailyTimefuture, dt_structfuture);
    
    if(dt_structfuture.day < 14) continue;
    if(dt_structfuture.day >= 14)
    {
            dt_structfuture.day = 14;
            dailyTimefuture = Time[iBarShift(_Symbol, PERIOD_CURRENT, StructToTime(dt_structfuture))];
    }

    string namefuture=TimeToStr(dailyTimefuture)+" Time_Vertical_Line_Future";

    if(ObjectFind(0,namefuture)<0)
    {
            if(!ObjectCreate(0,namefuture,OBJ_VLINE,0,dailyTimefuture,0))
            Print("Fail to draw the line ERROR CODE : ",GetLastError());
            ObjectSet(namefuture,OBJPROP_WIDTH,widthLine);
            ObjectSet(namefuture,OBJPROP_COLOR,colorLineQuarter);
            ObjectSet(namefuture,OBJPROP_BACK,true);
    }
}
 
Panjianom Adi Pratomo:

Here's the update code but still nothing happen.

The Time array only goes to the current bar. You need to specify the exact time in the future you want the line drawn. See my example above. 

Reason: