Candle Fill % Meter
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © EsIstTurnt

//@version=5
indicator("Candle Fill % Meter",overlay=true)
//Make sure the chart is set to Hollow Candles!
//Inputs
label           = input.bool (true,'Show Measurment Value by Candle',group='Candle      ')
cop             = input.bool (false,'Fill Using Cooppock Curve isntead of RSI              ',group='Candle Source (Optional:Select Only 1)')
vol             = input.bool (false,'Fill Using Volume isntead of RSI                      ',group='Candle Source (Optional:Select Only 1)')
flip            = input.bool (false,'Fill from candle Open rather than from the bottom up  ',group='Candle                                ')
zoom            = input.bool (true ,'Increase Fill Sensitivity                             ',group='Candle                                ')
arrow           = input.bool (true ,'Show Value-Dircection Characters                      ',group='Measurement                           ')
levels          = input.bool (true ,'Show Level Dividers                                   ',group='Measurement                           ')
measurecolor    = input.bool (false,'Measurement Line Color Switch                         ',group='Measurement                           ')
offsetvalue     = input.int  (1    ,'Dot Offset                                            ',group='Measurement                           ')
layers          = input.int  (5    ,'Dividing Levels                     ',maxval=5,minval=0,group='Measurement                           ')
transparency    = input.int  (50   ,'Fill Transparency 1                                   ',group='Transparency                          ')
transparency2   = input.int  (30   ,'Fill Transparency 2                                   ',group='Transparency                          ')
transparency3   = input.int  (80   ,'Fill Transparency 2                                   ',group='Transparency                          ')
border          = input.int  (0    ,'Border Transparency                                   ',group='Transparency                          ')
//Candle Colors
overbought      = input.color(#acfb00      ,'overbought (70 +)                             ',group='Colors                                ')
buy             = input.color(color.olive  ,'buy (50-70)                                   ',group='Colors                                ')
sell            = input.color(color.orange ,'sell (30-50)                                  ',group='Colors                                ')
oversold        = input.color(#ff0000      ,'oversold (- 30)                               ',group='Colors                                ')

//Calculations
float1          = 1/layers 
float2          = float1>2? float1-1:float1
oc2             = math.avg(open,close)
rs              = zoom?ta.rsi(ohlc4,8):ta.rsi(ohlc4,16)
coppock         = zoom?(ta.wma(ta.roc(hl2,6)+ta.roc(hl2,7),5)/4)+50:(ta.wma(ta.roc(hl2,11)+ta.roc(hl2,14),10)/4)+50
rsi             = rs/100
highest1        = ta.highest(high,128)
highest2        = ta.highest(high,64 )
lowest1         = ta.lowest (low ,128)
lowest2         = ta.lowest (low ,64 )
center          = ta.linreg(math.avg(highest1,highest2,lowest1,lowest2),16,0)
h_l             = highest1-lowest1
rsihl           = ta.wma((rsi*h_l)+lowest1,32)
ocbase          = flip?open:math.min(open,close)
gap             = open<close?close-open:open-close
base            = flip?open:(open<close?open:close)
rsifill         = (rsi)
volfill         = zoom?(volume/ta.highest(volume,32)):(volume/ta.highest(volume,128))
measure         = cop?(coppock/100):vol?volfill:rsifill
value           = flip?open>close?ocbase-(measure*gap):ocbase+(measure*gap):ocbase+(measure*gap)
linex           = flip?open>close?value:base:base
liney           = flip?open>close?base:value:value
linez           = open>open[1]?liney:linex
mid             = math.avg(open,close)
candle_level1   = math.min(open,close) + ((math.max(open,close)-math.min(open,close))*float1 )
candle_level2a  = math.min(open,close) + ((math.max(open,close)-math.min(open,close))*float1 )
candle_level2b  = math.max(open,close) - ((math.max(open,close)-math.min(open,close))*float1 )
candle_level3a  = math.min(open,close) + ((math.max(open,close)-math.min(open,close))*(float1*2) )
candle_level3b  = math.max(open,close) - ((math.max(open,close)-math.min(open,close))*(float1*2))
//Colors
color_a        = rs>=70?color.new(overbought,transparency):rs>=50?color.new(buy,transparency):rs>=30?color.new(sell,transparency):color.new(oversold,transparency)
color_b        = rs>=70?color.new(overbought,transparency2):rs>=50?color.new(buy,transparency2):rs>=30?color.new(sell,transparency2):color.new(oversold,transparency2)
levelcolor=measurecolor?color.new(input.color(color.white,'Alternative Measure Line Color'),transparency):color.new(color_a,transparency2)
//Draw
//plot      (candle_level1 ,'50',linewidth=1,style=plot.style_stepline,color=levelcolor)
plot      (candle_level2a,'Level #1',linewidth=1,style=plot.style_stepline,color=float2<0.5?levelcolor:na)
plot      (candle_level2b,'Level #4',linewidth=1,style=plot.style_stepline,color=float2<0.5?levelcolor:na)
plot      (candle_level3a,'Level #2',linewidth=1,style=plot.style_stepline,color=float2<0.5?levelcolor:na)
plot      (candle_level3b,'Level #3',linewidth=1,style=plot.style_stepline,color=float2<0.5?levelcolor:na)
plot      (oc2,'50',linewidth=1,style=plot.style_stepline,color= layers == 2?levelcolor:na)

plotcandle(base,high,low,value,color=cop?color_a:color_a,bordercolor=cop?color_a:color_a,wickcolor=na)
plotchar  (arrow?open<hl2[3]and value< value[2]?low  :na:na,color=color.new(color_b,transparency2),char='ₓ',offset=0,location=location.absolute,size=size.tiny)//︾
plotchar  (arrow?open>hl2[3]and value> value[2]?high :na:na,color=color.new(color_b,transparency2),char='ₓ',offset=0,location=location.absolute,size=size.tiny)//︽
plotchar  (arrow?low <hl2[2] or value<=value[4]?liney:na:na,color=color.new(color.white,transparency2),char='-',offset=0,location=location.absolute,size=size.tiny)
var label1 = label?label.new(bar_index, liney, "", style=label.style_none):na
label.set_xloc(label1, time, xloc.bar_time)
label.set_text(label1, text= input.string('Val=','Value=')+ (cop?str.tostring(math.round(coppock)):vol?str.tostring(math.round(volfill*100)):str.tostring(math.round(rs))))
label.set_y(label1, high)
label.set_textcolor(label1,color_b)

