sDotToLineDist - MetaTrader 5 Script | Trading Script Download - MT4/MT5 Resources

Function parameters:

According to the coordinates of the two points of the straight line, we get the straight line formula: y=a+k*x . This k coefficient determines the slope of the straight line, that is, the coordinate x coordinates for each unit change in y . The k coefficient is calculated as follows:
Double K=(LY2-LY1)/(LX2-LX1);This constant determines the value of the line, if x=0 , which corresponds to the level at which the line crosses the y-axis. Knowing the slope coefficient and the X-coordinate of one of the line points, we calculate one :
Double LA=LY1-K*LX1;The distance from a point to a line is determined based on a line drawn perpendicular to the line. If you rotate the plot 90 degrees counterclockwise, the d- line has the same slope as the main line, but the opposite sign. Knowing the slope and coordinates of a point, we can get the equation of the straight line, but in this case, it's of the form x=a-ky . So, a continuous:
Double DA=DX+K*DY;With the formulas for two straight lines, we can find their intersection. To do this, we replace y to express the formula in the first row to the formula in the second row, perform some transformations, and get the x intersection coordinates:
Double CX=(DA-K*LA)/( 1.0 +K*K);
Then substitute the obtained x into the first line of formula to get the coordinates of the intersection of the y line:
Double CY=LA+K*CX;Knowing the coordinates of two points, we can calculate the distance between them along the x- and y-axes (projections on the axes). Further, use the Pythagoras theorem to calculate the distance:
Math square root ( math package (DX-CX, 2 ) + math package (DY-CY, 2 ))
Discussion in Russian is available at https://www.mql5.com/ru/forum/237198 . You can also discuss this idea in the comments here.
Attachment download
📎 sdottolinedist.mq5 (0.74 KB)
Source: MQL5 #20481
💡 Featured Recommendations
✍️ Latest by the author
- •
- •
- •
- •
- •
- •
📌 Popular topics
- •
- •
- •
- •
- •
- •
- •
- •
🔗 You May Be Interested In
- •
- •
- •
- •
- •
- •