Candlestick Trailing Allocation
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © sumitmak

//@version=5
indicator("Candlestick Trailing Allocation")
l = input.int(20, minval=1, title='Length')
size = input.float(0.1, minval=0.01, title='Doji Size')
d = math.abs(open - close) <= ((high - low) * size) ? 1:0
u = (close>open) ? 1:0
dn = (open>close) ? 1:0
dsum = math.sum(d, l)
usum = math.sum(u, l)-dsum/2
dnsum = math.sum(dn, l)-dsum/2
ua = usum/l*100
dna = dnsum/l*100
da = dsum/l*100

plot(ua, color=color.green, title="Up")
plot(dna, color=color.red, title="Down")
plot(da, color=color.blue, title="Doji")
