Problem getting angle of a trend line in build 600

 

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.
 
gbownes:

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.

You should read the documentation,
OBJ_TRENDBYANGLE3Trend by angle. Uses 1 coordinate. To set angle of line use ObjectSet() function.



 
RaptorUK:
You should read the documentation,

My documentation set for MQL4 says the following:


OBJ_TRENDBYANGLE

Trend Line By Angle.

Note

For Trend Line By Angle, it is possible to specify the mode of continuation of its display to the right and/or left (OBJPROP_RAY_RIGHT and OBJPROP_RAY_LEFT properties accordingly).

Both angle and the second anchor point's coordinates can be used to set the slope of the line.

Example

The following script creates and moves the trend line on the chart. Special functions have been developed to create and change graphical object's properties. You can use these functions "as is" in your own applications.

 
gbownes:

My documentation set for MQL4 says the following:


OBJ_TRENDBYANGLE

Trend Line By Angle.

Note

For Trend Line By Angle, it is possible to specify the mode of continuation of its display to the right and/or left (OBJPROP_RAY_RIGHT and OBJPROP_RAY_LEFT properties accordingly).

Both angle and the second anchor point's coordinates can be used to set the slope of the line.

Example

The following script creates and moves the trend line on the chart. Special functions have been developed to create and change graphical object's properties. You can use these functions "as is" in your own applications.

Which version of ObjctCreate() are you using ?
 
RaptorUK:
Which version of ObjctCreate() are you using ?


How can I get the version? (I am using build 600 if that helps)
 
gbownes:

How can I get the version? (I am using build 600 if that helps)
Show the code for the ObjectCreate() call . . . there are two versions of the call, check the Help in MetaEditor. This is where the mql4.5 mess is very apparent.
 
RaptorUK:
Show the code for the ObjectCreate() call . . . there are two versions of the call, check the Help in MetaEditor. This is where the mql4.5 mess is very apparent.


Sorry, I misunderstood your question. I have the two versions in my documentation as shown below:


ObjectCreate

The function creates an object with the specified name, type, and the initial coordinates in the specified chart subwindow of the specified chart. There are two variants of the function:

bool ObjectCreate(
long chart_id, // chart ID
string name, // object name
ENUM_OBJECT type, // object type
int window, // window index
datetime time1, // time of the first anchor point
double price1, // price of the first anchor point
...
datetime timeN=0, // time of the N-th anchor point
double priceN=0 // price of the N-th anchor point
);

The function creates an object with the specified name, type, and the initial coordinates in the specified chart subwindow:

bool ObjectCreate(
string name, // object name
ENUM_OBJECT type, // object type
int window, // window index
datetime time1, // time of the first anchor point
double price1, // price of the first anchor point
datetime time2=0, // time of the second anchor point
double price2=0, // price of the second anchor point
datetime time3=0, // time of the third anchor point
double price3=0 // price of the third anchor point
);


I am using the first version with the ChartID as the first parameter. I have also tried using the second version of the function with the same result. Here is the code, I am using. The time and price coordinates are obtained from another graphical object and I am trying to create a parallel line by determining the angle of the original line.

double pricePt1 = 0.0;
double pricePt2 = 0.0;

datetime timePt1;
datetime timePt2;

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

 
gbownes:

Sorry, I misunderstood your question. I have the two versions in my documentation as shown below:



I am using the first version with the ChartID as the first parameter. I have also tried using the second version of the function with the same result. Here is the code, I am using. The time and price coordinates are obtained from another graphical object and I am trying to create a parallel line by determining the angle of the original line.

So all you need to do is offset the price coordinates by the same value and your line will be parallel.

The two versions of ObjectCreate() and the old mql4 version and new mql4.5 version . . . the documentation is inadequate and you will have to test for yourself what works and doesn't work. I assume that parameters taken from mql5 won't work with the mql4 version but this is not stated . . .
Reason: