/// <summary> /// Initializes a new instance of the BollingerBands class /// </summary> /// <param name="name">The name of this indicator</param> /// <param name="period">The period of the standard deviation and moving average (middle band)</param> /// <param name="k">The number of standard deviations specifying the distance between the middle band and upper or lower bands</param> /// <param name="movingAverageType">The type of moving average to be used</param> public BollingerBands(string name, int period, double k, MovingAverageType movingAverageType = MovingAverageType.Simple) : base(name) { WarmUpPeriod = period; MovingAverageType = movingAverageType; StandardDeviation = new StandardDeviation(name + "_StandardDeviation", period); MiddleBand = movingAverageType.AsIndicator(name + "_MiddleBand", period); LowerBand = MiddleBand.Minus(StandardDeviation.Times(k), name + "_LowerBand"); UpperBand = MiddleBand.Plus(StandardDeviation.Times(k), name + "_UpperBand"); }
/// <summary> /// Initializes a new instance of the BollingerBands class /// </summary> /// <param name="name">The name of this indicator</param> /// <param name="period">The period of the standard deviation and moving average (middle band)</param> /// <param name="k">The number of standard deviations specifying the distance between the middle band and upper or lower bands</param> /// <param name="movingAverageType">The type of moving average to be used</param> public BollingerBands(string name, int period, decimal k, MovingAverageType movingAverageType = MovingAverageType.Simple) : base(name) { WarmUpPeriod = period; MovingAverageType = movingAverageType; StandardDeviation = new StandardDeviation(name + "_StandardDeviation", period); MiddleBand = movingAverageType.AsIndicator(name + "_MiddleBand", period); LowerBand = MiddleBand.Minus(StandardDeviation.Times(k), name + "_LowerBand"); UpperBand = MiddleBand.Plus(StandardDeviation.Times(k), name + "_UpperBand"); var UpperMinusLower = UpperBand.Minus(LowerBand); BandWidth = UpperMinusLower .Over(MiddleBand) .Times(new ConstantIndicator <IndicatorDataPoint>("ct", 100m), name + "_BandWidth"); Price = new Identity(name + "_Close"); PercentB = IndicatorExtensions.Over( Price.Minus(LowerBand), UpperMinusLower, name + "_%B"); }