EMA/MA Cross + BB + Alerts 
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © revolution05
/////// u/ tmyerskerry for the math on slope and look back period
///////
///////Multiple Parts to Code - Part 1 EMA/SMA  -  Part 2 Bollinger Band   -    Part 3
///////
//@version=5
indicator(title="EMA/MA + BB + Alerts ", shorttitle="EMA/SMA+BB", overlay=true)

lookback_period=input(defval=100)
radians_to_degrees=180/3.14159265359
signal = ta.ema(close, 200)

len1 = input(9, title="EMA #1 - Primary Cross")
src1 = input(close, title="EMA Source #1")
out1 = ta.ema(src1, len1)
plot(out1, title="EMA #1",color=color.yellow)

len2 = input(13, title="EMA #2")
src2 = input(close, title="EMA Source #2")
out2 = ta.ema(src2, len2)
plot(out2, title="EMA #2",color=color.green)

len3 = input(34, title="EMA #3 - Secondary Cross")
src3 = input(close, title="SMA Source #3")
out3 = ta.ema(src3, len3)
plot(out3, title="EMA #3",color=color.gray)

len4 = input(55, title="EMA #4")
src4 = input(close, title="EMA Source #4")
out4 = ta.ema(src4, len4)
plot(out4, title="EMA #4")

len5 = input(50, title="SMA #1")
src5 = input(close, title="SMA Source #1")
out5 = ta.sma(src5, len5)
plot(out5, title="SMA #1",color=color.red)

len6 = input(100, title="SMA #2")
src6 = input(close, title="SMA Source #2")
out6 = ta.sma(src6, len6)
plot(out6, title="SMA #2",color=color.green)

len7 = input(200, title="SMA #3 - ")
src7 = input(close, title="SMA Source #3")
out7 = ta.sma(src7, len7)
plot(out7, title="SMA #3",color=color.purple)

len8 = input(1, title="SMA #4")
src8 = input(close, title="SMA Source #4")
out8 = ta.sma(src8, len8)
plot(out8, title="SMA #4")

len9 = input(1, title="SMA #5")
src9 = input(close, title="SMA Source #5")
out9 = ta.sma(src9, len9)
plot(out9, title="SMA #5")

len10 = input(1, title="SMA #6")
src10 = input(close, title="SMA Source #6")
out10 = ta.sma(src10, len10)
plot(out10, title="SMA #6")


signal_slope = radians_to_degrees*math.atan((signal[0]-nz(signal[lookback_period]))/lookback_period)


plotshape(signal_slope > 0 and ta.crossover(out1,out3),title= "Strong Long",style=shape.arrowup, location=location.belowbar,color=color.green, size=size.huge)
plotshape(signal_slope < 0 and ta.crossover(out1,out3),title= "Weak Long", style=shape.arrowup, location=location.belowbar,color=color.yellow, size=size.huge)
plotshape(signal_slope < 0 and ta.crossunder(out1,out3),title= "Strong Short", style=shape.arrowdown, location=location.abovebar,color=color.red, size=size.huge)
plotshape(signal_slope > 0 and ta.crossunder(out1,out3),title= "Weak Short", style=shape.arrowdown, location=location.abovebar,color=color.orange, size=size.huge)

////Bollinger Band Code

[middle, upper, lower] = ta.bb(close, 20, 2)
plot(middle, title="Middle BB", color=color.blue)
p1PlotID = plot(upper, title="Upper BB", color=color.white)
p2PlotID = plot(lower, title="Lower BB", color=color.white)
crossUp = ta.crossover(high, upper)
crossDn = ta.crossunder(low, lower)

var TRANSP = 90

fill(p1PlotID, p2PlotID, color = color.new(color.white, TRANSP),title="BB Shadow")
bgcolor(crossUp ? color.new(color.green, TRANSP) : crossDn ? color.new(color.red, TRANSP) : na, title="Outside BB Shadow")


//// Code for alerts
