2-3 Day VWAP

Viewing 2 posts - 1 through 2 (of 2 total)
  • Author
    Posts
  • #238349 quote
    trwcapital
    Participant
    New

    Anyone have a good solution for a rolling 2 and 3 day vwap that properly ignores non-trading days? If I use the standard PRT VWAP and set it to 2 days, nothing shows up on monday on stocks and ETFs that don’t trade on the weekends.  I thought about using a 5 day anchored vwap on mondays but the switching back and forth really doesn’t appeal to me.

    #238366 quote
    Iván González
    Moderator
    Master

    Maybe this code can give you an idea:

    //PRC Rolling VWAP
    //version = 0
    //06.03.24
    //Iván González @ www.prorealcode.com
    //Sharing ProRealTime knowledge
    ///inputs
    src = customclose
    minBarsInput = 10
    stdevMult1 = 1
    stdevMult2 = 1.5
    stdevMult3 = 2.5
    showbands = 1
    
    //////BARS TO CALCULATE VWAP/////////
    if gettimeframe < 86400 then
    bars = minbarsinput
    elsif gettimeframe >= 86400 and gettimeframe < 604800 then
    bars = MAX(22,minbarsinput)
    elsif gettimeframe = 604800 then
    bars = MAX(round(90/5),minbarsinput)
    else
    bars = MAX(round(252/22),minbarsinput)
    endif
    //////////////////////////////////////
    
    sumSrcVol = summation[bars](src*volume)
    sumVol = summation[bars](volume)
    sumSrcSrcVol = summation[bars](pow(src,2)*volume)
    
    rollingvwap = sumSrcVol / SumVol
    
    variance = sumSrcSrcVol / SumVol - pow(rollingvwap,2)
    variance = max(0,variance)
    
    stDev = sqrt(variance)
    
    if showbands then
    upperband1 = rollingVwap + stDev*stdevMult1
    lowerband1 = rollingVwap - stDev*stdevMult1
    
    upperband2 = rollingVwap + stDev*stdevMult2
    lowerband2 = rollingVwap - stDev*stdevMult2
    
    upperband3 = rollingVwap + stDev*stdevMult3
    lowerband3 = rollingVwap - stDev*stdevMult3
    else
    upperband1 = undefined
    lowerband1 = undefined
    upperband2 = undefined
    lowerband2 = undefined
    upperband3 = undefined
    lowerband3 = undefined
    endif
    
    return rollingvwap as "rollingVwap" coloured("orange"),upperband1 as "upperband1"coloured("red"),lowerband1 as "lowerband1"coloured("red"),upperband2 as "upperband2"coloured("yellow"),lowerband2 as "lowerband2"coloured("yellow"),upperband3 as "upperband3"coloured("green"),lowerband3 as "lowerband3"coloured("green")
    
    trwcapital thanked this post
Viewing 2 posts - 1 through 2 (of 2 total)
  • You must be logged in to reply to this topic.

2-3 Day VWAP


ProBuilder: Indicators & Custom Tools

New Reply
Author
author-avatar
trwcapital @trwcapital Participant
Summary

This topic contains 1 reply,
has 2 voices, and was last updated by Iván González
1 year, 4 months ago.

Topic Details
Forum: ProBuilder: Indicators & Custom Tools
Language: English
Started: 10/01/2024
Status: Active
Attachments: No files
Logo Logo
Loading...