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

 
Itum:

Can you tell me how to calculate the distance between two parallel lines including the scale of the graph (so that the scale is not affected)?

Here's an example:

The red line is the distance between two parallel lines - how can you calculate ?

You have a red perpendicular line that will change in multiples of a simple vertical line connecting the two lines.

Don't sweat it, your answer is:

The price difference at the same time at the two points on the lines.

//PS: Swam already...

However, you can check my assertion.

There is also an answer, but it's in geometry on "Rectangular triangle. Length of the cathetus."

 
Itum:

Can you tell me how to calculate the distance between two parallel lines including the scale of the graph (so that the scale is not affected)?

Here's an example:

The red line is the distance between two parallel lines - how can you calculate ?

Spring.

Calculate something including the scale, but in a way that the scale does not affect it.

Maybe parallelism shouldn't affect it?

 
Itum:

Can you tell me how to calculate the distance between two parallel lines including the scale of the graph (so that the scale is not affected)?

Here is an example:

The red line is the distance between two parallel lines - how can you calculate ?

Put the MAH on the chart, set the levels and you don't need to calculate anything.

 
Itum:

How can you calculate the distance between two parallel lines including the scale of the graph (so that the scale is not affected)?

It depends on what you want to get? If you want the distance in pixels, you build a triangle and use the Pythagoras theorem to calculate the side. But this value will be influenced by the scale. If you want the price movement, project on the OX/OY axis and it will be the price movement. If you want the distance in units, multiply the projections. So on. The task is in fact elementary.

 
   ObjectCreate("Line1",OBJ_TREND,0,Time[0],High[10],Time[10],Low[10]);
   ObjectSetInteger(0,"Line1",OBJPROP_STYLE,STYLE_SOLID);
   ObjectSetInteger(0,"Line1",OBJPROP_COLOR,Red);
   ObjectSetInteger(0,"Line1",OBJPROP_WIDTH,2);
   
   ObjectCreate("Line2",OBJ_TREND,0,Time[10],High[10],Time[20],Low[10]);
   ObjectSetInteger(0,"Line2",OBJPROP_STYLE,STYLE_SOLID);
   ObjectSetInteger(0,"Line2",OBJPROP_COLOR,Lime);
   ObjectSetInteger(0,"Line2",OBJPROP_WIDTH,2);
   
   Comment("Разница: ");
 
Itum:

According to the formula above, the shortest distance R between these two parallel lines:

   double V = (High[10]-Low[10])/(Time[10]-Time[20]);
   double R = (High[10]-Low[10])/sqrt(1+V*V) ; 

Where V is the rate of change in price with unit point/second. Also V = tangent of the slope of the line in a system with a scale of 1 point = 1 second.

Just need to stipulate that this formula works if there are no time holes between bars. For example weekends. Otherwise, the result will not be correct. In this case, it is necessary to use thePeriodSeconds() function and calculate the time delta through the number of bars multiplied by the number of seconds in a bar.

I.e. in this case it will be:

   double V = (High[10]-Low[10])/(10*PeriodSeconds());
   double R = (High[10]-Low[10])/sqrt(1+V*V) ;


Also, you should understand that @Renat Akhtyamov was essentially rightin this post. Becauseif the time interval is large enough, the denominator value (sqrt(1+V*V))will always be slightly greater than 1.

And then this formula can be simplified:

double R = High[10]-Low[10] ;




 
Itum:
   ObjectCreate("Line1",OBJ_TREND,0,Time[0],High[10],Time[10],Low[10]);
   ObjectSetInteger(0,"Line1",OBJPROP_STYLE,STYLE_SOLID);
   ObjectSetInteger(0,"Line1",OBJPROP_COLOR,Red);
   ObjectSetInteger(0,"Line1",OBJPROP_WIDTH,2);
   
   ObjectCreate("Line2",OBJ_TREND,0,Time[10],High[10],Time[20],Low[10]);
   ObjectSetInteger(0,"Line2",OBJPROP_STYLE,STYLE_SOLID);
   ObjectSetInteger(0,"Line2",OBJPROP_COLOR,Lime);
   ObjectSetInteger(0,"Line2",OBJPROP_WIDTH,2); 
   
   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);
   }
   
   Comment("Разница: " + DoubleToString(MathAbs(p1 - p2) / _Point, 0));
 
Sergey Kolemanov:

You've got it all wrong....
t1 in this case always = t2

Everything you wrote,

can be written in one line:

Comment("Разница: " + DoubleToString((High[10]-Low[10]) / _Point, 0));

the result would be the same.

 
Nikolai Semko:

Well, you've got it all wrong....
t1 in this case always = t2

Everything you wrote,

can be written in one line:

the result would be the same.

Yes, in his example t1 = t2 , and how they are actually built only the topicstarter knows. And if they are built as t1 > t2 , then recalculated and t1 < t2, then how to count?

 
Nikolai Semko:

can be written in one line:

Comment("Разница: " + DoubleToString((High[10]-Low[10]) / _Point, 0));


You count the distance between High and Low , and he has lines