OPEN-SOURCE SCRIPT
Anchored VWAP + Bands + Signals

//version=5
indicator("Anchored VWAP + Bands + Signals", overlay=true)
// ===== INPUTS =====
anchorTime = input.time(timestamp("2025-12-02 00:00"), "Anchor Date/Time")
std1 = input.float(1.0, "±1σ Band")
std2 = input.float(2.0, "±2σ Band")
// ===== VWAP CALCULATION =====
var float cumPV = 0.0
var float cumVol = 0.0
if time >= anchorTime
cumPV += close * volume
cumVol += volume
vwap = cumVol != 0 ? cumPV / cumVol : na
// ===== STANDARD DEVIATION =====
barsSinceAnchor = bar_index - ta.valuewhen(time >= anchorTime, bar_index, 0)
sd = barsSinceAnchor > 1 ? ta.stdev(close, barsSinceAnchor) : 0
// ===== BANDS =====
upper1 = vwap + std1 * sd
lower1 = vwap - std1 * sd
upper2 = vwap + std2 * sd
lower2 = vwap - std2 * sd
plot(vwap, color=color.orange, title="VWAP")
plot(upper1, color=color.green, title="+1σ Band")
plot(lower1, color=color.green, title="-1σ Band")
plot(upper2, color=color.red, title="+2σ Band")
plot(lower2, color=color.red, title="-2σ Band")
// ===== SIGNALS =====
buySignal = ta.crossover(close, lower1)
sellSignal = ta.crossunder(close, upper1)
plotshape(buySignal, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Buy Signal")
plotshape(sellSignal, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Sell Signal")
alertcondition(buySignal, title="Buy Alert", message="Price touched lower 1σ band – Buy Opportunity")
alertcondition(sellSignal, title="Sell Alert", message="Price touched upper 1σ band – Sell Opportunity")
indicator("Anchored VWAP + Bands + Signals", overlay=true)
// ===== INPUTS =====
anchorTime = input.time(timestamp("2025-12-02 00:00"), "Anchor Date/Time")
std1 = input.float(1.0, "±1σ Band")
std2 = input.float(2.0, "±2σ Band")
// ===== VWAP CALCULATION =====
var float cumPV = 0.0
var float cumVol = 0.0
if time >= anchorTime
cumPV += close * volume
cumVol += volume
vwap = cumVol != 0 ? cumPV / cumVol : na
// ===== STANDARD DEVIATION =====
barsSinceAnchor = bar_index - ta.valuewhen(time >= anchorTime, bar_index, 0)
sd = barsSinceAnchor > 1 ? ta.stdev(close, barsSinceAnchor) : 0
// ===== BANDS =====
upper1 = vwap + std1 * sd
lower1 = vwap - std1 * sd
upper2 = vwap + std2 * sd
lower2 = vwap - std2 * sd
plot(vwap, color=color.orange, title="VWAP")
plot(upper1, color=color.green, title="+1σ Band")
plot(lower1, color=color.green, title="-1σ Band")
plot(upper2, color=color.red, title="+2σ Band")
plot(lower2, color=color.red, title="-2σ Band")
// ===== SIGNALS =====
buySignal = ta.crossover(close, lower1)
sellSignal = ta.crossunder(close, upper1)
plotshape(buySignal, style=shape.triangleup, location=location.belowbar, color=color.green, size=size.small, title="Buy Signal")
plotshape(sellSignal, style=shape.triangledown, location=location.abovebar, color=color.red, size=size.small, title="Sell Signal")
alertcondition(buySignal, title="Buy Alert", message="Price touched lower 1σ band – Buy Opportunity")
alertcondition(sellSignal, title="Sell Alert", message="Price touched upper 1σ band – Sell Opportunity")
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。
开源脚本
秉承TradingView的精神,该脚本的作者将其开源,以便交易者可以查看和验证其功能。向作者致敬!您可以免费使用该脚本,但请记住,重新发布代码须遵守我们的网站规则。
免责声明
这些信息和出版物并非旨在提供,也不构成TradingView提供或认可的任何形式的财务、投资、交易或其他类型的建议或推荐。请阅读使用条款了解更多信息。