Download MetaTrader 5

Problem getting angle of a trend line in build 600

To add comments, please log in or register
Develop applications to order. Make profit using Freelance service!
gbownes
26
gbownes 2014.02.12 00:39 

The following code has been entered in a CHARTEVENT_OBJECT_CREATE event handler in an indicator

#1    ObjectCreate(0, "Angle", OBJ_TRENDBYANGLE, 0, timePt1, pricePt1, timePt2, pricePt2);

#2    ObjectSetDouble (0, "Angle", OBJPROP_PRICE2, pricePt2);

#3    ObjectSetInteger (0, "Angle", OBJPROP_TIME2, timePt2);

#4    angle = ObjectGet ("Angle", OBJPROP_ANGLE);


I have encountered two problems with this code. Line #1 creates a trend line using two sets of time/price coordinates. The trendline is created as a vertical line at the first set of coordinates. ObjectCreate function seems to ignore the second set of coordinates. It is necessary to set the price and time separately for the second coordinates and this works, although it should not be necessary.

The second problem is that line #4 always returns 0.0. I am unable to determine the angle of the line.

Any help to understand how to resolve this problem would be appreciated. It seems to me that there are two bugs here, but perhaps, I am doing something wrong. I have tried to find some good documentation on event handling but unfortunately, I have found only the most basic documentation that does not get into all the details of handling events. It occurs to me that it might not be possible to create a new graphical object when handling the create event for another graphical object, for instance, and I might need to create a custom event to create the new object.

Anther problem that I have encountered (I have not included any code for it here) is that when I delete a graphical object from a chart, I expect to get a CHARTEVENT_OBJECT_DELETE event, but I get instead a CHARTEVENT_OBJECT_CHANGE event. This appears to be a bug as well.

Simon Gniadkowski
Moderator
17998
Simon Gniadkowski 2014.02.12 00:43  
gbownes:

The following code has been entered in a CHARTEVENT_OBJECT_CREATE event handler in an indicator


Perhaps you would get more success posting to the correct forum ?
To add comments, please log in or register