Guarda come scaricare robot di trading gratuitamente
Ci trovi su Facebook!
Unisciti alla nostra fan page
Script interessante?
Pubblica il link!
lasciare che altri lo valutino
Ti è piaciuto lo script? Provalo nel Terminale MetaTrader 5
Visualizzazioni:
3161
Valutazioni:
(19)
Pubblicato:
2018.06.06 14:38
Hai bisogno di un robot o indicatore basato su questo codice? Ordinalo su Freelance Vai a Freelance

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.

Tradotto dal russo da MetaQuotes Ltd.
Codice originale https://www.mql5.com/ru/code/20481

maximus_vX lite maximus_vX lite

The Expert Advisor trades using levels. It can have a maximum of two positions of each type (Buy and Sell) in the market.

WCCI WCCI

A weighted CCI.

Poker_SHOW Poker_SHOW

An Expert Advisor based on a random number generator. Trend is determined using the iMA (Moving Average, MA) indicator.

TrueSort_1100 TrueSort_1100

The Expert Advisor waits when the lines of MA(10), MA(20), MA(50), MA(100) and MA(200) get arranged one above the other (or one below the other).