Volume scaled Price + auto colour change light/dark mode
fi(ki)=>'ra' // © fikira This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
//@version=5
indicator('Volume scaled Price', overlay= false, precision= 3, format= format.volume)

_=' 
          --- ––––––––––––––––––––– ---[ settings ]--- ––––––––––––––––––––– ---'

src = input.string('candles', 'Option'               , options= [           'candles'     , 'volume'   ])
shw = input.string('percentile nearest rank', 'Lines', options= ['percentile nearest rank', 'BB', 'SMA'])
len = input.int   (  100    , 'length'               , minval = 1                                       )
mlt = input.float (    2    , 'mult'                 , minval = 0.1         , tooltip=  'for BB'        )
prc = input.int   (   90    , '% perc. nearest rank' , minval = 1           , maxval = 99               )
w   = input.bool  ( false   , 'show wick'                                                               )

_=' 
          --- ––––––––––––––––––––– ---[  colors  ]--- ––––––––––––––––––––– ---'

cPuD = input.color(#089981  , 'Candle '  , group='Colours (Dark theme)' , inline='1')
cPdD = input.color(#f23645  , ''         , group='Colours (Dark theme)' , inline='1')
cVuD = input.color(#91e8cb  , 'Volume'   , group='Colours (Dark theme)' , inline='2')
cVdD = input.color(#ff984e  , ''         , group='Colours (Dark theme)' , inline='2')
cBsD = input.color(#eafd43  , 'Base    ' , group='Colours (Dark theme)' , inline='3')
cB_D = input.color(#f1ffffa9, 'Line     ', group='Colours (Dark theme)' , inline='4')

cPuL = input.color(#388e3c  , 'Candle '  , group='Colours (Light theme)', inline='1')
cPdL = input.color(#b22833  , ''         , group='Colours (Light theme)', inline='1')
cVuL = input.color(#26c6da  , 'Volume'   , group='Colours (Light theme)', inline='2')
cVdL = input.color(#f57f17  , ''         , group='Colours (Light theme)', inline='2')
cBsL = input.color(#4d10c6  , 'Base    ' , group='Colours (Light theme)', inline='3')
cB_L = input.color(#574eff  , 'Line     ', group='Colours (Light theme)', inline='4')

_=' 
          --- ––––––––––––––––––––– ---[  colour  ]--- ––––––––––––––––––––– ---'

r = color.r(chart.bg_color)
g = color.g(chart.bg_color)
b = color.b(chart.bg_color)
isDark = r < 80 and g < 80 and b < 80


sCn = src   == 'candles'
upC = close > open
col = upC   ? sCn ? isDark ? cPuD : cPuL : isDark ? cVuD : cVuL  : sCn ? isDark ? cPdD : cPdL : isDark ? cVdD : cVdL 
m   = upC   ?         open : close
o   = open  - m
h   = high  - m
l   = low   - m
c   = close - m
z   = math.max(o, c)
a   = math.min(o, c)

plotcandle(sCn ?  o : 0, sCn ? w ? h : z : volume, sCn ? w ? l : a : 0, sCn ? c : volume, title= '', color= col, wickcolor= col, bordercolor= col, display= display.all - display.status_line)

prP  = ta.percentile_nearest_rank(  z   , len,       prc)
prP_ = ta.percentile_nearest_rank(  z   , len, 100 - prc)
smaP = ta.sma                    (  z   , len           )
[baseP, upP, loP] = ta.bb        (  z   , len,       mlt)

prV  = ta.percentile_nearest_rank(volume, len,       prc)
prV_ = ta.percentile_nearest_rank(volume, len, 100 - prc)
smaV = ta.sma                    (volume, len           )
[baseV, upV, loV] = ta.bb        (volume, len,       mlt)

basePlot = 
 sCn ?
 shw == 'percentile nearest rank' ?         na   :
 shw == 'BB'                      ? baseP : smaP :
 shw == 'percentile nearest rank' ?         na   :
 shw == 'BB'                      ? baseV : smaV

plot2 = 
 sCn ?
 shw == 'percentile nearest rank' ? prP   :
 shw == 'BB'                      ? upP   : na   :
 shw == 'percentile nearest rank' ? prV   :
 shw == 'BB'                      ? upV   : na

plot3 = 
 sCn ?
 shw == 'percentile nearest rank' ? prP_  :
 shw == 'BB'                      ? loP   : na   :
 shw == 'percentile nearest rank' ? prV_  :
 shw == 'BB'                      ? loV   : na

p1 = plot(basePlot, title= 'Base' , color= isDark ? cBsD  : cBsL , display= display.all - display.status_line)
p2 = plot(plot2   , title= 'Upper', color= isDark ? cB_D  : cB_L , display= display.all - display.status_line)
p3 = plot(plot3   , title= 'Lower', color= isDark ? cB_D  : cB_L , display= display.all - display.status_line)

fill(p2, p3, color= shw == 'percentile nearest rank' ? isDark ? color.new(cB_D, 93) : color.new(cB_L, 93) : na)

var line zero = line.new(na, 0, na, 0, style=line.style_dotted, color=isDark ? color.white :
 color.black, extend=extend.both), zero.set_x1(bar_index), zero.set_x2(zero.get_x1() + 1)
//hline(0, color= isDark ? color.white : color.black, linestyle=hline.style_solid)

plot(0, color= isDark ? color.white : color.black, style= plot.style_line)

dvP = volume > volume[1] and z < z[1] and z < prP_ and volume > prV
dvV = volume < volume[1] and z > z[1] and z > prP  and volume < prV_

bgcolor(dvP ? color.new(color.silver, 90) : dvV ? color.new(color.orange, 90) : na)

//pr100= ta.percentile_nearest_rank(  z   , len,       100), plot(pr100)

