Volume Weighted Reversal Bands
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © FriendOfTheTrend

//@version=5
indicator("Volume Weighted Reversal Bands", overlay=true)

//Percent Deviation Amount
percentDeviation = input.float(.5, title="Percentage Deviation Per Channel")/100

//Turn Short Moving Average Off
shortMaOff = input.bool(false, title="Turn Short MA Off")
vwapOff = input.bool(false, title="Turn VWAP Off")

//Styling
mainLineSupportColor = input.color(color.lime, title="Main Line Support Color")
mainLineResistanceColor = input.color(color.red, title="Main Line Resistance Color")
mainLinewidth = input.int(4, title="Main Linewidth")
deviationLineSupportColor = input.color(color.lime, title="Deviation Lines Support Color")
deviationLineResistanceColor = input.color(color.red, title="Deviation Lines Resistance Color")
deviationLinewidth = input.int(2, title="Deviation Linewidth")
vwapColor = input.color(color.white, title="VWAP Color")
vwapLinewidth = input.int(1, title="VWAP Linewidth")
shortMaSupportColor = input.color(color.lime, title="Short Line Support Color")
shortMaResistanceColor = input.color(color.red, title="Short Line Resistance Color")
shortMaLinewidth = input.int(1, title="Short MA Linewidth")

//Moving Averages
vwma100 = ta.vwma(close, 100)
vwma500 = ta.vwma(close, 500)
vwma1000 = ta.vwma(close, 1000)
vwap = ta.vwap(close)

//Combined Moving Average Logic
combinedMa = (vwma100 + vwma500 + vwma1000 + vwap) / 4
shortMa = (ta.vwma(close, 5) + ta.vwma(close, 10) + ta.vwma(close, 20) + ta.vwma(close, 50) + ta.wma(close, 5) + ta.wma(close, 10) + ta.wma(close, 20) + ta.wma(close, 50)) / 8

//Percentage Deviation Calculations
combinedMa1Up = combinedMa * (1 + percentDeviation)
combinedMa2Up = combinedMa * (1 + (percentDeviation*2))
combinedMa3Up = combinedMa * (1 + (percentDeviation*3))
combinedMa4Up = combinedMa * (1 + (percentDeviation*4))
combinedMa5Up = combinedMa * (1 + (percentDeviation*5))
combinedMa6Up = combinedMa * (1 + (percentDeviation*6))
combinedMa7Up = combinedMa * (1 + (percentDeviation*7))
combinedMa8Up = combinedMa * (1 + (percentDeviation*8))
combinedMa9Up = combinedMa * (1 + (percentDeviation*9))
combinedMa10Up = combinedMa * (1 + (percentDeviation*10))

combinedMa1Down = combinedMa * (1 - percentDeviation)
combinedMa2Down = combinedMa * (1 - (percentDeviation*2))
combinedMa3Down = combinedMa * (1 - (percentDeviation*3))
combinedMa4Down = combinedMa * (1 - (percentDeviation*4))
combinedMa5Down = combinedMa * (1 - (percentDeviation*5))
combinedMa6Down = combinedMa * (1 - (percentDeviation*6))
combinedMa7Down = combinedMa * (1 - (percentDeviation*7))
combinedMa8Down = combinedMa * (1 - (percentDeviation*8))
combinedMa9Down = combinedMa * (1 - (percentDeviation*9))
combinedMa10Down = combinedMa * (1 - (percentDeviation*10))

// Plot Lines
plot(combinedMa, title="Start Line", color=close > combinedMa ? mainLineSupportColor : mainLineResistanceColor, linewidth=mainLinewidth)

