Nevermind. For anyone who is interested, you can solved it using something like this:
int time_of_vertical_line = ObjectGet("VerticalLineName", OBJPROP_TIME1); if ( (Period()*60) != 0 ) // This line avoids zero divide errors. { int index_setback_from_0 = (Time[0]-time_of_vertical_line)/(Period()*60); }
The integer value for "index_setback_from_0" will be the numerical index of the bar (relative to the current bar in the usual way).
Nevermind. For anyone who is interested, you can solved it using something like this:
The integer value for "index_setback_from_0" will be the numerical index of the bar (relative to the current bar in the usual way).
Actually, this goes wrong when the chart has time gaps, such as over a weekend!
Yep. Market closed over week end and holidays. Don't hard code numbers and don't assume. Simplify your code. OBJPROP_TIME returns a datetime not an int.
datetime time_of_vertical_line = ObjectGet("VerticalLineName", OBJPROP_TIME1); int index_setback_from_0 = iBarShift(NULL,0, time_of_vertical_line;
Thanks. I forgot about iBarsShift !!!
What does "hard code numbers" mean? (It still works when using int, I'm using it right now).
Thanks. I forgot about iBarsShift !!!
What does "hard code numbers" mean? (It still works when using int, I'm using it right now).
Master WHRoeder ment 'hard core numbers'. LOL!
Thank you for the code snippet, just what I have been looking for.
Best regards,
Simon
S love nia
int index_setback_from_0 = (Time[0]-time_of_vertical_line)/(Period()*60);
@WHRoeder: your iBarShift() code is good and simple. I use homegrown offline.hst generator for Kase True Range Bars. Finding two-bar patterns which forced code down all paths was a very onerous trial and my solution using your code was simple enough.
Plotted vLine with known name. Now all I had to do was drag it around to likely pattern and hotKey a script to show results etc.
You always seem to come up with interesting suggestions which cause one to carefully consider.
![MQL5 - Language of trade strategies built-in the MetaTrader 5 client terminal](https://c.mql5.com/i/registerlandings/logo-2.png)
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
Is there any way to get ObjectGetShiftByValue() to work with vertical lines, or am I wasting my time trying?
I just keep getting the return value of -1, and the error code 4205 (ERR_OBJECT_COORDINATES_ERROR, Object coordinates error).
I'm guessing that is because ObjectGetShiftByValue() requires a price value, whereas vertical lines do not seem to have price values ...
Does anyone know a way around this?