There are five steps in calculating VWAP:
VWAP = Cumulative(Typical Price x Volume) / Cumulative(Volume)
- Calculate the Typical Price for the period. [(High + Low + Close)/3)]
- Multiply the Typical Price by the period Volume (Typical Price x Volume)
- Create a Cumulative Total of Typical Price. Cumulative(Typical Price x Volume)
- Create a Cumulative Total of Volume. Cumulative(Volume)
- Divide the Cumulative Totals.
thinkScript Code
Code:
# VWAP with period
# Assembled by BenTen at useThinkScript.com
# Converted from https://www.tradingview.com/script/rSTNnV6B-VWAP-with-period/
input cumulativePeriod = 14;
def typicalPrice = (high + low + close) / 3;
def typicalPriceVolume = typicalPrice * volume;
def cumulativeTypicalPriceVolume = sum(typicalPriceVolume, cumulativePeriod);
def cumulativeVolume = sum(volume, cumulativePeriod);
def vwapValue = cumulativeTypicalPriceVolume / cumulativeVolume;
plot warp = vwapValue;