xmd79

Unit Circle and Quadrants with hi lo range for circle area

May 23rd, 2023
188
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.03 KB | None | 0 0
  1. //@version=5
  2. indicator("Unit Circle and Quadrants", overlay=true)
  3.  
  4. // Define constants
  5. pi = 3.14159
  6.  
  7. // Calculate number of points on the unit circle
  8. numPoints = 360
  9.  
  10. // Calculate circle radius
  11. circleRadius = high[1] - low[1]
  12.  
  13. // Calculate x and y coordinates of the unit circle
  14. circle_x = array.new_float(numPoints, na)
  15. circle_y = array.new_float(numPoints, na)
  16.  
  17. for i = 0 to numPoints - 1
  18. angle = 2 * pi * i / numPoints
  19. if bar_index >= i
  20. array.set(circle_x, i, close + circleRadius * math.cos(angle))
  21. array.set(circle_y, i, close + circleRadius * math.sin(angle))
  22.  
  23. // Plotting the unit circle
  24. index = bar_index >= numPoints - 1 ? numPoints - 1 : bar_index
  25. plot(array.get(circle_x, index), "Unit Circle X", color=color.blue, linewidth=2)
  26. plot(array.get(circle_y, index), "Unit Circle Y", color=color.red, linewidth=2)
  27.  
  28. // Plotting the quadrants
  29. plotshape(close > close[1] and high > high[1], title="Quadrant 1", style=shape.labelup, location=location.belowbar, color=color.green, text="Q1")
  30. plotshape(close > close[1] and high < high[1], title="Quadrant 2", style=shape.labelup, location=location.belowbar, color=color.red, text="Q2")
  31. plotshape(close < close[1] and high < high[1], title="Quadrant 3", style=shape.labelup, location=location.belowbar, color=color.blue, text="Q3")
  32. plotshape(close < close[1] and high > high[1], title="Quadrant 4", style=shape.labelup, location=location.belowbar, color=color.orange, text="Q4")
  33.  
  34. // Plotting the circle made by lines
  35. bar_limit = bar_index + 500
  36. line.new(bar_index, close + circleRadius, bar_index + (bar_limit >= bar_index ? 500 : bar_limit - bar_index), close + circleRadius, color=color.gray, width=2)
  37. line.new(bar_index, close - circleRadius, bar_index + (bar_limit >= bar_index ? 500 : bar_limit - bar_index), close - circleRadius, color=color.gray, width=2)
  38. line.new(bar_index, close + circleRadius, bar_index, close - circleRadius, color=color.gray, width=2)
  39. line.new(bar_limit, close + circleRadius, bar_limit, close - circleRadius, color=color.gray, width=2)
  40.  
Advertisement
Add Comment
Please, Sign In to add comment