Draw Vertical Line on Spesific Date Every Month

 

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 January, 14 February, 14 March, 14 April etc...
Something like this:

extern string hour = "22";
extern int width = 2;
extern color Color = FireBrick;

int start()
{ 
    if (ObjectFind("Time_Vertical_Line") > -1)
    {
       ObjectDelete("Time_Vertical_Line");
    }

    datetime time = StrToTime(TimeToStr(TimeCurrent(), TIME_DATE) + " " + hour + ":00");
      
    ObjectCreate("Time_Vertical_Line", OBJ_VLINE, 0, time, 0);
    ObjectSet("Time_Vertical_Line", OBJPROP_WIDTH, width);
    ObjectSet("Time_Vertical_Line", OBJPROP_COLOR, Color);
    ObjectSet("Time_Vertical_Line", OBJPROP_BACK, true);

    return(0);
}

Can someone suggest the changes?
Thanks in advance.

 
Panjianom Adi Pratomo:

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 January, 14 February, 14 March, 14 April etc...
Something like this:

Can someone suggest the changes?
Thanks in advance.

here I wrote the code to draw line on the 14th day of the month.. Note it will draw the line on the 00:00 hour of the 14th.. but you can change the code to get it to the day you want

   int lookBack = 100; // no of days you wanna look back
   for(int i=100;i>=0;i--)
     {
      datetime dailyTime=iTime(Symbol(),1440,i);
      string name=TimeToStr(dailyTime)+" Time_Vertical_Line";
      if(TimeDay(dailyTime)==14 && ObjectFind(0,name)<0)
        {
         if(!ObjectCreate(0,name,OBJ_VLINE,0,dailyTime,0))
            Print("Fail to draw the line ERROR CODE : ",GetLastError());
         ObjectSet(name,OBJPROP_WIDTH,width);
         ObjectSet(name,OBJPROP_COLOR,Color);
         ObjectSet(name,OBJPROP_BACK,true);
        }
     }
 
Lakshan Perera:

here I wrote the code to draw line on the 14th day of the month.. Note it will draw the line on the 00:00 hour of the 14th.. but you can change the code to get it to the day you want

Thank you so much Lakshan, this's what I want!

But there's missing line when the date not on trading days. How to include the weekend day?

 
Panjianom Adi Pratomo:

Thank you so much Lakshan, this's what I want!

But there's missing line when the date not on trading days. How to include the weekend day?

Weekend days are not visible on the chart

 
Panjianom Adi Pratomo: But there's missing line when the date not on trading days. How to include the weekend day?

In MT4 you can only put lines on a bar. Best you can do is to put it on the previous bar.

   for(int i=100;i>=0;i--)
     {
      datetime dailyTime=iTime(Symbol(),1440,i);
      MqlDateTime dt_struct; TimeToStruct(TimeCurrent(), dt_struct);
      if(dt_struct.day < 14) continue;
      if(dt_struct.day >= 14){
         dt_struct.day = 14;
         dailyTime = Time[iBarShift(_Symbol, PERIOD_CURRENT, StructToTime(dt_struct) )];         
      }
      string name=TimeToStr(dailyTime)+" Time_Vertical_Line";
      if(ObjectFind(0,name)<0) ...
     }
 
whroeder1:

In MT4 you can only put lines on a bar. Best you can do is to put it on the previous bar.

Great information whroeder1, I will try your code.

Thank you so much.

 
whroeder1:

In MT4 you can only put lines on a bar. Best you can do is to put it on the previous bar.

Shouldn't that TimeCurrent() be dailyTime or Time[i] or something related to i ?

MqlDateTime dt_struct; TimeToStruct(TimeCurrent(), dt_struct);


MqlDateTime dt_struct; TimeToStruct(dailyTime, dt_struct); // or it could be Time[i] or anything similar to that
 
Lakshan Perera:

Shouldn't that TimeCurrent() be dailyTime or Time[i] or something related to i ?

Yes, with dailyTime it can work.
Thank you so much Lakshan & Whroeder1, it work!

Reason: