#### sDotToLineDist - script for MetaTrader 5 Function parameters:

• double LX1 - the X coordinate of the first point of the line;
• double LY1 - the Y coordinate of the first point of the line;
• double LX2 - the X coordinate of the second point of the line;
• double LY2 - the Y coordinate of the second point of the line;
• double DX - the X coordinate of the point;
• double DY - the Y coordinate of the point. ### Calculation principle

Based on the coordinates of two points of the line, we get the line formula: y=a+k*x. The k coefficient determines the slope of the line, i.e. a change in the y coordinate per a unit of change in the x coordinate. The k coefficient is calculated as follows:

`double K=(LY2-LY1)/(LX2-LX1);`

The a constant determines the value of the line, if x=0, i.e. corresponds to the level, where the line crosses the y axis. Knowing the slope coefficient and the X coordinate of one of the line points, we calculate a:

`double LA=LY1-K*LX1;`

The distance from a point to the line is determined based on the perpendicular drawn to the line. If you rotate the drawing 90 degrees counterclockwise, the d line will have the same slope as the main line, but with the opposite sign. Knowing the slope and the coordinates of one point, we can get the equation of the line, but in this case in the form x =a-ky. So, the a constant:

`double DA=DX+K*DY;`

Having the formulas of two lines, we find the point of their intersection. For this purpose, we substitute y expressed by the formula of the first line to the formula of the second line, make some transformations and obtain the x coordinate of the intersection point:

`double CX=(DA-K*LA)/(1.0+K*K);`

Then substitute the resulting x in the formula for the first line, and obtain the y coordinate of the point of intersection of lines:

`double CY=LA+K*CX;`

Knowing the coordinates of two points, we can calculate the distance between them along the x and y axes (the projections on the axis). Further, using the Pythagorean theorem, calculate the distance:

`MathSqrt(MathPow(DX-CX,2)+MathPow(DY-CY,2))`

A discussion in Russian is available at https://www.mql5.com/ru/forum/237198. You can also discuss the idea here, in comments. Related News

Latest News
Two Expected 2020 IPOs Bring Hope to Egypt’s Subdued Market
10.12.2019 05:15
(Bloomberg) -- Egypt’s ailing stock market could find a much-needed jolt of liquidity from two state-owned enterprises set to go public early next year. The long-awaited initial public offering of one of the biggest banks in the country, Banque du Caire, in particular could draw funds from outside the region, according to Hasnain Malik, head of
Gold’s Been on a Tear This Year and 2020 May See More Reward
10.12.2019 05:12
(Bloomberg) -- Gold’s impressive advance in 2019 -- aided by trade war frictions, easier monetary policy across the world’s leading economies and sustained central-bank buying -- may be set to spill into the new decade. As 2020 looms, BlackRock Inc (NYSE:BLK)., the world’s largest money manager, remains constructive on bullion as a hedge, while