St_cumulative
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Alferow

//@version=4
study("St_cumulative", overlay=false)



p = input(30, title = 'period')

max = highest(p)
min = lowest(p)
med = (max + min)/2


graph = if close > open
	high
else
	low

delta = graph - med

sum = delta
for i = 1 to p
    sum := sum + delta[i]
    
   
col_grow_above = #26A69A
col_grow_below = #FFCDD2
col_fall_above = #B2DFDB
col_fall_below = #EF5350


plot(sum, title="Histogram", style=plot.style_columns, color=(sum>=0 ? (sum[1] < sum ? col_grow_above : col_fall_above) : (sum[1] < sum ? col_grow_below : col_fall_below)))    

