Multi day VWAP

06Apr09

VWAP, or Volume Weighted Average Price, is a great tool for analysing intraday trends. I got my insight to this useful indicator from Brian Shannon at Alphatrends and Dr. Brett Steenbarger at Traderfeed. A big thanks to both for the great resources they provide.

The daily VWAP starts tracking it’s value from the start of the trading day. I have decided to extend this concept and create a multiday VWAP which starts tracking this value for the last major change in Market Sentiment (first positive day after the last bottom).

In Amibroker, I have done this by defining a vertical line study, and then coding up the multi day VWAP to start calculating from this line. What I like about this method is that I can drag the line forwards and backwards without needing to enter parameters or modifying code. Probably at some point I would extend this concept to locate this shift automatically.

Here is the result on the S&P Rally since the day I consider the sentiment changed. The light green vertical bar is the study which can be dragged left or right and the pink line is the VWAP. Note how the price retracts quite nicely back to the VWAP before moving higher. It will be interesting to watch whether the price will retract back and resume it’s upward trend or fall through.

image

 

Here is the Amibroker AFL code:

//VWAP since last change in sentiment
TurningPoint = IIf(Study(“ST”,GetChartID())==0,1,0);
BarsSinceLastTurn = 1 + BarsSince(TurningPoint==1);
StartBar = ValueWhen(TurningPoint==1, BarIndex());
RunVolume = Sum(V,BarsSinceLastTurn);
IIf (BarIndex() >= StartBar, MTVWAP = Sum (C * V, BarsSinceLastTurn  ) / RunVolume,0);
Plot (MTVWAP,”MTVWAP”,colorPink, styleLine);

(Code was adapted from a formula available on the Amibroker AFL Library)

 

In order for this to work, a vertical study must be placed on the chart, and its ID set to “ST”.

image



5 Responses to “Multi day VWAP”

  1. 1 dingo

    This line:

    IIf (BarIndex() >= StartBar, MTVWAP = Sum (C * V, BarsSinceLastTurn ) / RunVolume,0);

    doesn’t do anything, does it? I say that since in the help file says that IIF should be on the right side of “=” and gives an array as a result.

  2. 2 dingo

    Actually ( I haven’t tested it yet ) that line might should read:

    MTVWAP = IIf (BarIndex() >= StartBar, Sum (C * V, BarsSinceLastTurn ) / RunVolume,0);

    d

  3. 3 etoke

    Hi Dingo,

    thanks for your feedback. I tested it and both the original and your version give the same result.
    Actually when I wrote this post, I copied and pasted the code from my working charts without much thought, but coming to think of it I am not quite sure why the original works, as you correctly point out IIF should be on the right side!

  4. It will work both ways, its just easier to understand with the variable = iif and I think its less typing. You can use the alternate method (as in the post) if you want to do totally different things based on the statement true or false

  5. I just did a post on this and link to you. When I used your code I got an error, inserted “nz” for the study line so if it doesn’t exist the code doesn’t complain.


Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Connecting to %s


Follow

Get every new post delivered to your Inbox.