xmd79

Circle

May 26th, 2023 (edited)
334
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.18 KB | None | 0 0
  1. //@version=5
  2. indicator("Circle", overlay=true)
  3.  
  4. // Circle radius
  5. radius = input(50, title="Radius")
  6.  
  7. // Circle color
  8. color_circle = input(color.white, title="Circle Color")
  9.  
  10. // Dot color
  11. color_dot = input(color.yellow, title="Dot Color")
  12.  
  13. // Line color
  14. color_line = input(color.blue , title="Line Color")
  15.  
  16. // Calculate circle points
  17. num_points = 100
  18. circle_x = array.new_float(num_points)
  19. circle_y = array.new_float(num_points)
  20.  
  21. for i = 0 to num_points-1 do
  22. angle = i * 2 * math.pi / num_points
  23. if i % 2 == 0
  24. circle_x[i] = close[0] + radius * math.cos(angle)
  25. circle_y[i] = close[0] + radius * math.sin(angle)
  26. else
  27. circle_x[i] = open[0] + radius * math.cos(angle)
  28. circle_y[i] = open[0] + radius * math.sin(angle)
  29.  
  30. // Draw the circle
  31. for i = 0 to num_points-1
  32. x1 = array.get(circle_x, i)
  33. y1 = array.get(circle_y, i)
  34. x2 = array.get(circle_x, (i+1)%num_points)
  35. y2 = array.get(circle_y, (i+1)%num_points)
  36.  
  37. if i % 2 == 0
  38. color = color_line
  39. else
  40. color = color_circle
  41.  
  42. line.new(x1 = x1,
  43. y1 = y1,
  44. x2 = x2,
  45. y2 = y2,
  46. color = color)
  47.  
Advertisement
Add Comment
Please, Sign In to add comment