MT4 - Object Create with invalid time creates 'random object'.

Back to topics list To post a new topic, please log in or register
avatar
1
b2885089 2016.03.29 00:43
 

I'm currently using something like this in my code: 

for (int i = 0; i < 10; i++)

{

// someday is date + 10 am

datetime linePos = someValidDate - 60*60*24*i; // minus i-days

ObjectCreate("SOMEPREFIX_" + i, OBJ_VLINE, 0, linePos, 0);

}

This works fine when the date is a valid date, but as you can imagine some days are sundays or saturdays without market data. But ObjectCreate doesn't return -1 in such a case. It draws a line at 10pm and that is very strange. All lines are drawn correctly, but every week there is a random line at 10pm (there is also a 10am line on that day - the 10pm line is the sunday line...). What can I do about this?

 

PS: When I  print someValidDate - 60*60*24*i it always shows 10am...

avatar
Moderator
3416
GumRai 2016.03.29 02:26 #
 

Something like this

   datetime linePos = someValidDate - 60*60*24*i; // minus i-days
   if(iBarShift(Symbol(),PERIOD_H1,linePos,true)>0)
      ObjectCreate("SOMEPREFIX_" + i, OBJ_VLINE, 0, linePos, 0); 

may work. I used PERIOD_H1, so if you do not have the H1 chart open, you will need to make sure that it is kept updated

avatar
12995
WHRoeder 2016.03.29 15:27 #
 
b2885089: This works fine when the date is a valid date, but as you can imagine some days are sundays or saturdays without market data. But ObjectCreate doesn't return -1 in such a case.
  1. Of course ObjectCreate doesn't return an error, It just creates a line.
  2. Don't use someValidDate - 60*60*24*i use a valid date
    for (int i = 0; i < 10; i++){
      datetime linePos = iTime(NULL, PERIOD_D1, i);
      ObjectCreate("SOMEPREFIX_" + i, OBJ_VLINE, 0, linePos, 0); 

Back to topics list  

To add comments, please log in or register