[_ParkF]Mini Chart(BB)
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ParkF

//@version=5
indicator('[_ParkF]Mini Chart(BB)', overlay=true)

// MINI LINE CHART
// input
barcount = input.int(50, 'Length', inline='SETTING', group='_____MINI LINE CHART')
width1 = input(2, 'Width', inline='SETTING', group='_____MINI LINE CHART')
line_col = input.color(color.new(#000000, 0), 'Color', inline='COLOR', group='_____MINI LINE CHART')
cross_bb20_col = input.color(color.new(#0c3299, 0), 'Color', inline='COLOR', group='_____MINI LINE CHART')
cross_bb120_col = input.color(color.new(#ffe500, 0), 'Color', inline='COLOR', group='_____MINI LINE CHART')

// func
line_show = true
src = close
offset = barcount+5[barcount]

// plot
plot(line_show ? src : na, title='Line', offset=offset, color=line_col, linewidth=width1, show_last=barcount, editable=false)

//  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //
//  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //
//  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //

// BOLLINGER BANDS
mult = input.float(1.0, 'Deviation', group='_____BOLLINGER BANDS')

len1 = input(20, 'Length', group='_____BB 20')
width2 = input(1, 'Width', inline='BASIS20', group='_____BB 20')
basis_col1 = input.color(color.new(#f57c00, 0), 'Color', inline='BASIS20', group='_____BB 20')
width3 = input(3, 'Width', inline='BAND20', group='_____BB 20')
band_col1 = input.color(color.new(#089981, 50), 'Color', inline='BAND20', group='_____BB 20')

len2 = input(120, 'Length', group='_____BB 120')
width4 = input(1, 'Width', inline='BASIS120', group='_____BB 120')
basis_col2 = input.color(color.new(#787b86, 0), 'Color', inline='BASIS120', group='_____BB 120')
width5 = input(4, 'Width', inline='BAND120', group='_____BB 120')
band_col2 = input.color(color.new(#5d606b, 55), 'Color', inline='BAND120', group='_____BB 120')

// func
dev1 = mult * ta.stdev(src, len1)
dev2 = mult * ta.stdev(src, len2)
basis1 = ta.sma(src, len1)
basis2 = ta.sma(src, len2)

upper1 = basis1 + dev1
upper2 = basis2 + dev2
lower1 = basis1 - dev1
lower2 = basis2 - dev2

// plot
plot(basis1, "20 BB Basis", style=plot.style_line, color=basis_col1, offset=offset, show_last=barcount, linewidth=width2, editable=false)
plot(upper1, "20 BB Upper", style=plot.style_line, color=band_col1, offset=offset, show_last=barcount, linewidth=width3, editable=false)
plot(lower1, "20 BB Lower", style=plot.style_line, color=band_col1, offset=offset, show_last=barcount, linewidth=width3, editable=false)
plot(basis2, "120 BB Basis", style=plot.style_line, color=basis_col2, offset=offset, show_last=barcount, linewidth=width4, editable=false)
plot(upper2, "120 BB Upper", style=plot.style_line, color=band_col2, offset=offset, show_last=barcount, linewidth=width5, editable=false)
plot(lower2, "120 BB Lower", style=plot.style_line, color=band_col2, offset=offset, show_last=barcount, linewidth=width5, editable=false)

// cross mark
crossbb20 = line_show == true and (ta.cross(src, basis1) or ta.cross(src, upper1) or ta.cross(src, lower1))
crossbb120 = line_show == true and (ta.cross(src, basis2) or ta.cross(src, upper2) or ta.cross(src, lower2))
plotshape(crossbb20 ? src : na, title='Line Cross 20', style=shape.circle, location=location.absolute, color=cross_bb20_col, offset=offset, size=size.tiny, show_last=barcount, editable=false)
plotshape(crossbb120 ? src : na, title='Line Cross 120', style=shape.circle, location=location.absolute, color=cross_bb120_col, offset=offset, size=size.tiny, show_last=barcount, editable=false)

//  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //
//  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //
//  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //  [_ParkF]  //

// PREDICTIVE
//input
p_width = input(1, 'Width', group='_____Predictive')
pbasis_col1 = input.color(color.new(#f57c00, 0), 'Color', inline='PBASIS20', group='_____Predictive')
pband_col1 = input.color(color.new(#089981, 0), 'Color', inline='PBASIS20', group='_____Predictive')
pbasis_col2 = input.color(color.new(#787b86, 0), 'Color', inline='PBASIS120', group='_____Predictive')
pband_col2 = input.color(color.new(#5d606b, 0), 'Color', inline='PBASIS120', group='_____Predictive')

tf = timeframe.period
sym = syminfo.tickerid
pbb20_1 = request.security(sym, tf, (ta.sma(src, len1 -1) * (len1 - 1) + src * 1) / len1)
pbb20_2 = request.security(sym, tf, (ta.sma(src, len1 -2) * (len1 - 2) + src * 2) / len1)
pbb20_3 = request.security(sym, tf, (ta.sma(src, len1 -3) * (len1 - 3) + src * 3) / len1)

pbb20_u1 = pbb20_1 + request.security(sym, tf, (ta.stdev(src, len1))) * mult
pbb20_u2 = pbb20_2 + request.security(sym, tf, (ta.stdev(src, len1))) * mult
pbb20_u3 = pbb20_3 + request.security(sym, tf, (ta.stdev(src, len1))) * mult

pbb20_l1 = pbb20_1 - request.security(sym, tf, (ta.stdev(src, len1))) * mult
pbb20_l2 = pbb20_2 - request.security(sym, tf, (ta.stdev(src, len1))) * mult
pbb20_l3 = pbb20_3 - request.security(sym, tf, (ta.stdev(src, len1))) * mult 

pbb120_1 = request.security(sym, tf, (ta.sma(src, len2 -1) * (len2 - 1) + src * 1) / len2)
pbb120_2 = request.security(sym, tf, (ta.sma(src, len2 -2) * (len2 - 2) + src * 2) / len2)
pbb120_3 = request.security(sym, tf, (ta.sma(src, len2 -3) * (len2 - 3) + src * 3) / len2)

pbb120_u1 = pbb120_1 + request.security(sym, tf, (ta.stdev(src, len2))) * mult
pbb120_u2 = pbb120_2 + request.security(sym, tf, (ta.stdev(src, len2))) * mult
pbb120_u3 = pbb120_3 + request.security(sym, tf, (ta.stdev(src, len2))) * mult

pbb120_l1 = pbb120_1 - request.security(sym, tf, (ta.stdev(src, len2))) * mult
pbb120_l2 = pbb120_2 - request.security(sym, tf, (ta.stdev(src, len2))) * mult
pbb120_l3 = pbb120_3 - request.security(sym, tf, (ta.stdev(src, len2))) * mult 


// plot
plot(pbb20_1, title='PBB_20 Base1', color=pbasis_col1, style=plot.style_circles, linewidth=p_width, offset=offset+1, show_last=1, editable=false)  
plot(pbb20_2, title='PBB_20 Base2', color=pbasis_col1, style=plot.style_circles, linewidth=p_width, offset=offset+2 , show_last=1, editable=false)  
plot(pbb20_3, title='PBB_20 Base3', color=pbasis_col1, style=plot.style_circles, linewidth=p_width, offset=offset+3, show_last=1, editable=false) 

plot(pbb20_u1, title='PBB_20 Upper1', color=pband_col1, style=plot.style_circles, linewidth=p_width, offset=offset+1, show_last=1, editable=false)
plot(pbb20_u2, title='PBB_20 Upper2', color=pband_col1, style=plot.style_circles, linewidth=p_width, offset=offset+2, show_last=1, editable=false)
plot(pbb20_u3, title='PBB_20 Upper3', color=pband_col1, style=plot.style_circles, linewidth=p_width, offset=offset+3, show_last=1, editable=false)

plot(pbb20_l1, title='PBB_20 Lower1', color=pband_col1, style=plot.style_circles, linewidth=p_width, offset=offset+1, show_last=1, editable=false)
plot(pbb20_l2, title='PBB_20 Lower2', color=pband_col1, style=plot.style_circles, linewidth=p_width, offset=offset+2, show_last=1, editable=false)
plot(pbb20_l3, title='PBB_20 Lower3', color=pband_col1, style=plot.style_circles, linewidth=p_width, offset=offset+3, show_last=1, editable=false)

plot(pbb120_1, title='PBB_120 Base1', color=pbasis_col2, style=plot.style_circles, linewidth=p_width, offset=offset+1, show_last=1, editable=false)  
plot(pbb120_2, title='PBB_120 Base2', color=pbasis_col2, style=plot.style_circles, linewidth=p_width, offset=offset+2 , show_last=1, editable=false)  
plot(pbb120_3, title='PBB_120 Base3', color=pbasis_col2, style=plot.style_circles, linewidth=p_width, offset=offset+3, show_last=1, editable=false) 

plot(pbb120_u1, title='PBB_120 Upper1', color=pband_col2, style=plot.style_circles, linewidth=p_width, offset=offset+1, show_last=1, editable=false)
plot(pbb120_u2, title='PBB_120 Upper2', color=pband_col2, style=plot.style_circles, linewidth=p_width, offset=offset+2, show_last=1, editable=false)
plot(pbb120_u3, title='PBB_120 Upper3', color=pband_col2, style=plot.style_circles, linewidth=p_width, offset=offset+3, show_last=1, editable=false)

plot(pbb120_l1, title='PBB_120 Lower1', color=pband_col2, style=plot.style_circles, linewidth=p_width, offset=offset+1, show_last=1, editable=false)
plot(pbb120_l2, title='PBB_120 Lower2', color=pband_col2, style=plot.style_circles, linewidth=p_width, offset=offset+2, show_last=1, editable=false)
plot(pbb120_l3, title='PBB_120 Lower3', color=pband_col2, style=plot.style_circles, linewidth=p_width, offset=offset+3, show_last=1, editable=false)

