Does ObjectGetShiftByValue() work with vertical lines?

 

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?

 

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).

 
clerin6:

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!
 
clerin6: 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).

 
clerin6:

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

 
clerin6: What does "hard code numbers" mean? (It still works when using int, I'm using it right now).
int index_setback_from_0 = (Time[0]-time_of_vertical_line)/(Period()*60);
This assumes that there is a bar for every time period. Not valid assumption over weekends, market holidays, and minute charts ('"Free-of-Holes" Charts - MQL4 Articles.)
 

@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.

Regards...
Reason: