# How to Calculate TWAP and use it for Trading?

TWAP or Time Weighted Average Price is another variant of VWAP (Volume Weighted Average Price). It is mostly used for large institutional investors to execute large orders without disturbing the market volatility. TWAP is defined as the average price of the stock for the specified period of time. It differs from VWAP as there is no volume involved in the calculation.  In this post we will understand how to calculate TWAP and use it for trading. We will also explore TWAP AFL and Excel sheet.

# How to Calculate TWAP?

TWAP is calculated by taking average of Open, High, Low and Close price of each bar, and then calculating the average of these averages for ‘n’ number of periods. For Ex: if you want TWAP value for 10 periods, then:

1. Take Average of Open, High, Low and Close values of each individual 10 bars. Say it a1,a2,a3…..a10
2. Take average of a1 to a10. TWAP= (a1+a2+a3………..+a10)/10

As simple as that, TWAP calculation does not require any  complex mathematical equations. The calculation is even simpler than VWAP.

Here is the screenshot showing how to calculate TWAP:

TWAP Calculation Excel Sheet

# TWAP AFL

Check out the TWAP AFL below from WiseStockTrader. This AFL is designed for intraday but can be easily modified for daily or weekly timeframe

```_SECTION_BEGIN("TWAP");
/*
The TWAP for a stock is calculated by Averaging OHLC in each bar then averaging the whole previous bars
Jarrah
*/

Bars_so_far_today = 1 + BarsSince( Day() != Ref(Day(), -1));
StartBar = ValueWhen(TimeNum() == 090000, BarIndex());
TodayClose = Sum(C,Bars_so_far_today);
TodayHigh = Sum(H,Bars_so_far_today);
TodayLow = Sum(L,Bars_so_far_today);
TodayOpen = Sum(O,Bars_so_far_today);
TWAP = (TodayClose + TodayHigh + TodayLow + TodayOpen)/4 ;
IIf (BarIndex() >= StartBar, ATWAP = TWAP / Bars_so_far_today,0);
Plot (ATWAP,"TWAP",colorYellow, styleThick);
_SECTION_END();
```