Volume Candles Standardized (VCS)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © peacefulLizard50262

//@version=5
indicator("VCS")

OHLC(src, int len = 4) =>
    Open  = ta.sma(src[1], len)
    High  = ta.highest(src, 1)
    Low   = ta.lowest(src, 1)
    Close = ta.wma(src, len)
    [Open, High, Low, Close]

select = input.string("Cumulative Volume", "Style", ["OBV","Cumulative Volume"])
candle = input.int(4, "Candle Transform", 1, tooltip = "1 is regular candles and 4 is ashi candles. That being said you can smooth it untill the cows come home.")
red    = input.color(color.new(#ef5350, 0), "", inline = "col")
green  = input.color(color.new(#26a69a, 0), "", inline = "col")
sel    = input.bool(true, "Candle Colour", "Chance how the candles are colored. If this is enabled it will color the candles bassed on the transformed open/close. Otherwise this indicator will use source/source[1]")
ma     = input.bool(false, "Enable MA")
len    = input.int(28, "MA Length")
st     = input.bool(true, "Standardization")
back   = input.int(12, "Standardization Length", 1)

perc   = input.bool(true, "Percent Rank Enable")
per_75 = input.int(75 , "Percentile Cloud Top")
per_25 = input.int(25 , "Percentile Cloud Bottom")
rank   = input.int(48, "Percent Rank Look Back")


cum = select == "OBV" ? ta.cum(math.sign(ta.change(close)) * volume) : ta.cum(open > close ? -float(volume) : float(volume))
src = st ? (cum - ta.sma(cum, back)) / ta.stdev(cum, back) : cum
osc = src

[Open, High, Low, Close] = OHLC(src, candle)

ma1 = ma ? ta.ema(Close, len) : na
ma2 = perc ? ta.percentile_nearest_rank(src, rank, 100) : na
ma3 = perc ? ta.percentile_nearest_rank(src, rank, per_75) : na
ma4 = perc ? ta.percentile_nearest_rank(src, rank, per_25) : na
ma5 = perc ? ta.percentile_nearest_rank(src, rank, 0) : na
ma6 = ma ? ta.ema(Close, 10*len) : na

plot(ma1, "Fast MA", color = color.new(color.blue, 30))
plot(ma6, "Slow MA", color = color.new(color.orange, 30))
m1 = plot(ma2, "100", color = color.new(color.orange, 100))
m2 = plot(ma3, "75", color = color.new(color.orange, 100))
m3 = plot(ma4, "25", color = color.new(color.orange, 100))
m4 = plot(ma5, "0", color = color.new(color.orange, 100))

fill(m1, m2, color = color.new(color.green, 80))
fill(m2, m4, color = color.new(color.gray, 90))
fill(m3, m4, color = color.new(color.red, 80))

colour = sel ? Open < Close ? green : red : src > src[1] ? green : red
plotcandle(Open, High, Low, Close, "RSI Candle", colour, colour, true, bordercolor = colour)
plot(Close, "Out", color.new(color.white, 100))
