Download MetaTrader 5

Angle in degrees of a trendline and OBJPROP_ANGLE

To add comments, please log in or register
Umberto
40
Umberto  
When you draw a Trendline by Angle, the angle in degrees of a Trendline is only a corner "visual" tied to the monitor, not to the chart. 

For example, a Trendline by Angle of 45 degrees is a line of 45 degrees on the display.
Zooming-in or zooming-out or compressing the vertical scale of prices, or changing timeframe, this trendline stays put at a 45 degree visual angle.

Therefore, the angle in degrees of a Trendline by Angle has no relation to time or price. 

With the mql4 code, you can find the angle of this trendline with the OBJPROP_ANGLE property, querying the trendline by angle with ObjectGet ("name_TrendlineByAngle" OBJPROP_ANGLE)

Similarly, with a classic Trendline, drawn between two points on the price chart, the visual angle is also tied to the display 

mode of the graph: timeframe, compression of the vertical scale of prices, etc.. 

To calculate the angle in degrees of a classic Trendline, you can not use the property OBJPROP_ANGLE: 
ObjectGet ("nomeTrendline" OBJPROP_ANGLE) is always equal to zero. 

To calculate the angle of the classic trendline you have to calculate the angle of the triangle built on two points of the trendline, expressed in pixels measured from the upper left corner of the window, as the pictures below and attached script.



 

uint i=30;

ObjectCreate("ClassicTrendline",OBJ_TREND,0,Time[i],High[i],Time[0],High[0]);
ObjectSetInteger(0,"ClassicTrendline", OBJPROP_RAY, false);
ObjectSetInteger(0,"ClassicTrendline", OBJPROP_WIDTH, 2);
ObjectSetInteger(0,"ClassicTrendline", OBJPROP_COLOR,clrBlue);

int x2,y2,x1,y1;
ChartTimePriceToXY(0,0,Time[i],High[i],x2,y2);
ChartTimePriceToXY(0,0,Time[0],High[0],x1,y1);
double base    = x1-x2;
double height = y1-y2;
double degrees = MathArctan(height/base)*(360/(2*M_PI));
commento = commento + "\n the triangle constructed between these two points has   Base = "+MathAbs(base)+" pixel    Height = "+MathAbs(height)+" pixel";
commento = commento + "\n   with an angle equal to   Arctg(height/base) * 360/(2*3.14) = "+DoubleToString(degrees,1);
commento=commento+"\n";
commento = commento + "\nANGLE IN DEGREES of trendline obtained with Arctangent = "+DoubleToString(MathMod((360-degrees),360),1);

Comment(commento);

 


Files:
whroeder1
15335
whroeder1  
umbertosm:

Zooming-in or zooming-out or compressing the vertical scale of prices, or changing timeframe, this trendline stays put at a 45 degree visual angle.

Therefore, the angle in degrees of a Trendline by Angle has no relation to time or price.

Because angle or tan(x/y) must be unit-less. X/Y is. A chart has price and time. Like saying what is the angle of a car going 30 miles in 15 minutes. Meaningless. You can specify the slope pips/time but not an angle.

After Angle Formula - MQL4 forum



To add comments, please log in or register