0% found this document useful (0 votes)
128 views1 page

VWAP Calculation in Trading Script

This document outlines the 5 step process for calculating the volume weighted average price (VWAP) over a given period: 1) calculate the typical price, 2) multiply the typical price by volume, 3) create a cumulative total of typical price x volume, 4) create a cumulative total of volume, 5) divide the cumulative totals to obtain the VWAP. It then implements this process to plot the VWAP value over a cumulative period input by the user.

Uploaded by

Kumar Rajput
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
128 views1 page

VWAP Calculation in Trading Script

This document outlines the 5 step process for calculating the volume weighted average price (VWAP) over a given period: 1) calculate the typical price, 2) multiply the typical price by volume, 3) create a cumulative total of typical price x volume, 4) create a cumulative total of volume, 5) divide the cumulative totals to obtain the VWAP. It then implements this process to plot the VWAP value over a cumulative period input by the user.

Uploaded by

Kumar Rajput
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

//@version=3

study("VWAP", overlay=true)

// There are five steps in calculating VWAP:


//
// 1. Calculate the Typical Price for the period. [(High + Low + Close)/3)]
// 2. Multiply the Typical Price by the period Volume (Typical Price x Volume)
// 3. Create a Cumulative Total of Typical Price. Cumulative(Typical Price x
Volume)
// 4. Create a Cumulative Total of Volume. Cumulative(Volume)
// 5. Divide the Cumulative Totals.
//
// VWAP = Cumulative(Typical Price x Volume) / Cumulative(Volume)

cumulativePeriod = input(14, "Period")

typicalPrice = (high + low + close) / 3


typicalPriceVolume = typicalPrice * volume
cumulativeTypicalPriceVolume = sum(typicalPriceVolume, cumulativePeriod)
cumulativeVolume = sum(volume, cumulativePeriod)
vwapValue = cumulativeTypicalPriceVolume / cumulativeVolume

plot(vwapValue)

You might also like