- There is no angle from 2 anchor points. An angle requires distance/distance a unitless number. A chart has price/time. What is the angle of going 30 miles in 45 minutes? Meaningless!
- You can get the slope from a trendline. Delta price/ delta time. Changing the axes scales changes the apparent angle, the slope is constant. Angle is meaningless.
- You can create a angled line using one point and setting the angle. The line is drawn that angle in pixels. Changing the axes scales does NOT change the angle.
Did you test your code renzbub ?
it give an horizontal line instead of an angle line.
this code use a chart ID :
ObjectGetDouble(0,"TrendByAngle",OBJPROP_ANGLE,0);
this one do not :
ObjectCreate("TrendByAngle",OBJ_TRENDBYANGLE,0,time1,highestHigh1,time2,highestHigh2);
it seem someone have to do it this way, to get a trend line on the chart :
ObjectDelete("TrendByAngle"); ObjectCreate("TrendByAngle",OBJ_TRENDBYANGLE,0, 0,0,0,0); ObjectSet ("TrendByAngle",OBJPROP_TIME1,time1); ObjectSet ("TrendByAngle",OBJPROP_PRICE1,highestHigh1); ObjectSet ("TrendByAngle",OBJPROP_TIME2,time2); ObjectSet ("TrendByAngle",OBJPROP_PRICE2,highestHigh2); ObjectSet ("TrendByAngle",OBJPROP_COLOR,Lime); ObjectSet ("TrendByAngle",OBJPROP_WIDTH,2);
int highest1 = iHighest(NULL,0,MODE_HIGH,2,0);
Can't be done.
- There is no angle from 2 anchor points. An angle requires distance/distance a unitless number. A chart has price/time. What is the angle of going 30 miles in 45 minutes? Meaningless!
- You can get the slope from a trendline. Delta price/ delta time. Changing the axes scales changes the apparent angle, the slope is constant. Angle is meaningless.
- You can create a angled line using one point and setting the angle. The line is drawn that angle in pixels. Changing the axes scales does NOT change the angle.
I apologise but I meant to say 4 anchor points :
time1 & highestHigh1 marks one specific point on the chart
time2 & highestHigh2 marks a second specific point on the chart
These 2 points will draw a line with an angle depending on where the points are located.
When I crate an object with :
ObjectCreate("TrendByAngle",OBJ_TREND,0,time1,highestHigh1,time2,highestHigh2);
It always places a line on the chart exactly how I want it. Located based on the previous 2 high's.
But when I use :
ObjectCreate("TrendByAngle",OBJ_TRENDBYANGLE,0,time1,highestHigh1,time2,highestHigh2);
The line is always horizontal it doesn't seem to read the anchor points. Hence my problem.
Did you test your code renzbub ?
it give an horizontal line instead of an angle line.
this code use a chart ID :
this one do not :
it seem someone have to do it this way, to get a trend line on the chart :
That's great. It draws the line using ObjectCreate() and sets the coordinates using ObjectSet() as written :
// OnTick() event handler void OnInit() { // Finding 1st highest high on price (3 bars back) int highest1 = iHighest(NULL,0,MODE_HIGH,2,0); double highestHigh1 = High[highest1]; datetime time1 = iTime(NULL,0,highest1); // Finding previous 2nd highest high on price (starts 9 bars back to 20) int highest2 = iHighest(NULL,0,MODE_HIGH,100,3); double highestHigh2 = High[highest2]; datetime time2 = iTime(NULL,0,highest2); ObjectCreate("TrendByAngle",OBJ_TRENDBYANGLE,0,0,0,0,0); ObjectSet("TrendByAngle",OBJPROP_TIME1,time1); ObjectSet("TrendByAngle",OBJPROP_PRICE1,highestHigh1); . ObjectSet("TrendByAngle",OBJPROP_TIME2,time2); ObjectSet("TrendByAngle",OBJPROP_PRICE2,highestHigh2); ObjectSet("TrendByAngle",OBJPROP_COLOR,Red); ObjectSet("TrendByAngle",OBJPROP_WIDTH,1); double angle2=ObjectGetDouble(0,"TrendByAngle",OBJPROP_ANGLE,0); if(angle2 == 168.9) { ObjectCreate("ThumbUp",OBJ_ARROW_THUMB_UP,0,time1,highestHigh1); } else { ObjectCreate("ThumbDown",OBJ_ARROW_THUMB_DOWN,0,time1,highestHigh1); } }
but unfortunately ObjectGetDouble() still doesn't get the angle as it returns 0 degree's. Im thinking the reason why is because its only reading ObjectCreate before its being set by ObjectSet() and so is why its reading 0?
You have to give the object an angle to start with
ObjectCreate("TrendByAngle",OBJ_TRENDBYANGLE,0,0,0,0,0); ObjectSet("TrendByAngle",OBJPROP_TIME1,time1); ObjectSet("TrendByAngle",OBJPROP_PRICE1,highestHigh1); ObjectSetDouble(0,"TrendByAngle",OBJPROP_ANGLE,45);
Then you can adjust the parameters
ObjectSet("TrendByAngle",OBJPROP_TIME2,time2); ObjectSet("TrendByAngle",OBJPROP_PRICE2,highestHigh2);
and retrieve the angle
//double angle2=ObjectGetDouble(0,"TrendByAngle",OBJPROP_ANGLE,0); double angle2=ObjectGetDouble(0,"TrendByAngle",OBJPROP_ANGLE);
You don't need the last parameter to get the value
You have to give the object an angle to start with
Then you can adjust the parameters
and retrieve the angle
You don't need the last parameter to get the value
Here it understand only the first setting of the angle at 45degrees but still not the angle drawn on chart.
// OnTick() event handler void OnInit() { // Finding 1st highest high on price (3 bars back) int highest1 = iHighest(NULL,0,MODE_HIGH,2,0); double highestHigh1 = High[highest1]; datetime time1 = iTime(NULL,0,highest1); // Finding previous 2nd highest high on price (starts 9 bars back to 20) int highest2 = iHighest(NULL,0,MODE_HIGH,100,3); double highestHigh2 = High[highest2]; datetime time2 = iTime(NULL,0,highest2); ObjectCreate(0,"TrendByAngle",OBJ_TRENDBYANGLE,0,0,0,0,0); ObjectSet("TrendByAngle",OBJPROP_TIME1,time1); ObjectSet("TrendByAngle",OBJPROP_PRICE1,highestHigh1); ObjectSetDouble(0,"TrendByAngle",OBJPROP_ANGLE,45); // You have to give the object an angle to start with ObjectSet("TrendByAngle",OBJPROP_TIME2,time2); // Then you can adjust the parameters ObjectSet("TrendByAngle",OBJPROP_PRICE2,highestHigh2); ObjectSet("TrendByAngle",OBJPROP_COLOR,Red); ObjectSet("TrendByAngle",OBJPROP_WIDTH,1); double angle=ObjectGetDouble(0,"TrendByAngle",OBJPROP_ANGLE); // and retrieve the angle if(angle == 45) { ObjectCreate("ThumbUp",OBJ_ARROW_THUMB_UP,0,time1,highestHigh1); } else { ObjectCreate("ThumbDown",OBJ_ARROW_THUMB_DOWN,0,time1,highestHigh1); } }
If only there was a way to redraw the angle so 2nd time ObjectGetDouble could understand the new angle? Or use another function to retrieve the new angle info.
Use slope and not angle.
Angle is not correct anyhow, the angle that you get is true only toards your current chart display - meaning that it is used for you just to see it on the chart, and if you change the chart scale it will still stay the same angle but the line axes will change accordingly (the other price2,time2 axes will change to show you the same angle on the new chart scale. only the price1,time1 will stay the same so it's meaningless).
So, just use slope.
Use slope and not angle.
Angle is not correct anyhow, the angle that you get is true only toards your current chart display - meaning that it is used for you just to see it on the chart, and if you change the chart scale it will still stay the same angle but the line axes will change accordingly (the other price2,time2 axes will change to show you the same angle on the new chart scale. only the price1,time1 will stay the same so it's meaningless).
So, just use slope.
I see that would explain why It could never find the angle. But, I cant find slope in reference. Is this an enumeration?
renzbub: I cant find slope in reference. Is this an enumeration?
| slope = change in price / change in time. |
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use
What I want to do is to create a trendline with angle based on 2 anchor points and then find the angle using ObjectGetDouble() so it can help me do various trading tasks such as finding chart patterns. See the code below :
Problem is according to MQL4 Reference the enumeration OBJ_TRENDBYANGLE needs an angle and 2nd anchor point. When I need to create the line based on only 2 anchor points where the angle is a result of those anchor points.
I find it no problem drawing a line based on 2 anchor points using enumeration OBJ_TREND but this doesn't have an angle and so ObjectGetDouble() cant recognise?