WebEx Study presentation, Starting at 17 Minutes into the presentation (link)
###########################################################
#
# Bollinger Band Percentage B
# This study plots the relative percentage that the price tracked has moved from the upper band to the lower band.
# hint AverageType: The type of average used in the Bollinger Band calculation. (Default is SMA)
# hint price: The price used to calculate the Bollinger Band. (Default is CLOSE)
# hint displace: Displacement the number of bars that the Bollinger Band is shifted left or right. (Default is 0)
# hint length: The number of bars used to calculate the average. (Default is 20)
# hint Num_Dev_Dn: The number of deviations below the average to plot the lower Bollinger band. (Default is -2.0)
# hint Num_Dev_Up: The number of deviations above the average to plot the upper Bollinger band. (Default is 2.0)
#
#########################################################
declare lower;
input AverageType = {default SMA, EMA};
input price = close;
input displace = 0;
input length = 5;
input Num_Dev_Dn = -1.0;
input Num_Dev_up = 1.0;
def upperBand;
def lowerBand;
switch (AverageType) {
case SMA:
upperBand = BollingerBandsSMA(price, displace, length, Num_Dev_Dn, Num_Dev_up).UpperBand;
lowerBand = BollingerBandsSMA(price, displace, length, Num_Dev_Dn, Num_Dev_up).LowerBand;
case EMA:
upperBand = BollingerBandsEMA(price, displace, length, Num_Dev_Dn, Num_Dev_up).UpperBand;
lowerBand = BollingerBandsEMA(price, displace, length, Num_Dev_Dn, Num_Dev_up).LowerBand;
}
plot PercentB = (price - lowerBand) / (upperBand - lowerBand) * 100;
plot ZeroLine = 0;
plot HalfLine = 50;
plot UnitLine = 100;
PercentB.AssignValueColor(if PercentB > 100 then GetColor(5) else if PercentB > 0 and PercentB < 100 then GetColor(6) else GetColor(1));
PercentB.SetPaintingStrategy(PaintingStrategy.HISTOGRAM);
PercentB.SetLineWeight(5);
ZeroLine.SetDefaultColor(GetColor(8));
HalfLine.SetDefaultColor(GetColor(8));
UnitLine.SetDefaultColor(GetColor(8));