Bollinger Band with Moving Average & Pin Bars
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © gary_trades

//This indicator was specifically built to be used for trading the Scalpius Trading System promoted by @scottphillipstrading
//Additionally I've added daily and weekly Highs, Lows and Central Pivot lines
//The central indicators used in the Scalpius trading system which are included here are:
//The Bollinger Band, chart plotting of Pin Bars (Hammers & Shooting Stars) and a adjustable moving average,
//the user can select EMA, SMA or WMA and length, the default settings are 8EMA as per the Scalpius system rules.

//@version=5
indicator(shorttitle="BolBand, MA & PinBar", title="Bollinger Band with Moving Average & Pin Bars", overlay=true)

//SCANNER FOR PIN BARS
hammer = (math.min(open,close)-low)>= (2*math.abs(open-close)) and close > (((high-low)/2)+low)
shootingStar = (high-math.max(open,close))>= (2*math.abs(open-close)) and close < (((high-low)/2)+low)
//Plot Pins Bars
plotchar(shootingStar, location=location.belowbar, color=color.red, size=size.tiny, char="S")
plotchar(hammer, location=location.abovebar, color=color.green, size=size.tiny, char="H")

//BOLLINGER BAND
BB_len = input.int(20, "BolBand Length", minval=1)
mult = input.float(2.00, minval=0.001, maxval=50, title="BolBand StdDev")
basis = ta.sma(close, BB_len)
dev = mult * ta.stdev(close, BB_len)
upper = basis + dev
lower = basis - dev
//Plot for Bollinger Band
plot(basis, "BolBand Basis", color=#872323)
p1 = plot(upper, "BolBand Upper", color=color.gray)
p2 = plot(lower, "BolBand Lower", color=color.gray)
fill(p1, p2, title = "Background", color=color.rgb(33, 150, 243, 90))

//MOVING AVERAGE
MA_len = input.int(8, minval=1, title="MA Length")
MA_src = input(close, title="MA Source")
MA_type = input.string(defval = 'EMA', title = 'MA Type', options = ['SMA','WMA','EMA'])
ma = switch MA_type
    'SMA' =>ta.sma(MA_src, MA_len)
    'WMA' =>ta.wma(MA_src, MA_len)
    'EMA' =>ta.ema(MA_src, MA_len)
//Plot for Moving Average
plot(ma, title= 'Moving Average',color=color.blue, linewidth=2)

//DAILY & WEEKLY LEVELS (high,low & pivot)
Show_d_lines = input.bool(title="Show Daily HiLo Lines?", defval=true)
Day_HiLo_labels = input.bool(title="Daily HiLo Labels?", defval=true)
Day_p_line = input.bool(title="Show Day Pivot Line?", defval=true)
Day_Pivot_label = input.bool(title="Daily Pivot Label?", defval=true)
Show_w_lines = input.bool(title="Show Weekly HiLo Lines?", defval=true)
Week_HiLo_labels = input.bool(title="Weekly HiLo Labels?", defval=true)
Week_p_line = input.bool(title="Show Weekly Pivot Line?", defval=true)
Week_Pivot_label = input.bool(title="Weekly Pivot Label?", defval=true)
//Line and label colors
d_HiLo_col = input.color(color.green, "Daily High/Low level colors", group="Drawings")
w_HiLo_col = input.color(color.yellow, "Weekly High/Low level colors", group="Drawings")
Pivot_col = input.color(color.gray, "Pivot level color", group="Drawings")
//Required calculations
d_high = request.security(syminfo.tickerid, "D", high[1], barmerge.gaps_off, lookahead=barmerge.lookahead_on)
d_low = request.security(syminfo.tickerid, "D", low[1], barmerge.gaps_off, lookahead=barmerge.lookahead_on)
d_close = request.security(syminfo.tickerid, "D", close[1], barmerge.gaps_off, lookahead=barmerge.lookahead_on)
d_pivot = request.security(syminfo.tickerid, "D", hlc3[1], barmerge.gaps_off, lookahead=barmerge.lookahead_on)
w_high = request.security(syminfo.tickerid, "W", high[1], barmerge.gaps_off, lookahead=barmerge.lookahead_on)
w_low = request.security(syminfo.tickerid, "W", low[1], barmerge.gaps_off, lookahead=barmerge.lookahead_on)
w_close = request.security(syminfo.tickerid, "W", close[1], barmerge.gaps_off, lookahead=barmerge.lookahead_on)
w_pivot = request.security(syminfo.tickerid, "W", hlc3[1], barmerge.gaps_off, lookahead=barmerge.lookahead_on)
//Plots for levels
plot(Show_d_lines ? d_high : na,  "Prev Day Hi", color=d_HiLo_col, trackprice=true, style=plot.style_cross, linewidth=1)
plot(Show_d_lines ? d_low : na, "Prev Day Lo", color=d_HiLo_col, trackprice=true, style=plot.style_cross, linewidth=1)
plot(Day_p_line ? d_pivot : na, "Day Pivot Point", color=Pivot_col, trackprice=true, style=plot.style_cross, linewidth=1)
plot(Show_w_lines ? w_high : na,  "Prev Week Hi", color=w_HiLo_col, trackprice=true, style=plot.style_cross, linewidth=1)
plot(Show_w_lines ? w_low : na, "Prev Week Lo", color=w_HiLo_col, trackprice=true, style=plot.style_cross, linewidth=1)
plot(Week_p_line ? w_pivot : na, "Week Pivot Point", color=Pivot_col, trackprice=true, style=plot.style_cross, linewidth=1)
//Labels
bar_offset = input.int(title="label offset", defval = -10)
d_HiLabel = Day_HiLo_labels ? label.new(x=bar_index - bar_offset, y=d_high, text="Prev Day Hi", textcolor=d_HiLo_col, style=label.style_none):na
label.delete(d_HiLabel[1])
d_LoLabel = Day_HiLo_labels ? label.new(x=bar_index - bar_offset, y=d_low, text="Prev Day Low", textcolor=d_HiLo_col, style=label.style_none):na
label.delete(d_LoLabel[1])
d_PivotLabel = Day_Pivot_label ? label.new(x=bar_index - bar_offset, y=d_pivot, text="Daily Pivot", textcolor=Pivot_col, style=label.style_none):na
label.delete(d_PivotLabel[1])
w_HiLabel = Week_HiLo_labels ? label.new(x=bar_index - bar_offset, y=w_high, text="Prev Week Hi", textcolor=w_HiLo_col, style=label.style_none):na
label.delete(w_HiLabel[1])
w_LoLabel = Week_HiLo_labels ? label.new(x=bar_index - bar_offset, y=w_low, text="Prev Week Low", textcolor=w_HiLo_col, style=label.style_none):na
label.delete(w_LoLabel[1])
w_PivotLabel = Week_Pivot_label ? label.new(x=bar_index - bar_offset, y=w_pivot, text="Weekly Pivot", textcolor=Pivot_col, style=label.style_none):na
label.delete(w_PivotLabel[1])