function ObjectGetTimeByValue throws error 4204 for horizontal OBJ_TREND line

 

Good morning, I use ObjectGetTimeByValue to receive the start/first date for OBJ_TREND objects. For just one object the function throws the error 4204. This object is a horizontal trend line having, apparently, the same price for both ends of the line. I think that the function ObjectGetTimeByValue throws the error because it does not know which date to return (beginning or end of trendline). Here is my code:

string current_date;

for(int i=0; i<ObjectsTotal(0,0,-1); i++){
	// First filter out all objects not of type OBJ_TREND. Code not shown here as not relevant. Then get current_date:	
	current_date=ObjectGetTimeByValue(0,ObjectName(0,i,-1,-1),ObjectGetDouble(0,ObjectName(0,i,-1,-1),OBJPROP_PRICE,0),0);
	// do some more stuff with current_date...
}

ObjectGetDouble returns the correct price and does not throw any errors. Same applies to the ObjectName function. The name is received correctly and no error is thrown. 

Can anybody confirm my assumption? I cannot think of any other reason.

Thank you

Documentation on MQL5: Object Functions / ObjectGetTimeByValue
Documentation on MQL5: Object Functions / ObjectGetTimeByValue
  • www.mql5.com
ObjectGetTimeByValue - Object Functions - MQL5 Reference - Reference on algorithmic/automated trading language for MetaTrader 5
 
Maybe you are confusing horizontal line with trend line.

Horizontal lines do not have a date.
 
Dominik Christian Egert #:
Maybe you are confusing horizontal line with trend line.

Horizontal lines do not have a date.
Hi Dominik. No, I am not confusing these two. I use OBJ_TREND to draw trendlines but when a trend is broken I also use this object to draw a horizontal line to indicate that the trend is broken. OBJ_TREND allows to draw horizontal lines as well. Maybe it is a bit misused but OBJ_HLINE draws the line through the entire chart. I wanted to add some images, but I am not yet allowed to post such. Thank you
 

Perhaps you should read the manual. ObjectGetTimeByValue
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

Do you see HLine listed there?

 
William Roeder #:

Perhaps you should read the manual. ObjectGetTimeByValue
   How To Ask Questions The Smart Way. (2004)
      How To Interpret Answers.
         RTFM and STFW: How To Tell You've Seriously Screwed Up.

Do you see HLine listed there?

Hi William, not quite sure if you are referring to my question or to Dominik's answer. HLine is apparently not listed... and as said I am aware of that a horizontal OBJ_TREND line is quite similar but still has a defined beginning and end date. 
 
To me it seems obvious the function you are using is designed to get the date value for a line from an object where the line crosses through multiple price values and it is not (or complex) possible to get the date correlating with a specific price value.

Since your object is not in this "condition" a calculation of such a value is not possible or viable.

So the function returns with the mentioned error.

So in this case you will need to go for a different approach of receiving the date values of the object.

Try ObjectGetInteger and get the values this way.
 
MartinaR:

Good morning, I use ObjectGetTimeByValue to receive the start/first date for OBJ_TREND objects. For just one object the function throws the error 4204. This object is a horizontal trend line having, apparently, the same price for both ends of the line. I think that the function ObjectGetTimeByValue throws the error because it does not know which date to return (beginning or end of trendline). Here is my code:

ObjectGetDouble returns the correct price and does not throw any errors. Same applies to the ObjectName function. The name is received correctly and no error is thrown. 

Can anybody confirm my assumption? I cannot think of any other reason.

Thank you

Of course, if the line is horizontal how could you expected to get a date from a price ?
 
good evening and thank you for further clarification. As stated in my post I was expecting the error resulting from this but wasn't sure whether I missed something. Maybe the function could have returned just the firt date in case the price is identical. Unfortunately you cannot look into the function how it is implemented...Nevertheless thanks for all comments. I will use an if clause to simple catch the error.
 
I suppose that's the best way to go.

But think about how should the function react. Imagine you have a line that at two dates same price. How would you know there might be a second date with the same price, if the function cannot tell you due to the given return value?

Somehow this information needs to be transmitted, after all, you know the price coordinate of the object you created by code. So this gives you possibly the opportunity to compare your search value to the coordinate value and thus let's you determine the price value you query for has more than one date.

Of course this includes the fact of rounding errors on price. Since the x and y pixel coordinates give you an absolute and higher resolution than the price and it's date.

Therefore to take respect to this blur, there needs to be a mechanism to identify these situations.

My thought.
 
Dominik Christian Egert #:
I suppose that's the best way to go.

But think about how should the function react. Imagine you have a line that at two dates same price. How would you know there might be a second date with the same price, if the function cannot tell you due to the given return value?

Somehow this information needs to be transmitted, after all, you know the price coordinate of the object you created by code. So this gives you possibly the opportunity to compare your search value to the coordinate value and thus let's you determine the price value you query for has more than one date.

Of course this includes the fact of rounding errors on price. Since the x and y pixel coordinates give you an absolute and higher resolution than the price and it's date.

Therefore to take respect to this blur, there needs to be a mechanism to identify these situations.

My thought.

Good morning Dominik, thank's for your additional and helpful thoughts!

Reason: