Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //@version=5
- indicator("Unit Circle and Quadrants", overlay=true)
- // Define constants
- pi = 3.14159
- // Calculate number of points on the unit circle
- numPoints = 360
- // Calculate circle radius
- circleRadius = close - low
- // Calculate x and y coordinates of the unit circle
- circle_x = array.new_float(numPoints, na)
- circle_y = array.new_float(numPoints, na)
- for i = 0 to numPoints - 1
- angle = 2 * pi * i / numPoints
- if bar_index >= i
- array.set(circle_x, i, close + circleRadius * math.cos(angle))
- array.set(circle_y, i, close + circleRadius * math.sin(angle))
- // Plotting the unit circle
- index = bar_index >= numPoints - 1 ? numPoints - 1 : bar_index
- plot(array.get(circle_x, index), "Unit Circle X", color=color.blue, linewidth=2)
- plot(array.get(circle_y, index), "Unit Circle Y", color=color.red, linewidth=2)
- // Plotting the quadrants
- plotshape(close > close[1] and high > high[1], title="Quadrant 1", style=shape.labelup, location=location.belowbar, color=color.green, text="Q1")
- plotshape(close > close[1] and high < high[1], title="Quadrant 2", style=shape.labelup, location=location.belowbar, color=color.red, text="Q2")
- plotshape(close < close[1] and high < high[1], title="Quadrant 3", style=shape.labelup, location=location.belowbar, color=color.blue, text="Q3")
- plotshape(close < close[1] and high > high[1], title="Quadrant 4", style=shape.labelup, location=location.belowbar, color=color.orange, text="Q4")
- // Plotting the circle made by lines
- bar_limit = bar_index + 500
- line.new(bar_index, close + circleRadius, bar_limit, close + circleRadius, color=color.gray, width=2)
- line.new(bar_index, close - circleRadius, bar_limit, close - circleRadius, color=color.gray, width=2)
- line.new(bar_index, close + circleRadius, bar_index, close - circleRadius, color=color.gray, width=2)
- line.new(bar_limit, close + circleRadius, bar_limit, close - circleRadius, color=color.gray, width=2)
Advertisement
Add Comment
Please, Sign In to add comment