Download MetaTrader 5
To add comments, please log in or register
Publish your trading signal. Gain access to millions of traders!
Clerin
176
Clerin 2012.06.23 11: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?

Clerin
176
Clerin 2012.06.23 12: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).

Clerin
176
Clerin 2012.06.23 12: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!
whroeder1
13627
whroeder1 2012.06.23 12: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;
Clerin
176
Clerin 2012.06.23 13:09  

Thanks. I forgot about iBarsShift !!!

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

Chistabo
140
Chistabo 2015.04.25 15: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

whroeder1
13627
whroeder1 2015.04.25 17: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.)
fbj
1047
fbj 2016.06.06 16: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...
/
To add comments, please log in or register