Bollinger Bands Width free

by modarkat in category Volatility at 17/02/2014

Bollinger Bands Width is a technical analysis indicator derived from the standard Bollinger Bands indicator. Bollinger Bands are a volatility indicator which creates a band of three lines which are plotted in relation to a security's price. The Middle Line is typically a 20 Day Simple Moving Average. The Upper and Lower Bands are typically 2 standard deviations above and below the SMA (Middle Line). Bollinger Bands Width serve as a way to quantitatively measure the width between the Upper and Lower Bands. BBW can be used to identify trading signals in some instances.

John Bollinger, introduced Bollinger Bands Width in 2010 almost 3 decades after the introduction of his Bollinger Bands.

Notification Publishing copyrighted material is strictly prohibited. If you believe there is copyrighted material in this section you may use the Copyright Infringement Notification form to submit a claim.
Formula / Source Code
Language: C#
Trading Platform: cAlgocTrader
using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
    [Indicator(IsOverlay = false, ScalePrecision = 5, AccessRights = AccessRights.None)]
    public class BollingerBandsWidth : Indicator
        [Parameter("Period", DefaultValue = 20)]
        public int Period { get; set; }

        [Parameter("SD Weight Coef", DefaultValue = 2)]
        public int K { get; set; }

        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MaType { get; set; }

        public DataSeries Source { get; set; }

        private BollingerBands _bollingerBands;

        public IndicatorDataSeries Diff { get; set; }

        protected override void Initialize()
            _bollingerBands = Indicators.BollingerBands(Source, Period, K, MaType);

        public override void Calculate(int index)
            Diff[index] = (_bollingerBands.Top[index] - _bollingerBands.Bottom[index]) / _bollingerBands.Main[index];

trader_ak - February 28, 2014 @ 22:48

Well done, thank you. :)


sohoj - January 02, 2015 @ 13:09

Is it possible to plot the this indicator as histogram instead of lines.Please do this. 


Thanks in advance.

sohoj - January 02, 2015 @ 13:27

Here is modified code.Coding seems easy in Calgo

Language: C#
Trading Platform: cAlgocTrader

using cAlgo.API;
using cAlgo.API.Indicators;

namespace cAlgo.Indicators
    [Indicator(IsOverlay = falseScalePrecision = 5, AccessRights = AccessRights.None)]
    public class BollingerBandsWidth : Indicator
        [Parameter("Period", DefaultValue = 20)]
        public int Period get; set; }

        [Parameter("SD Weight Coef", DefaultValue = 2)]
        public int K get; set; }

        [Parameter("MA Type", DefaultValue = MovingAverageType.Simple)]
        public MovingAverageType MaType get; set; }

        public DataSeries Source get; set; }

        private BollingerBands _bollingerBands;

        [Output("diff", PlotType = PlotType.Histogram)]
        public IndicatorDataSeries Diff get; set; }

        protected override void Initialize()
            _bollingerBands = Indicators.BollingerBands(Source, Period, K, MaType);

        public override void Calculate(int index)
            Diff[index] = (_bollingerBands.Top[index] - _bollingerBands.Bottom[index]) / _bollingerBands.Main[index];

firemyst - May 27, 2019 @ 03:36

Why do you divide by Main[index]?

Subtracting the bottom from the top alone will provide you with the width. Or subtracting the bottom from the top and dividing by 2. 

Thank you.