/// <summary> /// Creates a new CompositeIndicator such that the result will be the product of the left and the constant /// </summary> /// <remarks> /// value = left*constant /// </remarks> /// <param name="left">The left indicator</param> /// <param name="constant">The constant value to multiple by</param> /// <returns>The product of the left to the right indicators</returns> public static CompositeIndicator <T> Times <T>(this IndicatorBase <T> left, decimal constant) where T : IBaseData { var constantIndicator = new ConstantIndicator <T>(constant.ToString(CultureInfo.InvariantCulture), constant); return(left.Times(constantIndicator)); }
/// <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) { MovingAverageType = movingAverageType; StandardDeviation = new StandardDeviation(name + "_StandardDeviation", period); MiddleBand = movingAverageType.AsIndicator(name + "_MiddleBand", period); var kConstant = new ConstantIndicator <IndicatorDataPoint>(k.ToString(), k); LowerBand = MiddleBand.Minus(StandardDeviation.Times(kConstant), name + "_LowerBand"); UpperBand = MiddleBand.Plus(StandardDeviation.Times(kConstant), name + "_UpperBand"); }
/// <summary> /// Creates a new CompositeIndicator such that the result will be the sum of the left and the constant /// </summary> /// <remarks> /// value = left + constant /// </remarks> /// <param name="left">The left indicator</param> /// <param name="constant">The addend</param> /// <returns>The sum of the left and right indicators</returns> public static CompositeIndicator <IndicatorDataPoint> Plus(this IndicatorBase <IndicatorDataPoint> left, decimal constant) { var constantIndicator = new ConstantIndicator <IndicatorDataPoint>(constant.ToString(CultureInfo.InvariantCulture), constant); return(left.Plus(constantIndicator)); }
/// <summary> /// Creates a new CompositeIndicator such that the result will be the difference of the left and constant /// </summary> /// <remarks> /// value = left - constant /// </remarks> /// <param name="left">The left indicator</param> /// <param name="constant">The subtrahend</param> /// <returns>The difference of the left and right indicators</returns> public static CompositeIndicator Minus(this IndicatorBase left, decimal constant) { var constantIndicator = new ConstantIndicator <IBaseData>(constant.ToString(CultureInfo.InvariantCulture), constant); return(left.Minus(constantIndicator)); }