That's right ... And I need the length of the Red Line... Imagine if these two parallel lines were vertical, what would the blue line show ?
It is possible that this red line will not be perpendicular due to the fact that it can be drawn only by bar price and time.
As an option, I see the following sequence: we determine the slope of the trend line or plot the trend line by an angle and obtain the perpendicular angle by which we calculate the distance to the second line.
It is possible that this red line will not be perpendicular because it can only be drawn based on the bar price and time.
As an option, I see the following sequence: we determine the slope of the trend line or draw the trend line by the angle and obtain the perpendicular angle based on which we calculate the distance to the second line.
All right ... And I need the length. the red line. Imagine if the two parallel lines were vertical, what would the blue line show ? (at different angles, will be different length)
If you draw two parallel lines 10 cm apart on a white sheet of paper(Fig.7), you can twist the sheet at any angle and it will still be the same 10 cm(Fig.6).
I'm confused about your goals...
Tell me what you have initially, please. It's not clear to me how you can ask about distance if we don't have parallel lines, and if we do, how is the second line constructed without that data?
Above you cited the code of the two lines, but, allow me, there is no parallelism there at all.
Or is the task just to build parallel lines? Or to check if the lines are parallel? Or just find the difference between any two lines at any time?
The example with the sheet is very simple, but the graph can show a different picture because of holes in the history, as an example - cut the sheet into three parts and remove the middle part, connect the two remaining parts and you will see that the lines have become curved, but the distance between them is preserved. Accordingly, we can measure the distance at any point where the line has not yet been cut, and for that we need coordinates at two points without holes for each line, or with holes restored.
Anyway, made this option - you can set delta and you can find from price/time position, provided the lines are really parallel.
#property strict#property script_show_inputsinputint X_1=100; //X1 в барахinputdouble Y_1=10; //Y1 в Пунктах от цены открытия бараinputint X_2=10; //X2 в барахinputdouble Y_2=15; //Y2 в Пунктах от цены открытия бараinputdouble Point_delta=30; //Зададим дельту в пунктах//+------------------------------------------------------------------+//| |//+------------------------------------------------------------------+voidOnStart()
{
//--- удаление всех созданных объектов bool DelAllObjects=true;
if(DelAllObjects==true)
{
int obj_total=ObjectsTotal();
PrintFormat("Всего%d объектов",obj_total);
for(int i=obj_total-1;i>=0;i--)
{
string name=ObjectName(i);
PrintFormat("Объект%d:%s",i,name);
ObjectDelete(name);
}
}
/*
Start Stop
x Time 10 20
y Price 30 50
Линейная функция y=kx+b
Система уравнений
30y=10k+b
50y=20k+b
//Вычитаем
20y=10k+0
-10k=-20y
k=-20/-10
k=2
*/double k=(Y_2-Y_1)*(-1)/(X_2-X_1)*(-1);
double b=(X_1*k-Y_1)*(-1);
//Point_delta - можно задать/рассчитать, если в этом смысл, а если не известна, то ищем по координатам второй линии - Deltadouble Y_3=X_1*k+b+Point_delta;
double Y_4=X_2*k+b+Point_delta;
double k2=(Y_3-Y_4)*(-1)/(X_2-X_1)*(-1);
double b2=(X_1*k-Y_2)*(-1);
double Delta=(Y_3-Y_1);
ObjectCreate("Line1",OBJ_TRENDBYANGLE,0,Time[X_1],Open[X_1]+Y_1*Point(),Time[X_2],Open[X_2]+Y_2*Point());
ObjectSetInteger(0,"Line1",OBJPROP_STYLE,STYLE_SOLID);
ObjectSetInteger(0,"Line1",OBJPROP_COLOR,Red);
ObjectSetInteger(0,"Line1",OBJPROP_WIDTH,2);
ObjectSetInteger(0,"Line1",OBJPROP_RAY_RIGHT,false);//Луч продолжается вправо ObjectCreate("Line2",OBJ_TRENDBYANGLE,0,Time[X_1],Open[X_1]+Y_3*Point(),Time[X_2],Open[X_2]+Y_4*Point());
ObjectSetInteger(0,"Line2",OBJPROP_STYLE,STYLE_SOLID);
ObjectSetInteger(0,"Line2",OBJPROP_COLOR,Lime);
ObjectSetInteger(0,"Line2",OBJPROP_WIDTH,2);
ObjectSetInteger(0,"Line2",OBJPROP_RAY_RIGHT,false);//Луч продолжается вправо
Label("Delta",//Название0, //Окно30, //X10, //Y"k="+DoubleToString(k,_Digits)+" b="+DoubleToString(b,_Digits)+" Delta="+DoubleToString(Delta,_Digits),
10,//Размер шрифта
Yellow,//Цвет шрифтаCORNER_LEFT_UPPER,//Выбор угла: 3 - нижний правый, 1 - верхний правый. 2 - нижний левый, 4 - верхний левый ANCHOR_LEFT_UPPER
);
return;
}
//+------------------------------------------------------------------+//|Функция вывода информации на экран |//+------------------------------------------------------------------+void Label(string _name,int _window,int _x,int _y,string _text,int _font,color _color,int corner,int anchor)
{
ObjectDelete(0,_name);
ObjectCreate(0,_name,OBJ_LABEL,_window,0,0);
ObjectSetInteger(0,_name,OBJPROP_CORNER,corner);
ObjectSetInteger(0,_name,OBJPROP_XDISTANCE,_x);
ObjectSetInteger(0,_name,OBJPROP_YDISTANCE,_y);
ObjectSetText(_name,_text,_font,"Arial",_color);
ObjectSetInteger(0,_name,OBJPROP_ANCHOR,anchor);
}
In the code the x-axis sees bars, so if you need more accuracy for prediction you need to convert to seconds and check the holes.
You can only predict the price given the bars in the future - this has to be calculated separately, given the planned holes! The funny thing is that sometimes you have to create them opposite...
And if you plan to build a channel, it is better to build in an indicator using graphical buffers or to make a cyclic redrawing, so as not to have objects running across the screen.
Anyway, made this option - you can set delta and you can find from price/time position, provided the lines are really parallel.
In the code the x-axis sees bars, so if you need more accuracy for prediction you need to convert to seconds and check the holes.
You can only predict the price given the bars in the future - this has to be calculated separately, given the planned holes! The funny thing is that sometimes you have to create them opposite...
Do I understand correctly that the delta is the blue line ... Isn't the size of the red one here ?
Allow the use of cookies to log in to the MQL5.com website.
Please enable the necessary setting in your browser, otherwise you will not be able to log in.
You are signed in. Two-factor authentication has been disabled. Set it up again and scan a new QR code, or continue with two-factor authentication disabled.
That's right ... And I need the length of the Red Line... Imagine if these two parallel lines were vertical, what would the blue line show ?
It's really rubbish.
I showed the principle of automating this kind of calculation, the rest is up to you, for you are all right with your brains.
And here we hit something...
https://www.mql5.com/ru/forum/233174
That's right ... And I need the length of the Red Line... Imagine if these two parallel lines were vertical, what would the blue line show ?
It is possible that this red line will not be perpendicular due to the fact that it can be drawn only by bar price and time.
As an option, I see the following sequence: we determine the slope of the trend line or plot the trend line by an angle and obtain the perpendicular angle by which we calculate the distance to the second line.
But this is just a theory. It should be checked.
It is possible that this red line will not be perpendicular because it can only be drawn based on the bar price and time.
As an option, I see the following sequence: we determine the slope of the trend line or draw the trend line by the angle and obtain the perpendicular angle based on which we calculate the distance to the second line.
But that's just theory. It needs to be tested.
Bummer. It is time to apply Fourier transforms.
It really does suck.
I showed you the principle of automating this kind of calculation, the rest is up to you, for you are all right in the head.
Well, we've hit on something here, too.
https://www.mql5.com/ru/forum/233174
a little bit, not the same... but something similar is there )
What a puzzle...
a little, not the same ... but there's something similar.)
What a puzzle...
There's no puzzle.
Find the angle, find the cathetus using the formula.
Here's the subject:
https://www.mql5.com/ru/forum/163710All right ... And I need the length. the red line. Imagine if the two parallel lines were vertical, what would the blue line show ? (at different angles, will be different length)
If you draw two parallel lines 10 cm apart on a white sheet of paper(Fig.7), you can twist the sheet at any angle and it will still be the same 10 cm(Fig.6).
I'm confused about your goals...
Tell me what you have initially, please. It's not clear to me how you can ask about distance if we don't have parallel lines, and if we do, how is the second line constructed without that data?
Above you cited the code of the two lines, but, allow me, there is no parallelism there at all.
Or is the task just to build parallel lines? Or to check if the lines are parallel? Or just find the difference between any two lines at any time?
The example with the sheet is very simple, but the graph can show a different picture because of holes in the history, as an example - cut the sheet into three parts and remove the middle part, connect the two remaining parts and you will see that the lines have become curved, but the distance between them is preserved. Accordingly, we can measure the distance at any point where the line has not yet been cut, and for that we need coordinates at two points without holes for each line, or with holes restored.In order to solve the problem you have to:
1. draw a perpendicular to the given parallel lines
2. determine the points of intersection of the perpendicular with the given lines
3. calculate the distance between the intersection points
Clearly in pictures:
(different lines and distances between them)
.............................................................................
.............................................................................
.............................................................................
.............................................................................
Anyway, made this option - you can set delta and you can find from price/time position, provided the lines are really parallel.
In the code the x-axis sees bars, so if you need more accuracy for prediction you need to convert to seconds and check the holes.
You can only predict the price given the bars in the future - this has to be calculated separately, given the planned holes! The funny thing is that sometimes you have to create them opposite...
Anyway, made this option - you can set delta and you can find from price/time position, provided the lines are really parallel.
In the code the x-axis sees bars, so if you need more accuracy for prediction you need to convert to seconds and check the holes.
You can only predict the price given the bars in the future - this has to be calculated separately, given the planned holes! The funny thing is that sometimes you have to create them opposite...
Do I understand correctly that the delta is the blue line ... Isn't the size of the red one here ?
https://c.mql5.com/3/181/lineee__2.jpg