#TOS Indicators - Home of the Volatility Box #Full YouTube Tutorial: https://youtu.be/mAPEodczf-k # #**10/6/19 - Feature Added: Ability for Users to Set Custom Standard Deviation in Label Output declare lower; input anchorDate = 20180901; input devStop = {default One, Two, Three, Zero, NegOne, NegTwo, NegThree, Custom}; input customDev = 0.15; def chosenDev; switch(devStop){ case One: chosenDev = 1; case Two: chosenDev = 2; case Three: chosenDev = 3; case Zero: chosenDev = 0; case NegOne: chosenDev = -1; case NegTwo: chosenDev = -2; case NegThree: chosenDev = -3; case Custom: chosenDev = customDev; } def postAnchorDate = if GetYYYYMMDD() >= anchorDate then 1 else 0; def yyyyMmDd = getYyyyMmDd(); def periodIndx = if getAggregationPeriod() < AggregationPeriod.HOUR then yyyyMMDD else postAnchorDate; def isPeriodRolled = compoundValue(1, periodIndx != periodIndx[1], yes); def volumeSum; def volumeVwapSum; def volumeVwap2Sum; if (isPeriodRolled) { volumeSum = volume; volumeVwapSum = volume * vwap; volumeVwap2Sum = volume * Sqr(vwap); } else { volumeSum = compoundValue(1, volumeSum[1] + volume, volume); volumeVwapSum = compoundValue(1, volumeVwapSum[1] + volume * vwap, volume * vwap); volumeVwap2Sum = compoundValue(1, volumeVwap2Sum[1] + volume * Sqr(vwap), volume * Sqr(vwap)); } def price = volumeVwapSum / volumeSum; def deviation = Sqrt(Max(volumeVwap2Sum / volumeSum - Sqr(price), 0)); def VScore = if (((price - close)*(-1))/deviation) > 5 or (((price - close)*(-1))/deviation) < -5 then 0 else (((price - close)*(-1))/(deviation)); plot scan = VScore[1] < 0 and VScore > 0;