Bollinger Bands and SMA Channel Buy and Sell
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © ivandra447
// This Indicator is a combination of a standard BB indicator incorporated with a SSL Channel by ErwinBeckers which is Simple Moving average with a length of set at 10 (Default) and calculates the high and low set for the default 10 to form a Channel.
//The Settings for the Bollinger Band is the standard settings on a normal Bollinger Band - Length 20, souce close and Standard dev 2
// The setting for the SMA is length 10 and high and low calculated or that lentht to form a channel. 
//The SMA  Channel gives a green line for the Up channel and the Red line for the down Channel.
//The basis of the indicator is that the Candle close above the Basis line of the BB and the SMA green line will give a buy indicator
//and the same for Sell indicator the candle close below the basis BB and the SMA line Red will give a Sell indicator.
// timeframe used is as per chart and using standard candles.
// Thanks for ASteyn idea and trading strategy and inspiration for the script
// This code will be open source for anyone to use or back test or use it for whatever they want.
// This code is for my own personal trading and cannot be relied upon. This indicator cannot be used and cannot guarantee anything, and caution should always be taken when trading. Use this with other indicators to give certanty.
//Again use this for Paper Trading only.
//  I  want to thank TradingView for its platform that facilitates development and learning.

//@version=4
study(shorttitle="IV BBSMA Buy & Sell", title="Bollinger Bands and SMA Channel Buy and Sell", overlay=true)
//
//Colours
blue = #2196F3
green = #3fff00
red = #ff1100
orange = #ffae00


// Bollinger Bands
length = input(20, "Bollinger Band Length", minval=1)
src = input(close, "Bollinger Band Source")
mult = input(2.0, "Bollinger Band StdDev", minval=0.001, maxval=50)
showBasis = input(true, "Show Bollinger Band Basis")
showUpper = input(false, "Show Bollinger Band Upper")
showLower = input(false, "Show Bollinger Band Lower")
basis = sma(src, length)
dev = mult * stdev(src, length)
upper = basis + dev
lower = basis - dev

plot(showBasis ? basis : na, "Bollinger Band Basis", color= orange,linewidth =2)
plot(showUpper ? upper : na, "Bollinger Band Upper", color=blue )
plot(showLower ? lower : na, "Bollinger Band Lower", color=blue)

// SSL Channel
len = input(10, title="SMA Length")
scr1 = input(close, "SMA Source")
showSSLDown = input(true, "Show SMA Down")
showSSLUp = input(true, "Show SMA UP")
showFill = input(true, "Show SMA Fill")
smaHigh = sma(high, len)
smaLow = sma(low, len)
var float Hlv = na
Hlv := scr1 > smaHigh ? 1 : scr1 < smaLow ? -1 : Hlv[1]
sslDown = Hlv < 0 ? smaHigh : smaLow
sslUp = Hlv < 0 ? smaLow : smaHigh
p1 = plot(showSSLDown ? sslDown : na, "SMA Down", linewidth=2, color=red)
p2 = plot(showSSLUp ? sslUp : na, "SMA Up", linewidth=2, color=green)
fillCondition = showFill ? (sslUp > sslDown ? green : red) : na
fill(p1, p2, color=fillCondition, title = "SMA Fill", transp=65)


// Buy and Sell Conditions
basisCrossUp = crossover(close, basis)
sslUpCondition = close > sslUp

buyCondition = basisCrossUp and sslUpCondition
sellCondition = crossunder(close, basis)

// Plot Buy and Sell Characters
plotshape(buyCondition ? close : na, title="Buy", location=location.belowbar,textcolor = color.white, color = color.green, style=shape.labelup, text="BUY")
plotshape(sellCondition ? close : na, title="Sell", location=location.abovebar,textcolor = color.white, color = color.red, style=shape.labeldown, text="SELL")

