Calculation of the slope angle of the trend line.

 
Good afternoon. I need to calculate the angle of slope of the trend line on the chart in degrees programmatically (MQL5). Can you please give me a formula or a method to do this?
 
https://www.mql5.com/ru/forum/97569
Индикатор "Тангенс" для идентификации тренда и флэтта
Индикатор "Тангенс" для идентификации тренда и флэтта
  • www.mql5.com
Если до сих пор не известен подобный индикатор, то, предлагаю его сделать по формуле: tg(alfa) = [C - MA(N)]/N, где: C - текущая цена; MA(N) - знач...
 
Sergei75:
Good afternoon. I need to calculate the slope angle of the trend line on the chart in degrees programmatically (MQL5). Please, advise me either the formula or some other method how to do it.

It is not possible to express the slope in degrees because the degree measure depends on the scale.

The slope of the trend line is measured either in price per bar or price per unit time.

 
George Merts:

It is not possible to express the slope in degrees because the degree measure is scale dependent.

The slope of the trend line is measured either in price per bar or price per unit of time.

Yes, I got it already, after writing the function, with normal scale it calculates correctly, but when you change the scale the angle changes....
 
Sergei75:
Yes, I got it already, after writing the function, with normal scale it calculates correctly, but when you change the scale and the angle changes....

Do you know how to identify a trend line?

How can you determine the start of a trend line? Especially when you want to identify a dynamic or current trend.

If you do it on a certain section, the size of which is set manually, then it's no longer a trend.

 
It is possible to determine both the trend and the exact slope, which is independent of the chart scale
 
George Merts:

It is not possible to express the slope in degrees because the degree measure is scale dependent.

The slope of the trend line is measured either in price per bar or price per unit of time.

...more accurately, it is possible to express it, but the expressed will depend on scale
 
Petros Shatakhtsyan:

Do you know how to identify a trend line?

How can you identify the start of a trend line? Especially when you want to identify a dynamic or current trend.

If you do this on a certain section, the size of which is set manually, it is no longer a trend.

The task was different: to determine the angle of slope of the trend line in degrees ("trend line" tool)
 
Taras Slobodyanik:
...it would be more accurate to say that it is possible to express, but what is expressed will depend on the scale
and so it is.
 
Renat Akhtyamov:

It is possible to determine the trend and the exact slope that does not depend on the chart scale

Here is a function that calculates the slope of the line in degrees, but the accuracy depends on the scale of the graph

//+------------------------------------------------------------------+
//|   функция возвращает значение угла трендовой линии в градусах.   |
//| в параметры функции передаются данные по котрым построена линия  |
//+------------------------------------------------------------------+
double Get_Degree_Angle(datetime time_1, double price_1, datetime time_2, double price_2)
{
   double A, B, C;
   double a_1, a_2, b_1, b_2;
   int x, y;
   ChartTimePriceToXY(0, 0, time_2, price_1, x, y);
   a_1 = (double)x;
   b_1 = (double)y;
   ChartTimePriceToXY(0, 0, time_1, price_1, x, y);
   a_2 = (double)x;
   A = a_1 - a_2;
   ChartTimePriceToXY(0, 0, time_2, price_2, x, y);
   b_2 = (double)y;
   B = b_1 - b_2;
   C = MathSqrt(MathPow(A, 2) + MathPow(B, 2));
   return(MathArcsin(B / C) * 180 / 3.14159);
}

Can you share your method of determining the slope (that does not depend on the scale)?

Reason: