WMA Combo Crossover V2
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © sueun123
// @version=4

// This is an upgrade of my indicator WMA Combo Crossover. Link: https://www.tradingview.com/script/X8qcBntl-WMA-Combo-Crossover/
// The upgrade was inspired from the CCI and Bollinger Bands indicator by matsu_bitmex. Link: https://www.tradingview.com/script/IkciCgbh/

study(title = "WMA Combo Crossover V2", shorttitle = "WMA Crossover V2", overlay = false, format = format.inherit, scale = scale.right)

// WMA
WMA1    = input(2, minval = 1)
Source1 = input(close, title = "Source 1")
wma1    = wma(2*wma(Source1, WMA1/2)-wma(Source1, WMA1), floor(sqrt(WMA1)))

WMA2    = input(defval = 25, minval = 1)
Source2 = input(close, title = "Source 2")
wma2    = wma(2*wma(Source2, WMA2/2)-wma(Source2, WMA2), floor(sqrt(WMA2)))

fillColor1 = wma1 > wma2 ? color.new(color.blue, transp = 70) : color.new(color.red, transp = 70)
fillColor2 = wma1 > wma2 ? color.new(color.blue, transp = 0)  : color.new(color.red, transp = 0)

p1 = plot(wma1, color = color.white, transp = 0, title = "Quick WMA",       linewidth = 1, style = plot.style_line, editable = true, display = display.all)
p2 = plot(wma2, color = fillColor2,  transp = 0, title = "Main Oscillator", linewidth = 1, style = plot.style_line, editable = true, display = display.all)
fill(p1, p2, fillColor1, title = "WMA Background Colors")

// BB
sourceone = input(open, title = "High")
sourcetwo = input(close, title = "Low")

multiply = input(defval = 1.5, minval = 0.5, title = "Deviation")

basisone = wma(sourceone, WMA2)
basistwo = wma(sourcetwo, WMA2)

deviationone = multiply * stdev(sourceone, WMA2)
deviationtwo = multiply * stdev(sourcetwo, WMA2)

upperbb = basisone + deviationone
lowerbb = basistwo - deviationtwo

p3 = plot(upperbb, title = "Upper", color = color.yellow, transp = 75, linewidth = 1, editable = true)
p4 = plot(lowerbb, title = "Lower", color = color.yellow, transp = 75, linewidth = 1, editable = true)

fillColorone = wma1 > upperbb ? color.new(color.yellow, transp = 65) : color.new(color.red, transp = 100)
fillColortwo = wma1 < lowerbb ? color.new(color.yellow, transp = 65) : color.new(color.yellow, transp = 100)

fill(p3, p1, fillColorone, title = "Outside Upper BB") // Price is very volatile going up
fill(p1, p4, fillColortwo, title = "Outside Lower BB") // Price is very volatile going down

//---END---