Registered User Joined: 4/17/2007 Posts: 39
|
I'm looking for a way of calculating VWAP in StockFinder. I see the PCF's in the forums for Telechart, but haven't quite been able to figure out how to do it using Realcode. I'm primarily interested in a 1 day and 2 day VWAP on a 5min chart, but ideally would like a flexible formula that could be adopted to other timeframes. Thanks in advance for any help.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
I do not know of a way to create a VWAP (Volume Weighted Average Price) in the current version of StockFinder (or TeleChart for that matter) as this would generally require more tick data than is available (there are additional reasons in TeleChart). It is possible to create a VWMA (Volume Weighted Moving Average) in both programs.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 4/17/2007 Posts: 39
|
Thanks Bruce. Can you please help with the VWMA calculation in Stockfinder?
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
One way to create a Simple Volume Weighted Moving Average of Price as a RealCode Indicator would be:
'# Period = UserInput.Integer = 20
Static SumVxP As Single
Static SumV As Single
If CurrentIndex >= Period Then
SumVxP += Price.Last * Volume - Price.Last(Period) * Volume(Period)
SumV += Volume - Volume(Period)
Plot = SumVxP / SumV
Else If CurrentIndex = Period Then
SumVxP += Price.Last * Volume
SumV += Volume
Plot = SumVxP / SumV
Else If isFirstBar Then
SumVxP = Price.Last * Volume
SumV = Volume
Plot = Single.NaN
Else
SumVxP += Price.Last * Volume
SumV += Volume
Plot = Single.NaN
End If
One way to create an Exponential Volume Weighted Moving Average of Price as a RealCode Indicator would be:
'# Period = UserInput.Single = 20
'# Cumulative
Static EMApXv As Single
Static EMAv As Single
Static sumWeight As Single
Static termRatio As Single
If isFirstBar Then
EMApXv = Price.Last * Volume
EMAv = Volume
sumWeight = termRatio + 1
termRatio = (Period - 1) / (Period + 1)
Else
Dim Weight As Single = 1 / sumWeight
EMApXv = EMApXv * (1 - Weight) + Weight * Price.Last * Volume
EMAv = EMAv * (1 - Weight) + Weight * Volume
sumWeight = sumWeight * termRatio + 1
End If
Plot = EMApXv / EMAv
You will need to make sure the Moving Average is Scaled with the Price History.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 4/17/2007 Posts: 39
|
Thanks for the code Bruce. I tried both of these and unfortunately the plots do resemble what VWAP should look like (even approximatly). I tried to use period of 78 on a 5 min chart (about 1 day) and get wild oscillations which are not appropriate for this type of average. I also compared these plots to VWAP plots from other sources and they are quite different in both shape and scale. Not sure what to try next.
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
You keep referencing Volume Weighted Average Price (VWAP). As already stated, I do not see a VWAP as practical in the current version of StockFinder (at least it is beyond my capabilities). The above code is for a Volume Weighted Moving Average (VWMA).
If you mean a VWMA instead of a VWAP, then the most likely reason I can think of that it would not match other sources is not being scaled with Price. You can right-click on the VWMA and select Scaling | Scale With | Price History if this is the issue.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 5/12/2008 Posts: 102
|
Bruce
I have just been searching for a VWAP indicator in SF and came across this thread.
I'm puzzled by your statement that you need more tick data than is available.
I published the VWAP formula in this thread some time ago:
http://www.worden.com/training/default.aspx?g=posts&t=33098
As per the formula, all that is needed is the ability to aggregate price and quantity for each trade.
There are many excellent indicators in SF, and it is a real oversight that VWAP isn't included.
To be able to scan for stocks over or below their VWAP, or for a rising of falling VWAP, would be hugely useful and a valuable asset for SF.
Thanks
Chris
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
operandi,
I am puzzled by your puzzlement as I do not know of a way to correlate price with individual trades without tick data (and my post mentions having limited tick data available). If you have an idea as to how to do so, please let me know and I'll see if I can figure something out.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 5/12/2008 Posts: 102
|
Hi Bruce
I wasn't aware that you are not sending tick data in your feed, so you obviously are unable to correlate trades with prices.
I'm evaluating SF, having been forced away from Blocks a while back, and although I think SF has some really excellent features (I particularly like the ability to display one symbol in another symbol's chart, for example), there are huge limitations in your data feed such as:
No tick data, as we are discussing
No out of hours data, analysis or trading ability
The update of real time data just as the markets open
We can't use our own datafeed, say from IB, for example, and have to pay extra for your inferior feed
I know that you are not marketing SF as a trading platform (although you have some trading capabilities), and that it is a really excellent scanning tool, however it's data feed limitations really seem to let the product down (IMO), particularly for intraday useage.
Chris
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
Just to avoid any confusion, StockFinder does have a Tick Time Frame available. It just doesn't have enough data for use in creating a significant number of Bars in longer Time Frames or for constructing a VWAP. Most of StockFinder's Time Frames are constructed entirely using either Daily or Minute data.
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 12/14/2005 Posts: 10
|
I don't want this to be a new topic, I am trying the follow the VWAP discussion. I have been following this thread with much interest since I would like to see SF track the one and two day Volume Weighted Average Price. I am rather clueless on the RealCode writing, but couldn't you use the average of the OHLC for each one minute bar for price against the volume for that one minute bar to arrive at the volume weighted price for that bar. The important thing is to "cummulate" the calculation from the first bar of the day to the current bar for the current day (for daily VWAP) and the first bar of the previous day to the current bar (for the 2-day VWAP) rather than run a 20 period volume weighted moving average as indicated in your RealCode?
Tyler
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
flamestillburns,
You should be able to Open the attached Chart directly into a running copy of StockFinder. You'll probably want to have 5000 Bars of Intraday data to get a good feel for what is happening. It's not meant as a final product by any means, it is just designed as a starting point for the conversation about what you think might work as an adequate substitute for a tick based VWAP and how you would want it calculated and Plotted.
The attached Chart has a 1-Minute Price History Pane, a Volume Pane and a 1-Day Price History Pane.
The 1-Day Price History Pane displays the ongoing Volume Weighted Average Price calculations as computed from the average of the 1-Minute Open, High, Low and Close values when reset at the start of each trading day. It also has a 390-Period Simple Volume Weighted Moving Average of the average of the 1-Minute Open, High, Low and Close values. You will notice that these lines match at the end of each trading day.
Using the (Open + High + Low + Close) / 4 is going to generally create a smoother line that just using the Close (or even Typical Price: (High + Low + Close) / 3 or Median Price: (High + Low) / 2), but there is no way to know how many shares traded at each level unless the High and the Low of the Bar are the same.Attachments: flamestillburns36855.sfChart - 80 KB, downloaded 558 time(s).
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Registered User Joined: 12/14/2005 Posts: 10
|
Bruce,
I took your plot, removed the 390 period Volume Weighted Average Price plot and unchecked the Price History dialogue box “draw on chart”. Then when I overlaid the VWAP 1-Day from 1-Minute plot over the Price History in my top pane, it scaled and line up perfectly against the price history (on all time frames). Except for the doubled up scale column, it seems that this is the calculation that I am looking for and it compares favorably to other chart applications that I have seen (Realtick) that display VWAP. I understand your comment about not knowing how many shares traded at each level, but on a one minute basis, its seems pretty close we are in the ballpark. Notwithstanding all of the dialogue about the VWAP’s relevance or usefulness, the shortcut to the price and volume data in your calculation seems to work fine. Why all the fuss and what am I missing? Ignorance has its place, I guess. Anyway, how do I eliminate one of the scales on my top Price History pane? I am assuming I can not "child plot" the VWAP into my top Price History pane since the price history plot is different. Also, can you show me the Real Code for a “VWAP 2-Day from 1-minute”? For the life of me I can not figure out the nomenclature for RealCode, but I am making some progress.. Thanks for your help.
Tyler
|
|
Worden Trainer
Joined: 10/7/2004 Posts: 65,138
|
The RealCode Indicator uses the Time Frame of the Chart, so the Bars used for the calculation of VWAP 1-Day on a 1-Hour Chart would be 1-Hour Bars, not 1-Minute Bars.
You can eliminate the second scale on the Price History Pane by right-clicking on the VWAP and selecting Scaling | Scale With | Price History (otherwise it isn't being Plotted on the same Scale).
It would seem to me that you would need two versions of a 2-Day VWAP (one that resets on "odd" days and another that resets on "even" days). The "odd" version could be written as:
Static SumOHLCxV As Single
Static SumV As Single
Static Count As Integer
If isFirstBar Then
SumOHLCxV = 0
SumV = 0
Count = 0
End If
If Price.DateValue.DayOfYear <> Price.DateValue(1).DayOfYear Then
If Count Mod 2 = 1 Then
SumOHLCxV = 0
SumV = 0
End If
Count += 1
End If
SumOHLCxV += (Price.Open + Price.High + Price.Low + Price.Last) / 4 * Volume
SumV += Volume
Plot = SumOHLCxV / SumV
While the "even" version could be written as:
Static SumOHLCxV As Single
Static SumV As Single
Static Count As Integer
If isFirstBar Then
SumOHLCxV = 0
SumV = 0
Count = 0
End If
If Price.DateValue.DayOfYear <> Price.DateValue(1).DayOfYear Then
If Count Mod 2 = 0 Then
SumOHLCxV = 0
SumV = 0
End If
Count += 1
End If
SumOHLCxV += (Price.Open + Price.High + Price.Low + Price.Last) / 4 * Volume
SumV += Volume
Plot = SumOHLCxV / SumV
-Bruce Personal Criteria Formulas TC2000 Support Articles
|
|
Guest-1 |