Questions from Beginners MQL5 MT5 MetaTrader 5 - page 480

You are missing trading opportunities:
- Free trading apps
- Over 8,000 signals for copying
- Economic news for exploring financial markets
Registration
Log in
You agree to website policy and terms of use
If you do not have an account, please register
Please help translate the algorithm for finding the coordinates of the intersection point of two segments
From the article:
It's very simple!
Maybe someone has a ready-made one in the archives?x1,y1 and x2,y2 are coordinates of vertices of the first segment;
x3,y3 and x4,y4 are coordinates of the vertices of the second segment;
to find the intersection we make the equations of the lines:
first equation:
(x-x1)/(x2-x1)=(y-y1)/(y2-y1);
second equation
(x-x3)/(x4-x3)=(y-y3)/(y4-y3);
these equations define a line passing through two points, which is what we need.
From these equations we find x and y by the following formulas:
x:=((x1*y2-x2*y1)*(x4-x3)-(x3*y4-x4*y3)*(x2-x1))/((y1-y2)*(x4-x3)-(y3-y4)*(x2-x1));
y:=((y3-y4)*x-(x3*y4-x4*y3))/(x4-x3);
since our lines intersect, they have a common intersection point with the coordinates (x,y), which we need to find.
For the intersection to belong to our line segments, we need to constrain it, i.e. check the condition:
if
(((x1<=x)and(x2>=x)and(x3<=x)and(x4 >=x))or((y1<=y)and(y2>=y)and(y3<=y) and(y4>=y))
then there is an intersection point of these segments, and if there is not, there is no intersection point.
You should also check the parallelism of these segments using angle coefficients:
k1:=(x2-x1)/(y2-y1);
k2:=(x4-x3)/(y4-y3);
where k1 and k2 are the tangents of the angles of the segments to the positive direction of the OX axis, if k1=k2, then the segments are parallel and therefore have no points of intersection.
Hello dear friends!
Please help translate the algorithm for finding the coordinates of intersection point of two line segments
From the article:
It's very simple!
Maybe someone has a ready one in the archives?x1,y1 and x2,y2 are the coordinates of the vertices of the first segment;
x3,y3 and x4,y4 are coordinates of the vertices of the second segment;
to find the intersection we make the equations of the lines:
first equation:
(x-x1)/(x2-x1)=(y-y1)/(y2-y1);
second equation
(x-x3)/(x4-x3)=(y-y3)/(y4-y3);
these equations define a line passing through two points, which is what we need.
From these equations we find x and y by the following formulas:
x:=((x1*y2-x2*y1)*(x4-x3)-(x3*y4-x4*y3)*(x2-x1))/((y1-y2)*(x4-x3)-(y3-y4)*(x2-x1));
y:=((y3-y4)*x-(x3*y4-x4*y3))/(x4-x3);
since our lines intersect, they have a common intersection point with the coordinates (x,y), which we need to find.
For the intersection to belong to our line segments, we need to constrain it, i.e. check the condition:
if
(((x1<=x)and(x2>=x)and(x3<=x)and(x4 >=x))or((y1<=y)and(y2>=y)and(y3<=y) and(y4>=y))
then there is an intersection point of these segments, and if there is not, there is no intersection point.
You should also check the parallelism of these segments using angle coefficients:
k1:=(x2-x1)/(y2-y1);
k2:=(x4-x3)/(y4-y3);
where k1 and k2 are the tangents of the angles of the segments to the positive direction of the OX axis, if k1=k2, then the segments are parallel and therefore have no points of intersection.
It's a bit complicated... I wrote the definition of the intersection of the lines, one at 2m highs and the other at 2m lows, further than the next bar or not. I wrote it using tangent, the ratio of the price difference in pips to the number of bars between the Haijs on which the line is drawn. Correspondingly, it is the tangent of the angle of the second line at lowes. And then I use the tangent to find the number of points on the next bar, i.e. I use the inverse formula with the changed value of one cathetus (the number of bars). We obtain the price value at the tested point of these lines. And accordingly if the price value of the straight bar is less, the crossing has occurred.
But so far I can't find this indicator.
...
Or maybe someone has a ready-made one in the archives?
Kim posted a function. The function returns the price of the point of the ray drawn from the line to the right.
x1 - bar of the first line coordinate, y1 - price of the first line coordinate. x2 - bar of the second line coordinate, y2 - price of the second line coordinate, x - the bar for which the price is returned.
You can find the prices for each of the two lines and see if they overlap...
I've written here sort of..., something counts and is drawn, but not at every intersection. There's something wrong with my writing. I don't understand what it is.
Thank you very much Alexey and Artem for your attention to my question!
I've written here sort of..., something counts and is drawn, but not at every intersection. There's something wrong with my writing. I don't know what it is.
At the moment, I'm not able to understand anything in programming, it's my beloved wife's birthday today. She is 18 years and 384 months old.
But!!! Note that the crossing of the lines can happen IN or OUT of the bars, and the price (Y coordinate) can only be obtained on the bar. Either before or after, but the crossover point cannot always be determined. I'd say that's rare. Considering the above, revise your code with this in mind, maybe it will work.
Alexey Viktorov 2015.12.12 17:33 # RU
She's turned 18.
Please advise what kind of commands should be inserted into the Expert Advisor so that it automatically corrects the already set takeprofits in the open positions when recalculating them. Or maybe there is a script that corrects all of the stops on the last set?
Please advise how to add code so that in the strategy tester you can change-fit weights of patterns. m_pattern_0(90) replace input variables
I'm not very good with OOP, I get errors"member function not defined" or the code simply doesn't work.
Similar unanswered question here https://www.mql5.com/ru/forum/13484
p.s.: With CiCustom I can change weights for models, but with standard indicators that have standard classes (like CSignalEnvelopes etc.) where are the methods for setting values for each model, but they are not yet available inthe Wizard?
Or maybe it was already suggested somewhere?
Something will be loaded from MetaQuotes site and I get the following picture:
Top : Database 2049/12358 records.
The penultimate one is from 17.10.2014, the last one is from 14.07.1993.
Where are the missing ones?