plot(combinedMa1Up, title="Up 1 Deviation Line", color=close > combinedMa1Up ? deviationLineSupportColor : deviationLineResistanceColor, linewidth=deviationLinewidth)
plot(combinedMa2Up, title="Up 2 Deviation Line", color=close > combinedMa2Up ? deviationLineSupportColor : deviationLineResistanceColor, linewidth=deviationLinewidth)
plot(combinedMa3Up, title="Up 3 Deviation Line", color=close > combinedMa3Up ? deviationLineSupportColor : deviationLineResistanceColor, linewidth=deviationLinewidth)
plot(combinedMa4Up, title="Up 4 Deviation Line", color=close > combinedMa4Up ? deviationLineSupportColor : deviationLineResistanceColor, linewidth=deviationLinewidth)
plot(combinedMa5Up, title="Up 5 Deviation Line", color=close > combinedMa5Up ? deviationLineSupportColor : deviationLineResistanceColor, linewidth=deviationLinewidth)
plot(combinedMa6Up, title="Up 6 Deviation Line", color=close > combinedMa6Up ? deviationLineSupportColor : deviationLineResistanceColor, linewidth=deviationLinewidth)
plot(combinedMa7Up, title="Up 7 Deviation Line", color=close > combinedMa7Up ? deviationLineSupportColor : deviationLineResistanceColor, linewidth=deviationLinewidth)
plot(combinedMa8Up, title="Up 8 Deviation Line", color=close > combinedMa8Up ? deviationLineSupportColor : deviationLineResistanceColor, linewidth=deviationLinewidth)
plot(combinedMa9Up, title="Up 9 Deviation Line", color=close > combinedMa9Up ? deviationLineSupportColor : deviationLineResistanceColor, linewidth=deviationLinewidth)
plot(combinedMa10Up, title="Up 10 Deviation Line", color=close > combinedMa10Up ? deviationLineSupportColor : deviationLineResistanceColor, linewidth=deviationLinewidth)

plot(combinedMa1Down, title="Down 1 Deviation Line", color=close > combinedMa1Down ? deviationLineSupportColor : deviationLineResistanceColor, linewidth=deviationLinewidth)
plot(combinedMa2Down, title="Down 2 Deviation Line", color=close > combinedMa2Down ? deviationLineSupportColor : deviationLineResistanceColor, linewidth=deviationLinewidth)
plot(combinedMa3Down, title="Down 3 Deviation Line", color=close > combinedMa3Down ? deviationLineSupportColor : deviationLineResistanceColor, linewidth=deviationLinewidth)
plot(combinedMa4Down, title="Down 4 Deviation Line", color=close > combinedMa4Down ? deviationLineSupportColor : deviationLineResistanceColor, linewidth=deviationLinewidth)
plot(combinedMa5Down, title="Down 5 Deviation Line", color=close > combinedMa5Down ? deviationLineSupportColor : deviationLineResistanceColor, linewidth=deviationLinewidth)
plot(combinedMa6Down, title="Down 6 Deviation Line", color=close > combinedMa6Down ? deviationLineSupportColor : deviationLineResistanceColor, linewidth=deviationLinewidth)
plot(combinedMa7Down, title="Down 7 Deviation Line", color=close > combinedMa7Down ? deviationLineSupportColor : deviationLineResistanceColor, linewidth=deviationLinewidth)
plot(combinedMa8Down, title="Down 8 Deviation Line", color=close > combinedMa8Down ? deviationLineSupportColor : deviationLineResistanceColor, linewidth=deviationLinewidth)
plot(combinedMa9Down, title="Down 9 Deviation Line", color=close > combinedMa9Down ? deviationLineSupportColor : deviationLineResistanceColor, linewidth=deviationLinewidth)
plot(combinedMa10Down, title="Down 10 Deviation Line", color=close > combinedMa10Down ? deviationLineSupportColor : deviationLineResistanceColor, linewidth=deviationLinewidth)

plot(vwapOff ? na : ta.vwap(close), color=vwapColor, linewidth=vwapLinewidth)
plot(shortMaOff ? na : shortMa, color=close > shortMa ? shortMaSupportColor : shortMaResistanceColor, linewidth=shortMaLinewidth)
