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); } }
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?
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
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) ... }
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.
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
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!

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
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.