Calculation of the slope angle of the trend line. - page 20

 
Dmitry:

Time is passing, but the tasks remain the same. I have faced the need to calculate the angle of slope of the trend and was about to start doing it on the basis of coordinate points, but by my good fortune I came across this article. I did not take into account that if we are referring to coordinates, the angle will change when zooming.

There is only one solution here, we have to forget about the angle degree in the classical sense. Theoretically, we can construct a triangle where one cathetus is bars and the other cathetus is points, calculate the angle of that triangle. You will get the technical value of the slope angle, it will not change when you change the scale, but you will visually see the angle on the chart quite differently because we have different types of data for the cathetuses.

To my mind, it is better to use the percentage of price change at the moment of time instead of the degrees. After all, it is the numbers by which you build your strategy that are important.

https://www.mql5.com/ru/code/28678

The phase is calculated in degrees, takes values from 0 to 360 and is shown with green line 5 (read from array 4).

The counter phase is also calculated in degrees, takes values from -360 to 0 and is represented by the 6th red line (read from array 5). In calculations it is more convenient to use counter phase values in the sum with 360 (which conventionally raises it to the phase level).


Pan PrizMA CD Phase Sin leverage_72
Pan PrizMA CD Phase Sin leverage_72
  • www.mql5.com
Этот индикатор построен на базе индикатора  PanPrizMA Sin leverage 72  , особенности которого позволяют  посчитать фазу и амплитуду. Иногда это может быть  полезно. Фаза рассчитывается в градусах, принимает значения от 0 до 360 и отображена 5-ой, зеленой линией (снимается с массива 4). Противофаза так же  рассчитывается в градусах, принимает...
 
Dmitry:

Time is passing, but the tasks remain the same. I have faced the need to calculate the angle of slope of the trend and was about to start doing it on the basis of coordinate points, but by my good luck I came across this article. I did not consider at all that if we refer to coordinates the angle will change when zooming in and out.

There is only one solution here, we have to forget about the angle degree in the classical sense. Theoretically, we can construct a triangle where one cathetus is bars and the other cathetus is points, calculate the angle of that triangle. You will get the technical value of the slope angle, it will not change when you change the scale, but you will visually see the angle on the chart quite differently because we have different types of data for the cathetuses.

To my mind, it is better to use the percentage of price change at the moment of time instead of the degrees. After all, it is the numbers by which you build your strategy that are important.

My point of view has not changed. The only correct unit of the trendline slope is the price per time unit. The slope angle characterizes the order in which the line appears on the screen, not the size of the trend at all.

 
Georgiy Merts:

My point of view has not changed. The only correct unit of trendline slope is price per unit of time. The slope angle characterises the order in which the line is displayed, not the magnitude of the trend at all.

I agree. Only the words "the only correct one" are overly categorical. It is the unit of "slope" that has the generally accepted, for everyone the same meaning of the rate of change of the course when moving along the trendline. It is clear that the rate of change is related to the slope angle of the trend line in the same way as the first derivative is related to the slope angle of the graph of any function y(x). The angle is equal to arctg (dy/dx) if the x-value is the same as the y-value on the graph. If they are different, the angle measured with a protractor will be different.

The analogue of the slope angle can be considered not only the rate of change of the course, that is, the derivative of the course over astronomical time, but for example the average increment of the course from tick to tick. Instead of astronomical time, use "proper", or "operational" time - the number of the tick.

 
Georgiy Merts:

My point of view has not changed. The only correct unit of trendline slope is price per unit of time. The slope angle characterises the order in which the line is displayed, not the magnitude of the trend at all.

+++ The scientific approach rules.

All the other beauty of ups and downs is for marketers.

 
Daniil Kurmyshev:

I agree with you, I don't like it, but when I initially created this function, I checked a few different ways, and then I didn't change it) and about the pixels, I completely agree with you, the most ideal calculation of the angle for me personally is this way, here is my function:

//-----------------------------------------------------------------------------------

// xAnglePixels /////////////////////////////////////////////////////////////////////

//-----------------------------------------------------------------------------------

double xAnglePixels(datetime x1,double y1,datetime x2,double y2) // x1,x2 Time[] - y1,y2

{

if(x1==0 || x2==0 || y1==y2){return(0);}

//---

int x[2],y[2];

ChartTimePriceToXY(0,0,x1,y1,x[0],y[0]);

ChartTimePriceToXY(0,0,x2,y2,x[1],y[1]);

//---

if(x[1]<x[0]){return(-1000);}

//---

double x1x2=MathAbs(x[0]-x[1]);

double y1y2=MathAbs(y[0]-y[1]);

//---

double theta;

if(x1x2!=0){theta=MathArctan(y1y2/x1x2)*(180/3.1415926535);}

else{theta=90;}

if(y2<y1){theta=NormalizeDouble(theta*(-1),2);}else{theta=NormalizeDouble(theta,2);}

return(theta);

}

//---------------------------------------------------------------------------------

p.s. in the functionif(x[1]<x[0]){return(-1000);} can be removed, as I used it for myself), and more specifically it is needed if the user has swapped two points of the object in places.

//-----------------

By the way, for the inscriptions on the chart, I use it. Earlier in the branch I posted examples of work of this indicator, there you can see it.

//-----------------

Many thanks to you and respect)

Needed this feature, started testing your function and found that the result

Depends on the scale...

 
Corner is time
 
podotr:
Angle is time

Yep,

time is an angle

 
Denis Sartakov:

Yep,

time is an angle

And you can't eat an angle :-) Corner you can burn

 
Angle is speed and speed is the absence of rest. All running, running...
 
It's time to have a corner yet