Bollinger Bands code

Created at 28 Aug 2012, 13:02
How’s your experience with the cTrader Platform?
Your feedback is crucial to cTrader's development. Please take a few seconds to share your opinion and help us improve your trading experience. Thanks!
sktrader's avatar

sktrader

Joined 03.08.2012

Bollinger Bands code
28 Aug 2012, 13:02


I need some help writing the code for a strategy that uses Bollinger Bands.  How do I code something that indicates that the Bands have tightened up?


@sktrader
Replies

admin
29 Aug 2012, 10:03

Hello

You can use the following code to express that the Bollinger Bands have tightened up:

 

        [Parameter]
        public DataSeries Source { get; set; }
    
        [Parameter(DefaultValue = 20)]
        public int Period { get; set; }

        [Parameter(DefaultValue = 2.5)]
        public double bbSTD { get; set; }

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

        [Output("Main")]
        public IndicatorDataSeries Result { get; set; }

		BollingerBands bbands;

        protected override void Initialize()
        {
            bbands = Indicators.BollingerBands(Source,Period,bbSTD,MAType);
        }

        public override void Calculate(int index)
        {
			if( bbands.Top.IsFalling && bbands.Bottom.IsRising ){
				//Code Logic goes here
			}
        }




@admin