
- www.mql5.com
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.
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 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 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.
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.
...it would be more accurate to say that it is possible to express, but what is expressed will depend on the scale
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)?

- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
You agree to website policy and terms of use