Volume
Volume Weighted Moving Average
A volume weighted moving average drawn against a simple average of the same length, which exposes the bars where heavy volume pulls the average away from where price alone would put it.
indicator
//@version=6
indicator("Volume Weighted Moving Average", "VWMA", overlay = true)
length = input.int(20, "Length", minval = 1, group = "Settings")
src = input.source(close, "Source", group = "Settings")
bull = input.color(#26A69A, "Volume weighted on top", group = "Style")
bear = input.color(#EF5350, "Simple on top", group = "Style")
plainCol = input.color(#787B86, "Simple average", group = "Style")
vwmaLine = ta.vwma(src, length)
smaLine = ta.sma(src, length)
leaning = vwmaLine > smaLine ? bull : bear
pVwma = plot(vwmaLine, "Volume weighted", color = leaning, linewidth = 2)
pSma = plot(smaLine, "Simple", color = color.new(plainCol, 20))
fill(pVwma, pSma, color = color.new(leaning, 88), title = "Gap")
crossedUp = ta.crossover(vwmaLine, smaLine)
crossedDown = ta.crossunder(vwmaLine, smaLine)
plotshape(crossedUp, "Weighted above simple", location = location.belowbar, style = shape.triangleup, color = bull, size = size.tiny)
plotshape(crossedDown, "Weighted below simple", location = location.abovebar, style = shape.triangledown, color = bear, size = size.tiny)
alertcondition(crossedUp, "VWMA above SMA", "The volume weighted average crossed above the simple average")
alertcondition(crossedDown, "VWMA below SMA", "The volume weighted average crossed below the simple average")
This runs in TradingView, not here
Pine Script only executes inside TradingView. Paste the source into the Pine Editor and add it to a chart to see it plotted.
What it will not do
- Both averages lag, and weighting by volume does not remove that. The cross confirms a shift that has already happened.
- The two lines sit close together most of the time. A gap only appears when volume was unusually concentrated on a few bars.
- Volume weighting is only as good as the volume feed. On spot forex TradingView reports tick count, so the weighting there is by activity rather than size.
Written from this description
Plot a volume weighted moving average and a simple moving average of the same length, shade the gap between them, colour it by which one is on top, and alert when they cross.
Educational only, not financial advice. The maths is simple arithmetic on the numbers you enter; it knows nothing about your broker, fees, slippage or the market. Something wrong with it? Say so in Site Feedback.