[Floride] 4 Layers of Bollinger Shadow
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © Floride

//@version=5

indicator('MLBS - Multi Layers of Bollinger Shadow', 'MLBS', overlay=true)

len = input.int(192, minval=1, title='주기-기간')
len2 = len * 2
len3 = len * 3
len4 = len * 4
len5 = len * 5

len15 = math.round(len * 1.5)
len25 = math.round(len * 2.5)
len35 = math.round(len * 3.5)
len45 = math.round(len * 4.5)
len55 = math.round(len * 5.5)

tunaon = input(true,"Tuna signal ON")
lmarlinon = input(true,"Little Marlin signal ON")
marlinon = input(true,"Marlin signal ON")

src = input(close, title='Input Source')

// m1 = input(1, minval=0.001, maxval=50)
m2 = input.float(1.62, minval=0.001, maxval=50)
m3 = input.float(2.62, minval=0.001, maxval=50)

cl = ta.ema(src, len)  // central line


dev11 = m2 * ta.stdev(src, len)
up11 = cl + dev11
low11 = cl - dev11

dev12 = m3 * ta.stdev(src, len)
up12 = cl + dev12
low12 = cl - dev12

dev151 = m2 * ta.stdev(src, len15)
up151 = cl + dev151
low151 = cl - dev151

dev152 = m3 * ta.stdev(src, len15)
up152 = cl + dev152
low152 = cl - dev152




dev22 = m2 * ta.stdev(src, len2)
up22 = cl + dev22
low22 = cl - dev22

dev252 = m2 * ta.stdev(src, len25)
up252 = cl + dev252
low252 = cl - dev252






dev32 = m2 * ta.stdev(src, len3)
up32 = cl + dev32
low32 = cl - dev32

dev352 = m2 * ta.stdev(src, len35)
up352 = cl + dev352
low352 = cl - dev352












dev42 = m2 * ta.stdev(src, len4)
up42 = cl + dev42
low42 = cl - dev42


dev452 = m2 * ta.stdev(src, len45)
up452 = cl + dev452
low452 = cl - dev452






dev52 = m2 * ta.stdev(src, len5)
up52 = cl + dev52
low52 = cl - dev52

dev53 = m3 * ta.stdev(src, len5)
up53 = cl + dev53
low53 = cl - dev53





L1ON = input(true, 'L1(Basis Layer) ON')
L2ON = input(true, 'L2 ON')
L3ON = input(true, 'L3 ON')
L4ON = input(true, 'L4 ON')
PRON = input(true, 'Precedence Layer on') //precede layer 1,2 on



betweenshadowon = input(true, 'Shadows between shadows ON?')

shadeoff = input(false,"shade off")


