Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to get angle by degree from line.new in pinescript?

I’ve create a line by line.new() in pinescript.
now I want to know how much is my line angle by degree?
how can I get the angle of my line1 ?

//@version=5
indicator("line.new")
var line1 = line.new(0, low, bar_index, high, extend=extend.right)

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

We can calculate the angle of a line using line.new() in PineScript:

//@version=5
indicator("Line Angle", overlay=true)

// Define the line using line.new
var line1 = line.new(0, low, bar_index, high, extend=extend.right, color=color.blue, width=2)

// Calculate the angle in radians
angleRad = atan(line.get_price(high, bar_index) - line.get_price(low, bar_index), line.get_x2(line1) - line.get_x1(line1))

// Convert angle to degrees
angleDeg = angleRad * (180 / math.pi)

// Print the angle on chart
plotchar(0, "", "Angle: " + tostring(angleDeg, "#.##°"), location=location.top)

We can use the atan() function to calculate the angle in radians, and then convert it to degrees by multiplying it with (180 / math.pi). Finally, we plot the angle on the chart using plotchar().

Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading