Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator('45 Degree Angle Line', overlay=true)
- // Define the start point of the line
- start_bar = 0
- start_price = open
- // Define the end point of the line
- end_bar = bar_index
- end_price = open
- // Calculate the distance between the start and end points
- distance = math.sqrt(math.pow(end_bar - start_bar, 2) + math.pow(end_price - start_price, 2))
- // Calculate the slope of the line
- slope = (end_price - start_price) / (end_bar - start_bar)
- // Calculate the angle of the line in degrees
- angle = math.atan(slope) * (180 / math.acos(-1))
- // Draw the line
- plot(start_price + slope * (bar_index - start_bar), color=color.new(color.blue, 0), linewidth=2)
- // Display the angle of the line on the chart
- label.new(bar_index, high, '45 Degree Angle: ' + str.tostring(angle) + ' degrees', color=color.white, textcolor=color.black, style=label.style_label_left)
Advertisement
Add Comment
Please, Sign In to add comment