//PRC_VWAP Z-score
//08.01.2019
//Nicolas @ www.prorealcode.com
//Sharing ProRealTime knowledge
// --- settings
SDminPeriod = 100 //minimal period to compute the Standard Deviation
smoothZscore = 0 //smooth the curve? (0=false ; 1=true)
// --- end of settings
d = max(2,intradaybarindex)//max(1, intradaybarindex)
if volume>0 then
if intradaybarindex=0 then
vwap = (volume*customclose)/(volume)
else
VWAP = SUMMATION[d](volume*customclose)/SUMMATION[d](volume)
endif
endif
sd = SUMMATION[max(SDminPeriod,d)](max(abs(high-vwap),abs(vwap-low)))/max(SDminPeriod,d)
if smoothZscore then
zscore=average[3]((close-vwap)/sd)
else
zscore = (close-vwap)/sd
endif
if zscore>=2 then
drawcandle(2,2.5,2,2.5) coloured(255,0,0,100) bordercolor(0,0,0,0)
endif
if zscore<=-2 then
drawcandle(-2,-2.5,-2,-2.5) coloured(0,255,0,100) bordercolor(0,0,0,0)
endif
RETURN zscore style(line,2), 1 coloured(168,168,168) style(line,2), 2 coloured(210,210,210) style(line,2), -1 coloured(168,168,168) style(line,2), -2 coloured(210,210,210) style(line,2), 0 coloured(168,168,168) style(dottedline)