public void TimesMultipliesLeftAndConstant_Py() { using (Py.GIL()) { var left = new Identity("left"); var composite = (IIndicator)IndicatorExtensions.Times(left.ToPython(), 5); left.Update(DateTime.Today, 10); Assert.AreEqual(50, composite.Current.Value); left.Update(DateTime.Today, 20); Assert.AreEqual(100, composite.Current.Value); } }
public void PlusAddsLeftAndConstant_Py() { using (Py.GIL()) { var left = new Identity("left"); var composite = (IIndicator)IndicatorExtensions.Plus(left.ToPython(), 10); left.Update(DateTime.Today, 1); Assert.AreEqual(11, composite.Current.Value); left.Update(DateTime.Today, 2); Assert.AreEqual(12, composite.Current.Value); } }
public void MinusSubstractsLeftAndRight_Py() { using (Py.GIL()) { var left = new Identity("left"); var right = new Identity("right"); var composite = (IIndicator)IndicatorExtensions.Minus(left.ToPython(), right.ToPython()); left.Update(DateTime.Today, 10); right.Update(DateTime.Today, 10); Assert.AreEqual(0, composite.Current.Value); left.Update(DateTime.Today, 20); Assert.AreEqual(0, composite.Current.Value); } }
/// <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"); }