Coding formula for VWAP – share price

Viewing 13 posts - 1 through 13 (of 13 total)
  • Author
    Posts
  • #94455 quote
    Pippa Carron
    Participant
    New

    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

    SP = Close[0]
    VWAP = VWAP[0]
    Difference = ((SP-VWAP)/SP)*100
    
    Return Difference

     

    Someone elsewhere has suggested the following code for VWAP but it comes up with a syntax error also.

    VWAP = 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.

    PRTcode.png PRTcode.png
    #94467 quote
    Vonasi
    Moderator
    Master

    [attachment file=94468]

    I tidied up your post for you. 🙂

    Screenshot_1-2.png Screenshot_1-2.png
    #94470 quote
    Vonasi
    Moderator
    Master

    Type 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.

    #94474 quote
    Vonasi
    Moderator
    Master

    You can try this. Not tested:

    SP = Close
    VWAP = SUMMATION[d](volume*typicalprice)/SUMMATION[d](volume)
    Difference = ((SP-VWAP)/SP)*100
     
    Return Difference
    #94475 quote
    Pippa Carron
    Participant
    New

    Dear 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:

    SP = Close
    VWAP = SUMMATION[1](volume*typicalprice)/SUMMATION[1](volume)
    Difference = SP-VWAP
    Return Difference
    codevWAP.png codevWAP.png
    #94477 quote
    Pippa Carron
    Participant
    New

    Sorry, sorry, it is % difference between share price and VWAP that I need.  But the code still seems to be wrong. See my image.

    Screen-Shot-2019-03-23-at-7.28.51-pm.png Screen-Shot-2019-03-23-at-7.28.51-pm.png
    #94480 quote
    Vonasi
    Moderator
    Master

    I 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. 🙂

    #94482 quote
    Vonasi
    Moderator
    Master

    Try this:

    d = max(1, intradaybarindex)
    VWAP = SUMMATION[d](volume*typicalprice)/SUMMATION[d](volume)
    difference = close - vwap
    
    return difference

    It 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:

    d = 60 //set to whatever look back period in bars that you want.
    
    VWAP = SUMMATION[d](volume*typicalprice)/SUMMATION[d](volume)
    difference = close - vwap
    
    return difference
    #94483 quote
    Vonasi
    Moderator
    Master

    I 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:

    d = 60
    //d = max(1, intradaybarindex)
    
    if volume > 0 then
    VWAP = SUMMATION[d](volume*typicalprice)/SUMMATION[d](volume)
    difference = close - vwap
    endif
    
    return 0,difference
    #94531 quote
    Pippa Carron
    Participant
    New

    Hi Vonasi,

    I’ve got your code working, so thanks very much. This is what I’ve ended up using:

    d = max(1, intradaybarindex)
    VWAP = SUMMATION[d](volume*typicalprice)/SUMMATION[d](volume)
    difference = ((close - vwap)/close)*100
    
    return difference

    One 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

    Code3.png Code3.png
    #94570 quote
    Vonasi
    Moderator
    Master

    Try this – not tested – it might only round it to two decimal places and not change the displayed number of digits:

    d = max(1, intradaybarindex)
    VWAP = SUMMATION[d](volume*typicalprice)/SUMMATION[d](volume)
    difference = (round(((close - vwap)/close)*100)*100)/100
     
    return difference
    #94598 quote
    Nicolas
    Keymaster
    Master

    Seems similar to measure the normalized distance from the VWAP like this indicator of the library: Z-Score distance from VWAP

    #94758 quote
    Pippa Carron
    Participant
    New

    Thanks, 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.

Viewing 13 posts - 1 through 13 (of 13 total)
  • You must be logged in to reply to this topic.

Coding formula for VWAP – share price


ProBuilder: Indicators & Custom Tools

New Reply
Author
Summary

This topic contains 12 replies,
has 3 voices, and was last updated by Pippa Carron
6 years, 10 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 03/23/2019
Status: Active
Attachments: 5 files
Logo Logo
Loading...