Does ObjectGetShiftByValue() work with vertical lines?

Back to topics list To post a new topic, please log in or register
avatar
648
clerin6 2012.06.23 13:01
 

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?

 
avatar
648
clerin6 2012.06.23 14:11 #
 

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


 
avatar
648
clerin6 2012.06.23 14:32 #
 
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!
 
avatar
12988
WHRoeder 2012.06.23 14:57 #
 
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;
 
avatar
648
clerin6 2012.06.23 15:09 #
 

Thanks. I forgot about iBarsShift !!!

What does "hard code numbers" mean? (It still works when using int, I'm using it right now).

 
avatar
58
Chistabo 2015.04.25 17:52 #
 
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

avatar
12988
WHRoeder 2015.04.25 19:18 #
 
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.)
avatar
865
fbj 2016.06.06 18:05 #
 

@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...
Back to topics list  

To add comments, please log in or register