Calculate the distance between two parallel lines including ! - page 4

 
Itum:


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

Значения трендовых линий при оптимизации ?
Значения трендовых линий при оптимизации ?
  • 2018.03.25
  • www.mql5.com
Известна первая точка по фракталам Известна вторая точка по вершинам high-low На графике рисуются трендовые линии по точкам Как получить цены тренд...
 
Itum:


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.

 
Alexey Viktorov:

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.

 
Renat Akhtyamov:

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...

 
Itum:

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/163710
Расчёт угла наклона трендовой линии.
Расчёт угла наклона трендовой линии.
  • 2016.12.17
  • www.mql5.com
Добрый день. Нужно расcчитать угол наклона трендовой линии на графике в градусах программно (MQL5...
 
Itum:

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.
 

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.

#property strict
#property script_show_inputs



input int X_1=100;   //X1 в барах
input double Y_1=10;  //Y1 в Пунктах от цены открытия бара
input int X_2=10;   //X2 в барах
input double Y_2=15;  //Y2 в Пунктах от цены открытия бара
input double Point_delta=30; //Зададим дельту в пунктах

//+------------------------------------------------------------------+
//|                                                                  |
//+------------------------------------------------------------------+
void OnStart()

  {


//--- удаление всех созданных объектов 
   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 - можно задать/рассчитать, если в этом смысл, а если не известна, то ищем по координатам второй линии - Delta
double 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,     //X
            10,      //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.
 
Aleksey Vyazmikin:

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

Reason: