Real-time price distribution in candles
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Dicargo_Beam

//@version=5
indicator("Real-time price distribution in candles", overlay=true)

int sec = math.floor((timenow-time)/1000)



varip p = array.new_float(31)

varip term = math.floor((time_close-time)/1000 /30)

if barstate.isnew
    for i = 0 to 30
        array.set(p,i,na)
        
array.set(p,0,open)

for i = 1 to 30
    if sec < i * term + 1 and sec > i * term - 1
        array.set(p,i,close)

col_op  =   input.color(color.new(color.yellow,50),"Open color")
col_cl  =   input.color(color.new(color.aqua,50),"Close color")
col     =   input.color(color.new(color.gray,50),"Real-time color")

width = input.int(2)

plot(array.get(p,0),    color=col_op,   style=plot.style_circles, linewidth = width)    
plot(array.get(p,1),    color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,2),    color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,3),    color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,4),    color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,5),    color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,6),    color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,7),    color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,8),    color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,9),    color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,10),   color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,11),   color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,12),   color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,13),   color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,14),   color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,15),   color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,16),   color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,17),   color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,18),   color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,19),   color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,20),   color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,21),   color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,22),   color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,23),   color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,24),   color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,25),   color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,26),   color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,27),   color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,28),   color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,29),   color=col,      style=plot.style_circles, linewidth = width)
plot(array.get(p,30),   color=col_cl,   style=plot.style_circles, linewidth = width)
