BollingerBands code needed

Created at 09 Sep 2013, 21:37
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!
IR

iRobot

Joined 17.02.2013

BollingerBands code needed
09 Sep 2013, 21:37


Hi,

could you provide full code of BollingerBands indicator?

Thanks.


@iRobot
Replies

cAlgo_Fanatic
10 Sep 2013, 12:36

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

namespace cAlgo.Indicators
{
    [Indicator("Bollinger Bands", ScalePrecision = 2, IsOverlay = true)]
    public class Bollinger_Bands : Indicator
    {
        private MovingAverage _movingAverage;
        private StandardDeviation _standardDeviation;

        [Parameter]
        public DataSeries Source { get; set; }

        [Parameter(DefaultValue = 20)]
        public int Periods { get; set; }

        [Parameter("Standard Dev", DefaultValue = 2.0, MinValue = 0.0001, MaxValue = 10)]
        public double StandardDeviations { get; set; }

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

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

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

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


        protected override void Initialize()
        {
            _movingAverage = Indicators.MovingAverage(Source, Periods, MAType);
            _standardDeviation = Indicators.StandardDeviation(Source, Periods, MAType);
        }

        public override void Calculate(int index)
        {
            var shift = _standardDeviation.Result[index] * StandardDeviations;

            Main[index] = _movingAverage.Result[index];
            Bottom[index] = _movingAverage.Result[index] - shift;
            Top[index] = _movingAverage.Result[index] + shift;
        }
    }
}

 


@cAlgo_Fanatic