Circular Candlestick Chart
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © alexgrover

//@version=5
indicator("Circular Candlestick Chart",max_lines_count=500)
length    = input(25)
width     = input(200)
spacing   = input(7)
precision = input(10)
//----
upper = ta.highest(length)
lower = ta.lowest(length)
q75   = ta.percentile_linear_interpolation(close,length,75)
q25   = ta.percentile_linear_interpolation(close,length,25)
//----
n = bar_index
if barstate.islast
    for element in line.all
        l = element
        line.delete(l[0])
    
    for i = 0 to length-1
        float prev_y = na
        int prev_x = na
        
        float prev_cy = na
        int prev_cx = na
        
        o = (open[i]  - lower)/(upper - lower)*360
        h = (high[i]  - lower)/(upper - lower)*360
        l = (low[i]   - lower)/(upper - lower)*360
        c = (close[i] - lower)/(upper - lower)*360
        
        for j = l to h by precision
            x = (width-i*spacing)*math.sin(math.toradians(j))
            y = (width-i*spacing)*math.cos(math.toradians(j))
            
            line.new(prev_x,prev_y,n+math.round(x),y,color=color.gray)
            
            prev_y := y
            prev_x := n+math.round(x)
        
        for k = o to c by precision
            x = (width-i*spacing)*math.sin(math.toradians(k))
            y = (width-i*spacing)*math.cos(math.toradians(k))
            
            css = close[i] > open[i] ? #26a69a : #ef5350
            
            line.new(prev_cx,prev_cy,n+math.round(x),y,color=css,width=2)
            
            prev_cy := y
            prev_cx := n+math.round(x)
    
    q75_deg = (q75 - lower)/(upper - lower)*360
    q25_deg = (q25 - lower)/(upper - lower)*360
    
    line.new(n,0,n+math.round(width*math.sin(math.toradians(q75_deg))),width*math.cos(math.toradians(q75_deg))
      ,color=#2157f3,width=1,style=line.style_dotted)
    line.new(n,0,n+math.round(width*math.sin(math.toradians(q25_deg))),width*math.cos(math.toradians(q25_deg))
      ,color=#ff5d00,width=1,style=line.style_dotted)