xmd79

45 Degree Angle Line

May 29th, 2023
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.87 KB | None | 0 0
  1. //@version=5
  2. indicator('45 Degree Angle Line', overlay=true)
  3.  
  4. // Define the start point of the line
  5. start_bar = 0
  6. start_price = open
  7.  
  8. // Define the end point of the line
  9. end_bar = bar_index
  10. end_price = open
  11.  
  12. // Calculate the distance between the start and end points
  13. distance = math.sqrt(math.pow(end_bar - start_bar, 2) + math.pow(end_price - start_price, 2))
  14.  
  15. // Calculate the slope of the line
  16. slope = (end_price - start_price) / (end_bar - start_bar)
  17.  
  18. // Calculate the angle of the line in degrees
  19. angle = math.atan(slope) * (180 / math.acos(-1))
  20.  
  21. // Draw the line
  22. plot(start_price + slope * (bar_index - start_bar), color=color.new(color.blue, 0), linewidth=2)
  23.  
  24. // Display the angle of the line on the chart
  25. label.new(bar_index, high, '45 Degree Angle: ' + str.tostring(angle) + ' degrees', color=color.white, textcolor=color.black, style=label.style_label_left)
  26.  
  27.  
Advertisement
Add Comment
Please, Sign In to add comment