Angle in degrees of a trendline and OBJPROP_ANGLE

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



 

Hi Dear Sr. Programmers.


could you please help me. I am struggling to draw a Vline at a particular angle

example: if you assume the chart window screen from left corner to right corner is 360 degrees if i want to draw a Vline for every 30 degrees (or whatever i give in input selections), How i can i achieve this please?


the vlines are based on time and price i could not get it drawn on a particular area of the screen .


your help is highly appreciated.


Thanks,


Rao

 
phanidhar.rao: left corner to right corner is 360 degrees if i want to draw a Vline for every 30 degrees
  1. Don't Hijack other threads for your off-topic post. Next time, make your own, new, thread.

  2. Loop through the bars, left most to right most, step n/(360/30)
              Chart Price Max/Min - MQL4 programming forum
 
double read_angle(double price1,long time1,double price2,long time2)
  {
   double result=0;

   int x1=0,x2=0;
   int y1=0,y2=0;
   long chart = ChartGetInteger(0,CHART_HEIGHT_IN_PIXELS,0);

   ChartTimePriceToXY(0,0,time1,price1,x1,y1);
   ChartTimePriceToXY(0,0,time2,price2,x2,y2);
   int size = (int)chart;
   y1=size-y1;
   y2=size-y2;
   double angle =NormalizeDouble((MathArctan(((double)y2-(double)y1)/((double)x2-(double)x1))*180)/M_PI,1);
   result=angle;
   return(result);
  }
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.



 

 


 
rahman jangjoo #:
And if you change the vertical scale or bar width, you get a different number. Meaningless.