Volume Spread Analysis [Ahmed]
// This source code is subject to the terms of the Mozilla Public License 2.0 at https://mozilla.org/MPL/2.0/
// © aothmaan

//@version=5
indicator("Volume Spread Analysis [Ahmed]",shorttitle ='VSA [Ahmed]', overlay=false)

//Relative Volume
length = input.int(50, minval=1)
maType = input.string("SMA", "Basis MA Type", options = ["SMA", "EMA", "SMMA (RMA)", "WMA", "VWMA"])
src = volume

ma(source, length, _type) =>
    switch _type
        "SMA" => ta.sma(source, length)
        "EMA" => ta.ema(source, length)
        "SMMA (RMA)" => ta.rma(source, length)
        "WMA" => ta.wma(source, length)
        "VWMA" => ta.vwma(source, length)

basis = ma(src, length, maType)

SD1 = basis + 1 * ta.stdev(src, length)
SD2 = basis + 2 * ta.stdev(src, length)
color1= input.color(color.new(#008000, 0), "Lower Color")
color2= input.color(color.new(#ffffff, 0), "MA Color")
color3= input.color(color.new(#ff9800, 0), "MA + 1 SD Color")
color4= input.color(color.new(#ff0000, 0), "MA + 2 SD Color")

offset = input.int(0, "Offset", minval = -500, maxval = 500)
base=plot(basis, "MA", color=color.new(#ffffff, 70), offset = offset)
p1 = plot(SD1, "MA + 1 SD", color=color3, offset = offset, display=display.none)
p2 = plot(SD2, "MA + 2 SD", color=color4, offset = offset, display=display.none)
fill(p1, p2, color=color.new(#ffffff, 70))
histocolor=volume>SD2?color4 :volume>SD1?color3:volume>basis?color2: color1
plot(volume, "Volume",style=plot.style_histogram, color=histocolor, linewidth = 4)
