Code Unity 1.0
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © hasindusithmin64

//@version=5
indicator(title='Code Unity 1.2', shorttitle='Codeunity Strategy', overlay=true)
shbb = input(false, title='Show Bolinger Bands')
shbbs = input(true, title='Show BB Signals')
sblue0 = color.new(color.blue, 0)
sorange0 = color.new(color.orange, 0)
//Bollinger Bands

lengthbb = input.int(20, minval=1, group='Bollinger Bands')
src = input(close, title='Source')
mult = input.float(2.0, minval=0.001, maxval=50, title='StdDev', group='Bollinger Bands')
basis = ta.sma(src, lengthbb)
dev = mult * ta.stdev(src, lengthbb)
upper = basis + dev
lower = basis - dev
offset = input.int(0, 'Offset', minval=-500, maxval=500, group='Bollinger Bands')
plot(shbb ? basis : na, 'BB Basis', color=color.new(#FF6D00, 0), offset=offset)
pbb1 = plot(shbb ? upper : na, 'BB Upper', color=color.new(#2962FF, 0), offset=offset)
pbb2 = plot(shbb ? lower : na, 'BB Lower', color=color.new(#2962FF, 0), offset=offset)
fill(pbb1, pbb2, title='BB Background', color=color.rgb(33, 150, 243, 95))

// DEMA

lengthd = input.int(15, minval=1, title='BB MA Length', group='BB Strategy MA')
e1 = ta.ema(close, lengthd)
e2 = ta.ema(e1, lengthd)
dema = 2 * e1 - e2

// Stoch

periodK = input.int(9, title='%K Length', minval=1, group='BB Strategy Stoch')
smoothK = input.int(3, title='%K Smoothing', minval=1, group='BB Strategy Stoch')
periodD = input.int(3, title='%D Smoothing', minval=1)
group = 'BB Strategy Stoch'
k = ta.sma(ta.stoch(close, high, low, periodK), smoothK)
d = ta.sma(k, periodD)


// RSI

rsibb = ta.rsi(close, 2)
rsibbos = input.int(9, 'BB RSI OS Level', group='BB RSI')
rsibbob = input.int(91, 'BB RSI OB Level', group='BB RSI')

//BB Strategy


shortbb = open > close and close < dema and (high > upper or high[1] > upper) and k[1] > 65 and (rsibb > rsibbob or rsibb[1] > rsibbob or rsibb[2] > rsibbob or rsibb[3] > rsibbob)
longbb = open < close and close > dema and (low < lower or low[1] < lower) and k[1] < 35 and (rsibb < rsibbos or rsibb[1] < rsibbos or rsibb[2] < rsibbos or rsibb[3] < rsibbos)


plotshape(shbbs ? shortbb : na, style=shape.labeldown, color=sorange0, location=location.abovebar, size=size.tiny, title='Short Label', text='SS', textcolor=color.new(color.white, 0))
plotshape(shbbs ? longbb : na, style=shape.labelup, color=sblue0, location=location.belowbar, size=size.tiny, title='Long Label', text='BB', textcolor=color.new(color.white, 0))

// signal = longbb == true ? 'BUY' : shortbb == true ? 'SELL' : 'NEUTRAL'

alertcondition(shortbb,"New Short Signal","Sell")
alertcondition(longbb,"New Long Signal","Buy")

