BAMBAM with VWAP Bands

// Knitted by Reigen lol
indicator("BAMBAM with VWAP Bands", overlay=true)
// Signal by BAMBAM
lookback = input.int(200, 'Lookback', minval=0, maxval=500, group='Signal')
lessRatio = input.float(0.05, 'Less Ratio', minval=0.001, maxval=0.1, group='Signal')
ph = high[1]
pl = low[1]
vb = high == low ? 0 : volume * (close - low) / (high - low)
vs = high == low ? 0 : volume * (high - close) / (high - low)
vd = vb[1] - vs[1]
vol = vb[1] + vs[1]
top = ta.highest(ph, lookback)
btm = ta.lowest(pl, lookback)
avgVol = math.sum(vol, lookback) / lookback
vdRatio = math.abs(vd / vol)
isLessRatio = vdRatio < lessRatio
highVol = vol > avgVol
bearSignal = ph >= top and highVol and (isLessRatio or vd < 0)
bullSignal = pl <= btm and highVol and (isLessRatio or vd > 0)
// Marker Generation
bearPlot = bearSignal ? 1 : na
bullPlot = bullSignal ? 1 : na
plotshape(series=bearPlot, color=color.new(color.red, 0), style=shape.labeldown, location=location.abovebar, offset=-1, title='Bearish Signal', size=size.small)
plotshape(series=bullPlot, color=color.new(color.lime, 0), style=shape.labelup, location=location.belowbar, offset=-1, title='Bullish Signal', size=size.small)
// Alert Conditions
alertcondition(bearSignal, title="Bearish Signal Alert", message="Bearish Signal detected")
alertcondition(bullSignal, title="Bullish Signal Alert", message="Bullish Signal detected")
// VWAP Bands by qrsq
getTheme(theme) =>
color lineCol = na
color bgCol = na
if theme == "Light"
lineCol := color.rgb(255,255,255,45)
bgCol := color.rgb(255,255,255,85)
if theme == "Dark"
lineCol := color.new(#393b44, 30)
bgCol := color.new(#393b44, 92)
if theme == "Blue"
lineCol := color.new(#2962ff,30)
bgCol := color.new(#2962ff,92)
if theme == "Red"
lineCol := color.new(#e84b4c, 30)
bgCol := color.new(#e84b4c, 92)
if theme == "Orange"
lineCol := color.new(#ffb228, 30)
bgCol := color.new(#ffb228, 92)
if theme == "Green"
lineCol := color.new(#01c082, 30)
bgCol := color.new(#01c082, 92)
[lineCol, bgCol]
theme = input.string("Dark", title="Theme", options=["Light", "Dark", "Blue", "Red", "Orange", "Green"], group="Styling")
color lineCol = na
color bgCol = na
[_lineCol, _bgCol] = getTheme(theme)
lineCol:=_lineCol
bgCol:=_bgCol
BV = high == low ? 0 : volume * (close - low) / (high - low)
SV = high == low ? 0 : volume * (high - close) / (high - low)
src = input(title = "Source", defval = hlc3, group="VWAP Settings")
length = input.int(100, title="Length", group="VWAP Settings")
stdevMultiplier = input.float(1.5, "SD Multiplier 1", group="VWAP Settings")
stdevMultiplier2 = input.float(2, "SD Multiplier 2", group="VWAP Settings")
showDouble = input.bool(true, "Show double bands", group="VWAP Settings")
sumBuy = math.sum(BV, length)
sumSrcBuy = math.sum(src*BV, length)
sumSrcSrcBuy = math.sum(BV*math.pow(src,2), length)
VWAPBuy = sumSrcBuy / sumBuy
varianceBuy = (sumSrcSrcBuy / sumBuy) - math.pow(VWAPBuy, 2)
stDevBuy = math.sqrt(varianceBuy < 0 ? 0 : varianceBuy)
sumSell = math.sum(SV, length)
sumSrcSell = math.sum(src*SV, length)
sumSrcSrcSell = math.sum(SV*math.pow(src,2),length)
VWAPSell = sumSrcSell / sumSell
varianceSell = (sumSrcSrcSell / sumSell) - math.pow(VWAPSell, 2)
stDevSell = math.sqrt(varianceSell < 0 ? 0 : varianceSell)
thresholdDown = VWAPBuy - stDevBuy * stdevMultiplier
thresholdUp = VWAPSell + stDevSell * stdevMultiplier
bottomUpper = plot(VWAPSell - stDevSell*stdevMultiplier, color=lineCol)
bottomLower = plot(thresholdDown, color=lineCol)
fill(bottomUpper, bottomLower, color=bgCol)
topLower = plot(VWAPBuy + stDevBuy*stdevMultiplier, color=lineCol)
topUpper = plot(thresholdUp, color=lineCol)
fill(topUpper, topLower, color=bgCol)
bottomDbl = plot(showDouble?VWAPSell - stDevSell*stdevMultiplier2:na, color=lineCol)
fill(bottomDbl, bottomLower, color=showDouble?bgCol:color.new(color.white, 100))
topDbl = plot(showDouble?VWAPBuy + stDevBuy*stdevMultiplier2:na, color=lineCol)
fill(topDbl, topUpper, color=showDouble?bgCol:color.new(color.white, 100))
Yalnızca davetli komut dosyası
Bu komut dosyasına yalnızca yazar tarafından onaylanan kullanıcılar erişebilir. Kullanmak için izin istemeniz ve almanız gerekir. Bu genellikle ödeme yapıldıktan sonra verilir. Daha fazla ayrıntı için aşağıdaki yazarın talimatlarını izleyin veya doğrudan Huynguyen8 ile iletişime geçin.
TradingView, yazarına tamamen güvenmediğiniz ve nasıl çalıştığını anlamadığınız sürece bir komut dosyası için ödeme yapmanızı veya kullanmanızı TAVSİYE ETMEZ. Ayrıca topluluk komut dosyalarımızda ücretsiz, açık kaynaklı alternatifler bulabilirsiniz.
Yazarın talimatları
Feragatname
Yalnızca davetli komut dosyası
Bu komut dosyasına yalnızca yazar tarafından onaylanan kullanıcılar erişebilir. Kullanmak için izin istemeniz ve almanız gerekir. Bu genellikle ödeme yapıldıktan sonra verilir. Daha fazla ayrıntı için aşağıdaki yazarın talimatlarını izleyin veya doğrudan Huynguyen8 ile iletişime geçin.
TradingView, yazarına tamamen güvenmediğiniz ve nasıl çalıştığını anlamadığınız sürece bir komut dosyası için ödeme yapmanızı veya kullanmanızı TAVSİYE ETMEZ. Ayrıca topluluk komut dosyalarımızda ücretsiz, açık kaynaklı alternatifler bulabilirsiniz.