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

 
Олег avtomat:

any way you like.

As you can see, there's nothing complicated about it. You just have to think about it a bit.

With such a detailed answer, I think TC will be able to write the code by himself.

Many people here have already forgotten school problems because they couldn't grasp their meaning at school.

 

The output is:

 // ЗАДАЕМ ДВЕ ТОЧКИ ПРИВЯЗКИ ДЛЯ ГЛАВНОЙ ЛИНИИ: ТОЧКА1(ВРЕМЯ,ЦЕНА) и ТОЧКА2(ВРЕМЯ,ЦЕНА)
   // ЭТА ЛИНИИ ГЛАВНАЯ
   datetime Line1_Врем0=Time[0], Line1_Врем1=Time[10];
   double Line1_Цена0=High[10], Line1_Цена1=Low[10];

   ObjectCreate("Line1",OBJ_TRENDBYANGLE,0,Line1_Врем0,Line1_Цена0,Line1_Врем1,Line1_Цена1);
   ObjectSetInteger(0,"Line1",OBJPROP_STYLE,STYLE_SOLID);
   ObjectSetInteger(0,"Line1",OBJPROP_COLOR,Red);
   ObjectSetInteger(0,"Line1",OBJPROP_WIDTH,2);

   // СТРОИМ ПАРАЛЛЕЛЬНУЮ ЛИНИЮ ТОЛЬКО ПО ОДНОЙ ТОЧКЕ-ПРИВЯЗКЕ
   ObjectCreate("Line2",OBJ_TRENDBYANGLE,0,Time[15],Low[15],0,0);
   ObjectSetInteger(0,"Line2",OBJPROP_STYLE,STYLE_SOLID);
   ObjectSetInteger(0,"Line2",OBJPROP_COLOR,Lime);
   ObjectSetInteger(0,"Line2",OBJPROP_WIDTH,2);

  // ПРИСВАИВАЕМ ЛИНИИ Line2 ТАКОЙ ЖЕ САМЫЙ УГОЛ КАК В ЛИНИИ Line1 ЧТО БЫ ЛИНИИ БЫЛИ ПАРАЛЛЕЛЬНЫЕ 
   ObjectSetDouble(0,"Line2",OBJPROP_ANGLE,ObjectGetDouble(0,"Line1",OBJPROP_ANGLE)); 

   // РИСУЕМ ПЕРПЕНДИКУЛЯРНУЮ ЛИНИЮ К Line1 и Line2
   ObjectCreate("Value",OBJ_TRENDBYANGLE,0,Time[0],Low[15],0,0);
   ObjectSetInteger(0,"Value",OBJPROP_RAY,false);
   ObjectSetInteger(0,"Value",OBJPROP_COLOR,Gold);
   ObjectSetInteger(0,"Value",OBJPROP_WIDTH,3);
   ObjectSetDouble(0,"Value",OBJPROP_ANGLE,90+ObjectGetDouble(0,"Line1",OBJPROP_ANGLE));

   // ЗАДАЧА: ПОЛУЧИТЬ РАЗМЕР ЖЕЛТОЙ ЛИНИИ МЕЖДУ Line1 и Line2. ОПТИМАЛЬНЫМ И УНИВЕРСАЛЬНЫМ ПАРАМЕТРОМ РАЗМЕРА НАВЕРНОЕ БУДУТ - ПИКСЕЛИ.

Next, through ObjectGetValueByShift("Line1",a++) and ObjectGetValueByShift("Value",a++) and ObjectGetValueByShift("Line2",a++) search for the intersection

Am I reading it right?
 
Олег avtomat:

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)



.............................................................................


.............................................................................


.............................................................................


.............................................................................


Not convincing.

 
Алексей Тарабанов:

Not convincing.

Open your textbooks and be convinced

 
The theory seems to be clear and there seems to be nothing complicated but... The only thing is how to do it in practice and how it will work...
 
Itum:

Yes

Unfortunately I am not a mathematician (
How about Googling it?


blue angle = 90 - line angle

convert angle to radians

red opposing cathetus = green hypotenuse * sine (blue angle)

We have already found the hypotenuse in this thread by crossing both lines vertically

If the angle of the line is 90 or 0, then consider the distance differently, that is, by crossing parallel lines horizontally or vertically.

 
Renat Akhtyamov:
How about Googling it?


blue angle = 90 - line angle

Convert angle to radians

red opposing cathetus = green hypotenuse * sine (blue angle)

We have already found the hypotenuse in this thread by crossing both lines vertically

If the angle of the line is 90 or 0, then count the distance in another way, that is, by crossing parallel lines horizontally or vertically.

Hmmm...

For some reason it doesn't work

   datetime t1 = (datetime)ObjectGetInteger(0, "Line1", OBJPROP_TIME, 0);
   datetime t2 = (datetime)ObjectGetInteger(0, "Line2", OBJPROP_TIME, 0);
   double p1 = 0;
   double p2 = 0;
   
   if(t1 > t2)
   {
      p1 = ObjectGetValueByTime(0, "Line1", t2);
      p2 = ObjectGetDouble(0, "Line2", OBJPROP_PRICE, 0);
   }
   if(t1 < t2)
   {
      p1 = ObjectGetDouble(0, "Line1", OBJPROP_PRICE, 0);
      p2 = ObjectGetValueByTime(0, "Line2", t1);;
   }
   if(t1 == t2)
   {
      p1 = ObjectGetDouble(0, "Line1", OBJPROP_PRICE, 0);
      p2 = ObjectGetDouble(0, "Line2", OBJPROP_PRICE, 0);
   }
   
   double rez = NormalizeDouble(MathAbs(p1 - p2) / _Point, 0) * MathSin(ObjectGetDouble(0,"Line1",OBJPROP_ANGLE));
   Comment("Разница: ", rez /* */);
 
It seems simple ... But it doesn't get the result you want
 
Itum:
It seems simple ... but it doesn't get the result you want


Yes, everything is simple, except that your task is not solvable.... ))

First of all, forget about theObjectGetDouble(0,"Line1",OBJPROP_ANGLE) function. It will always return 0, since it cannot be applied to a trend line. It is needed, in particular, for the "angle" trend line, which does not depend on the chart scale BUT it also does not depend on bar prices. That is, its angle will not change when changing the scale, but the line itself will move away from bars...


But that's not the biggest problem... The whole point is that you want to find the size of the perpendicular between 2 parallel trend lines, try to draw such a perpendicular on the chart... And then change the scale of the graph... the perpendicular becomes non-perpendicular... )))) So the problem is exactly what you consider a perpendicular (dependence on scale and how YOU see it) and a mathematical perpendicular.

The perpendicular on a price scaled chart is an optical illusion.

Using geometry this problem in its pure form is solved in one go... BUT the mathematical result of the calculation will never coincide with the one seen on the chart... And you need exactly the match, so the problem is unsolvable. Just simplify your requirements, do not look for a perpendicular, but just the distance between 2 lines at the same time point...

 

I have no words.

I know all the letters, but I can't read the word

Come on, come on, don't give up, study MQL, it's just a matter of time