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
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.
- Of course ObjectCreate doesn't return an error, It just creates a line.
- 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);
You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
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...