Download MetaTrader 5
To add comments, please log in or register
Use searching on MQL5.community. It is easy!
leong
23
leong 2014.03.27 07:48 

Hi guys... I don't really know how to do this. Not even sure if it is possible...

Problem description:
1)Draw a line from the start of today (day 0) till the end of tomorrow.

-The issue I have is that there is no way to draw a line into the future (or I just don't know how). I don't want to use a horizontal line or a rayed-trendline. I simply want to use a trendline that will draw from the current day up till the next day. Things like iTime only returns a value up to bar 0 which is the current bar.

Example:

ObjectCreate("line",OBJ_TREND,0,iTime(NULL,PERIOD_D1,0),1305.00,iTime(NULL,PERIOD_D1,tomorrow's_time),1305.00); 
ObjectSet("line",OBJPROP_RAY, False); 


2)When a new day is here (day_0 ), remove lines from yesterday (day 1).

-I don't want to have a million lines so to keep things clean, I want to delete the previous day's lines. The reason I'm asking is because I want to know if it is efficient remove the drawings and redraw them every time the script is executed (which I set to execute every hour). Or is there a more efficient way to do this.

My current code:

datetime oldbartime=Time[0]; 

int start() 

if (oldbartime != Time[0]) 
{
ObjectDelete("line"); 
ObjectCreate("line",OBJ_TREND,0,iTime(NULL,PERIOD_D1,0),1305.00,iTime(NULL,PERIOD_D1,tomorrow's_time),1305.00); 
ObjectSet("line",OBJPROP_RAY, False); 
}
qjol
3243
qjol 2014.03.27 10:13  
thelws:


1)Draw a line from the start of today (day 0) till the end of tomorrow.

datetime tomorrows_time = iTime(NULL,PERIOD_D1,0) + 86399;
ObjectCreate("line",OBJ_TREND,0,iTime(NULL,PERIOD_D1,0),1305.00,tomorrows_time,1305.00);
thelws:
-I don't want to have a million lines so to keep things clean, I want to delete the previous day's lines. The reason I'm asking is because I want to know if it is efficient remove the drawings and redraw them every time the script is executed (which I set to execute every hour). Or is there a more efficient way to do this.

you can use

ObjectSet("line",OBJPROP_PRICE1, iTime(NULL,PERIOD_D1,0));    
ObjectSet("line",OBJPROP_PRICE2, tomorrows_time);    
leong
23
leong 2014.03.28 03:07  

works great. thx qjol.


should add that it should be 172800 instead of 86399. :)

qjol
3243
qjol 2014.03.28 03:18  
thelws:

should add that it should be 172800 instead of 86399. :)


-1 = 172799

I thought you need the end of the day

leong
23
leong 2014.03.31 06:32  

Er sorry for bumping. Something came up...

I had an issue when it came to weekends. I'm not sure if this is working as intended, but the mt4 client counted the weekends as part of the calculation.

Problem description:

-How to draw a line to connect from Friday to Monday. If I drew a line till "iTime(NULL,PERIOD_D1,1) + 172799", the lines appear truncated because the weekends are longer than 172799 secs.



qjol
3243
qjol 2014.03.31 06:46  

make an if statement

   datetime tomorrows_time = iTime(NULL,PERIOD_D1,0) + 172799;
   if (TimeDayOfWeek(iTime(NULL,PERIOD_D1,0)) == 5)
   tomorrows_time = iTime(NULL,PERIOD_D1,0) + 259199;

problem solved ;-)

leong
23
leong 2014.03.31 07:24  

ahh. goodstuff :)

thx again qjol

/
To add comments, please log in or register