Average Proportional Capital
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © AlexanderRios

//@version=5
indicator(title='Capital Proporcial Medio', shorttitle='CPM', format=format.price, precision=2, timeframe='')
//indicator("CPM")
len1 = input.int(52, minval=1)
CPM = close * volume
volmax = ta.highest(CPM, len1)
v = CPM * 100 / volmax * 4 / 5
volpmed = ta.ema(v, len1)
CPM2 = v - volpmed
sma5 = ta.sma(CPM2, 5)
sma20 = ta.sma(CPM2, 20)
// plot(close)
plot(CPM2, title='CPM', style=plot.style_histogram, color=CPM2 > 0 ? color.green : color.red)
plot(sma5, title='SMA5', color=color.new(color.gray, 0))
plot(sma20, title='SMA20', color=color.new(color.orange, 0))