Calculate length of an hypotenuse line (of right angle triangle)

Hi,

I want to be able to calculate the length of a hypotenuse of a right angled triangle and its angle to the x-axis (horizontal), but don’t want to have to draw a triangle to do this.

I want to be able work it like the Time Price Measure, which already calculates the price (p) and time (t) component of a range (r). In the same way, I want to select a starting point e.g. a low, and drag the cursor to another point e.g. a high, and automatically have the hypotenuse length calculated.

Basically, I would be applying Pythagoras’ theorem i.e. Hypotenuse = Square Root ( price^2+time^2).

As indicated, I would also like to be able to include an angle of the line to the horizontal axis, like you do for a TL e.g. 45% angle etc.

So, I would like to have these calculations included in the TPM or create a tool for myself. Is this possible and how do I go about it? I know nothing about code or scripting.

Chris

Hi Chris,

The Time Price Measure tool has it’s own expression scripts (like Gann Square Markers and Gann Square Range Markers).

Just go to “Show Labels” and add a new item. Call it Hypotenuse and set the script to SQRT(SQR(P2-P1) + SQR(I2-I1))

I’m using “I” for index so I am measuring time in terms of bars. You could use D2-D1 instead for Calendar days.

More information on this at https://help.optuma.com/kb/faq.php?id=388

Also blog post on this at https://www.optuma.com/time-price-measures/

Hope that helps

Mathew

As well as adding the formula to the TPM tool you could also use the Time Price Label tool and enable the Time Price Vector label:

Capture

Thankyou to you both. Those are excellent suggestions.

Chris