plot(PRON ? up11 : na, 'up11', color=color.new(#acff2f, 50), linewidth=0 ,style=plot.style_circles)
plot(PRON ? low11 : na, 'low11', color=color.new(#acff2f, 55), linewidth=0,style=plot.style_circles)
plot(PRON ? up151 : na, 'up151', color=color.new(#aee161, 25), linewidth=1,style=plot.style_circles)
plot(PRON ? low151 : na, 'low151', color=color.new(#acdf60, 22), linewidth=1,style=plot.style_circles)



pu252 = plot(L1ON and betweenshadowon? up252 : na, 'up2', color=color.new(#006400, 33), linewidth=3)
pl252 = plot(L1ON and betweenshadowon? low252 : na, 'low2', color=color.new(#006400, 33), linewidth=3)

pu32 = plot(L2ON ? up32 : na, 'up32', color=color.new(#414b94, 32), linewidth=3)
pl32 = plot(L2ON ? low32 : na, 'low32', color=color.new(#414b94, 44), linewidth=3)
pu352 = plot(L2ON and betweenshadowon? up352 : na, 'up352', color=color.new(#414b94, 55), linewidth=2)
pl352 = plot(L2ON and betweenshadowon? low352 : na, 'low352', color=color.new(#414b94, 55), linewidth=2)

pu42 = plot(L3ON ? up42 : na, 'up42', color=color.new(#737373, 55), linewidth=2)
pl42 = plot(L3ON ? low42 : na, 'low42', color=color.new(#737373, 55), linewidth=2)
pu452 = plot(L3ON and betweenshadowon? up452 : na, 'up452', color=color.new(#737373, 66), linewidth=2)
pl452 = plot(L3ON and betweenshadowon? low452 : na, 'low452', color=color.new(#737373, 66), linewidth=2)


pu52 = plot(L4ON ? up52 : na, 'up22', color=color.new(#FF0000, 66), linewidth=4)
pl52 = plot(L4ON ? low52 : na, 'low22', color=color.new(#FF0000, 66), linewidth=4)

pu53 = plot(L4ON ? up53 : na, 'up23', color=color.new(#FF0000, 33), linewidth=2)
pl53 = plot(L4ON ? low53 : na, 'low23', color=color.new(#FF0000, 33), linewidth=2)



CL = plot(cl, 'cl', color=color.new(color.gray, 0), linewidth=4)



MP = plot(hl2,color=color.new(color.silver,99))

var tr0 = 0
var tr0s = 0
if ta.crossover(close, up22)
    tr0 := 1

if ta.crossunder(close, up22)
    tr0 := 0

if ta.crossunder(close, low22)
    tr0 := -1
if ta.crossover(close, low22)
    tr0 := 0




low3 = ta.ema(low,3)
high3 = ta.ema(high,3)


if ta.crossover(low3, up22)
    tr0s := 1
    

if ta.crossunder(high3, low22)
    tr0s := -1


var float tr0p = na
float tuna = na



if tr0s[1] != 1 and tr0s == 1 and tunaon
    tuna := close
if tr0s[1] != -1 and tr0s == -1 and tunaon
    tuna := close

tr0cu = tr0 == 1 ? color.lime : na
tr0cl = tr0 == -1 ? color.lime : na

plot(tunaon ? tuna : na,color=color.lime,linewidth=7,style=plot.style_cross)

var tr1 = 0

if ta.crossover(close, up32)
    tr1 := 1
    
if ta.crossunder(close, up32)
    tr1 := 0
    
if ta.crossunder(close, low32)
    tr1 := -1

if ta.crossover(close, low32)
    tr1 := 0
    


tr1cu = tr1 == 1 ? color.rgb(255, 153, 0, 25) : na
tr1cl = tr1 == -1 ? color.rgb(255, 153, 0, 33) : na




float marlin = na      
float lmarlin = na

var int tr3s = na
var tr3 = 0
if ta.crossover(close, up53)
    tr3 := 1

if ta.crossunder(close, up53)
    tr3 := 0

if ta.crossunder(close, low53)
    tr3 := -1

if ta.crossover(close, low53)
    tr3 := 0


if ta.crossunder((hl2+close)/2, low52)
    tr3s := -1

if ta.crossover((hl2+close)/2  , up52)
    tr3s := 1





if tr3s[1] == -1 and tr3s == 1
    lmarlin := close

if tr3s[1] == 1 and tr3s == -1
    lmarlin := close


tr3sc = tr3s == 1 ? color.new(color.orange,96) : color.new(color.lime,77)


tr0bgon = input(true,"L1 transition BGC ON")
tr3bgon = input(false,"L4 transition BGC ON")

bgcolor(tr0bgon and tr0s == 1 ? color.new(color.orange,99) : tr0bgon and tr0s == -1 ? color.new(color.blue,80) : na)
bgcolor(tr3bgon ? tr3sc : na)




if ta.crossover(low, up53) and marlinon
    marlin := close
if ta.crossunder(high, low53)  and marlinon
    marlin := close

tr3cu = tr3 == 1 ? color.red : na
tr3cl = tr3 == -1 ? color.red : na


plot(marlinon ? marlin : na,style=plot.style_cross,linewidth=12,color=color.red)
plot(lmarlinon ? lmarlin : na,style=plot.style_cross,linewidth=9,color=color.rgb(243, 226, 77))



pu22 = plot(L1ON ? up22 : na, 'up2'  , color=color.new(#d3ff91, 55), linewidth=10)
pl22 = plot(L1ON ? low22 : na, 'low2', color=color.new(#d3ff91, 55), linewidth=10)



plot(L1ON and tr0s == -1 ?  up22  : na, 'up2'  , color=color.new(#ADFF2F, 0), linewidth=9,style= plot.style_linebr)
plot(L1ON and tr0s ==  1 ?  low22 : na, 'low2' , color=color.new(#ADFF2F, 0), linewidth=9,style= plot.style_linebr)

plot(L1ON and tr0s == -1 ?  up22  : na, 'up2' , color=color.new(#7cc254, 19) , linewidth=6 ,style= plot.style_linebr)
plot(L1ON and tr0s ==  1 ?  low22 : na, 'low2', color=color.new(#7cc254, 19), linewidth=6 ,style= plot.style_linebr)

plot(L1ON and tr0s == -1 ? up22  : na, 'up2' , color=color.new(#006400, 0), linewidth=3,style= plot.style_linebr)
plot(L1ON and tr0s ==  1 ? low22 : na, 'low2', color=color.new(#006400, 0), linewidth=3,style= plot.style_linebr)

alttrend = input(false,"alt trend")


plot(alttrend == false ?  up22  : na, 'up2'  , color=color.new(#ADFF2F, 77), linewidth=4,style= plot.style_linebr)
plot(alttrend == false ?  low22 : na, 'low2' , color=color.new(#ADFF2F, 77), linewidth=4,style= plot.style_linebr)


plot(alttrend == false ?  up22  : na, 'up2' , color=color.new(#7cc254, 22) , linewidth=3 ,style= plot.style_linebr)
plot(alttrend == false ?  low22 : na, 'low2', color=color.new(#7cc254, 22), linewidth=3 ,style= plot.style_linebr)

plot(alttrend == false ?  up22  : na, 'up2' , color=color.new(#006400, 0), linewidth=2,style= plot.style_linebr)
plot(alttrend == false ?  low22 : na, 'low2', color=color.new(#006400, 0), linewidth=2,style= plot.style_linebr)



fill(pu52, pl52, color=shadeoff ? na :color.new(color.red, 88))
fill(pu42, pl42, color=shadeoff ? na :color.new(#737373, 80))
fill(pu32, pl32, color=shadeoff ? na : color.new(#414b94, 80))
fill(pu22, pl22, color=shadeoff ? na : color.new(color.green, 77))




fill(MP, pu22, color=tr0cu )
fill(MP, pl22, color=tr0cl )

fill(MP, pu32, color=tr1cu )
fill(MP, pl32, color=tr1cl )

fill(MP, pu53, color=tr3cu )
fill(MP, pl53, color=tr3cl )






alertcondition(tr0 > 0 and tuna , title='ASCENDING TUNA'  , message = 'ASCENDING TUNA-상승참치')
alertcondition(tr0 < 0 and tuna , title='DESCENDING TUNA' , message = 'DESCENDING TUNA-하락참치')

alertcondition(tr0 > 0 and lmarlin , title='ASCENDING LITTLE MARLIN-상승소새치', message = 'ASCENDING LITTLE MARLIN-상승소새치')
alertcondition(tr0 < 0 and lmarlin , title='DESCENDING LITTLE MARLIN-하락소새치', message = 'DESCENDING LITTLE MARLIN-하락소새치')

alertcondition(tr0 > 0 and marlin , title='ASCENDING MARLIN-상승청새치', message = 'ASCENDING MARLIN-상승청새치')
alertcondition(tr0 < 0 and marlin , title='DESCENDING MARLIN-하락청새치', message = 'DESCENDING MARLIN-하락청새치')



// © Floride
