Coding formula for VWAP – share price
Forums › ProRealTime English forum › ProBuilder support › Coding formula for VWAP – share price
- This topic has 12 replies, 3 voices, and was last updated 5 years ago by Pippa Carron.
Tagged: vwap
-
-
03/23/2019 at 1:27 AM #94455
I am trying to create an indicator that will give me the difference between the current share price and VWAP as a percentage. I’m using the code shown below, but it has a syntax error in line 2 and I don’t know how to fix it. I can’t get ProBuilder to give me the correct code for VWAP as it doesn’t appear in the indicator list. Any suggestions gratefully received. Thanks
12345SP = Close[0]VWAP = VWAP[0]Difference = ((SP-VWAP)/SP)*100Return DifferenceSomeone elsewhere has suggested the following code for VWAP but it comes up with a syntax error also.
1VWAP = Sum (Close[0] x Volume[0]) / Sum(Volume[0])Sorry, the instructions say to use the <> “insert PRT code” button but I can’t see where that is.
03/23/2019 at 8:01 AM #9446703/23/2019 at 8:07 AM #94470Type VWAP in the search box (found top right by hovering over your profile picture) and several VWAP indicators are already in the library. You can use the VWAP calculations found in these to easily create your indicator.
Sum and VWAP are not code words used in PRT which is why you get the error.
03/23/2019 at 8:33 AM #9447403/23/2019 at 9:05 AM #94475Dear Vonasi,
Thank you so much for your quick reply. I realise in looking at it that I really only need an indicator which gives share price minus VWAP. However, when I tried this it didn’t work. I used the code:
1234SP = CloseVWAP = SUMMATION[1](volume*typicalprice)/SUMMATION[1](volume)Difference = SP-VWAPReturn Difference03/23/2019 at 9:30 AM #94477Sorry, sorry, it is % difference between share price and VWAP that I need. But the code still seems to be wrong. See my image.
03/23/2019 at 9:34 AM #94480I cut and pasted the VWAP code from an indicator and I notice now that it is showing VWAP for the close of the previous bar.
The VWAP calculation is on the previous bar but your on price VWAP indicator is the daily VWAP on a 5 minute chart hence the difference.
I tidied up your post again. Please see my previous post with the image of where the ‘Insert PRT Code’ button is and try to remember to use it. 🙂
03/23/2019 at 9:42 AM #94482Try this:
12345d = max(1, intradaybarindex)VWAP = SUMMATION[d](volume*typicalprice)/SUMMATION[d](volume)difference = close - vwapreturn differenceIt starts measuring VWAP from the first candle of the day. If you just want a fixed number of bars for the calculation then try this:
123456d = 60 //set to whatever look back period in bars that you want.VWAP = SUMMATION[d](volume*typicalprice)/SUMMATION[d](volume)difference = close - vwapreturn difference03/23/2019 at 9:57 AM #94483I just found a minor bug due to the lack of volume history which means that when switching time frames the indicator does not work.
Here is a fix:
123456789d = 60//d = max(1, intradaybarindex)if volume > 0 thenVWAP = SUMMATION[d](volume*typicalprice)/SUMMATION[d](volume)difference = close - vwapendifreturn 0,difference03/24/2019 at 9:20 AM #94531Hi Vonasi,
I’ve got your code working, so thanks very much. This is what I’ve ended up using:
12345d = max(1, intradaybarindex)VWAP = SUMMATION[d](volume*typicalprice)/SUMMATION[d](volume)difference = ((close - vwap)/close)*100return differenceOne other question, is there any way that I can reduce the number of decimal places on the index readouts from 5 to 2 on the charts? (e.g. 0.25, rahter than 0.25467) See image.
With thanks, Pippa
03/24/2019 at 10:24 PM #94570Try this – not tested – it might only round it to two decimal places and not change the displayed number of digits:
12345d = max(1, intradaybarindex)VWAP = SUMMATION[d](volume*typicalprice)/SUMMATION[d](volume)difference = (round(((close - vwap)/close)*100)*100)/100return difference03/25/2019 at 10:16 AM #94598Seems similar to measure the normalized distance from the VWAP like this indicator of the library: Z-Score distance from VWAP
03/27/2019 at 8:27 AM #94758Thanks, no this is quite different from a Z-score concept. It is the difference between the trading price at any given time, and the VWAP number, expressed as a percent. Z-score is related to standard deviations. A completely different concept to VWAP. But thanks.
-
AuthorPosts