How do you calculate the length of a line from the coordinates? - page 9

 
AlexSTAL:

How do you get the zigzag line length (wavelength in essence) in any units, knowing the coordinates of the two points?

Needed to compare the wavelengths of the two as a percentage

It's quite simple to solve - you need to use GDI functions

Here is an even more complicated example: calculation of the MA slope. Pixel distances are used


#import "user32.dll"
        int GetWindowDC(int dc);
        bool GetWindowRect(int h, int& pos[4]);
        int ReleaseDC(int h, int dc);
#import

//---------------------------------------------------------------   CheckAngle
int CheckAngle(string smb, int tf, int iB)
{
  double p1, p2, ang;
  p1=iMA(smb, tf, dPeriod, 0, dMode, dPrice, iB+1);
  p2=iMA(smb, tf, dPeriod, 0, dMode, dPrice, iB);

  int hWnd=WindowHandle(Symbol(), Period()); int hDC=GetWindowDC(hWnd); // получаем хендл окна
  int rect[4]; GetWindowRect(hWnd, rect); ReleaseDC(hWnd, hDC);   // берем его DC
  double wW=rect[2]-rect[0]; double wH=rect[3]-rect[1];           // получаем высоту и ширину в пикселях
  double H=(WindowPriceMax()-WindowPriceMin()); double W=WindowBarsPerChart(); // переводим на график
  double x=wW/W; double y=((p2-p1))*wH/H;                         // определяем катеты
  ang=MathArctan(y/x)*180/3.1415926535; if (ang>180) ang=ang-360; // равняем относительно оси Х
}


In later versions, I used normalizing coefficients to keep the angle value unchanged when zooming in and out of the chart. But now I cannot find them.

 

That's what I was talking about, but I forgot all about the API (I needed it too rarely):

AlexSTAL:

If you could get the size of the chart in pixels - there would be no problem. There are operators that get the price minimum and maximum, there are operators that get the number of bars on the screen. Translating them into conditional units is not a problem


Once again many thanks to Alexey, a true professional!

 

I am of course late to the discussion.

Question for the Mathematician:

In what units is the hypotenuse of such a triangle obtained if it is parallel to the parrot axis? In what units were the lengths of the cathetuses?

And on the merits of the question, I think it is necessary to count the length not in bars, but in time. The minimum timeframe is M1 - it means that time is measured discretely with 1 minute increments. This is the number of minutes and should be taken as the length of one of the cathetuses. This approach guarantees the same length of the cathetus at different timeframes and does not depend on the scaling in the terminal.

 
api:

I am of course late to the discussion.

Question for the Mathematician:

In what units is the hypotenuse of such a triangle obtained if it is parallel to the parrot axis? In what units were the lengths of the cathetuses?

And on the merits of the question, I think it is necessary to count the length not in bars, but in time. The minimum timeframe is M1 - so the time is measured discretely with 1 minute increments. This is the number of minutes and should be taken as the length of one of the cathetuses. This approach guarantees the same length of the cathetus at different timeframes and does not depend on the scaling in the terminal.

Not a Mathematician, but I'll ask, in what units do you measure the lengths of the cathetuses?
 
sanyooooook:
Not a Mathematician, but I'll ask, in what units do you measure the lengths of the cathetuses?

The same as the length of the hypotenuse!
 
api:

The same as the length of the hypotenuse!
i.e. the square root of: the square of the parrots plus the square of the parrots, and what does that have to do with apples?
 
sanyooooook:
i.e. the square root of: the square of parrots plus the square of parrots, and what does that have to do with apples?

The picture doesn't make any sense at all.
 
sergeev:

In later versions, I used to add normalisation coefficients, so that when you change the scale of the graph, the angle values don't change. But I can't find them now.

Why all this dancing around (with pixels) then?

Add one coefficient to bring the second hypotenuse to about the same order as the first and... Pythagoras theorem. It is clear that the result will be measured neither in seconds, nor in bars or in pixels, it will be just some number, but it will allow to compare separate segments among themselves and with the given parameters (and the result will be concrete and onomatological, with a constant coefficient value), which is enough for the solution of the task. There are no other options.

 
sanyooooook:
i.e. the square root of: the square of parrots plus the square of parrots, and what does that have to do with apples?

Not really.

It is an abstract space and it has nothing to do with real space and is not a projection of it. To prove this, imagine any object in this space, such as a parrot positioned so that its growth line is parallel to the parrot axis. Looking at it from the side of the parrot's axis you see a whole parrot, and looking at it from the side of the apple axis you see some part of an apple or several apples - it does not matter. On this side you do not see the parrot. Now turn the parrot around so that its growth line is parallel to the axis of the apples. In this case, observing the parrot from the axis of the apples, you will see.... That's right - a few apples and no parrots. And on the axis side of the parrots you will observe... well, let's say - a "parrot wing", to use the language of a famous cartoon character.

This is such a tricky space, which nevertheless obeys the law of Pythagoras.

But in our case no one rotates the graphs and the price remains the price and time remains the time.

 
Mischek:

The picture makes no sense at all
)