SMA EMA Bands [CraftyChaos]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © CraftyChaos
//
// @version=5
//
// Generates Bands between EMA and SMA and their average. I find price tends to hit one of these lines, and sometimes
// the average of the two.


indicator("SMA EMA Bands [CraftyChaos]", overlay=true)

// INPUTS

p1 = input(9, "Nine Period")
p2 = input(20, "Short Period")
p3 = input(50, "Medium Period")
p4 = input(200, "Long Period")

// COLORS

color p1c1 = color.gray
color p1c2 = color.gray

color p2c1 = #ce93d8
color p2c2 = #ba68c8

color p3c1 = #26c6da
color p3c2 = #0097a7

color p4c1 = #fbc02d
color p4c2 = #f57f17

// TA

p1ema = ta.ema(close,p1)
p1sma = ta.sma(close,p1)

p2ema = ta.ema(close,p2)
p2sma = ta.sma(close,p2)

p3ema = ta.ema(close,p3)
p3sma = ta.sma(close,p3)

p4ema = ta.ema(close,p4)
p4sma = ta.sma(close,p4)


// COLORS AGAIN

color p1cf = p1ema > p1sma ? color.new(p1c1,90) : color.new(p1c2,90)
color p2cf = p2ema > p2sma ? color.new(p2c1,90) : color.new(p2c2,90)
color p3cf = p3ema > p3sma ? color.new(p3c1,90) : color.new(p3c2,90)
color p4cf = p4ema > p4sma ? color.new(p4c1,90) : color.new(p4c2,90)


// PLOTS

p1p1 = plot(p1ema, color=p1c1)
p1p2 = plot(p1sma, color=p1c2)
p1p3 = plot((p1sma+p1ema)/2,color=p1c1, style=plot.style_cross)

p2p1 = plot(p2ema, color=p2c1)
p2p2 = plot(p2sma, color=p2c2)
p2p3 = plot((p2sma+p2ema)/2,color=p2c1, style=plot.style_cross)

p3p1 = plot(p3ema, color=p3c1)
p3p2 = plot(p3sma, color=p3c2)
p3p3 = plot((p3sma+p3ema)/2,color=p3c1, style=plot.style_cross)

p4p1 = plot(p4ema, color=p4c1)
p4p2 = plot(p4sma, color=p4c2)
p4p3 = plot((p4sma+p4ema)/2,color=p4c1, style=plot.style_cross)


// FILLS

fill(p1p1, p1p2, color=p1cf)
fill(p2p1, p2p2, color=p2cf)
fill(p3p1, p3p2, color=p3cf)
fill(p4p1, p4p2, color=p4cf)