/// <summary>
 /// Initializes a new instance of the
 /// <see cref="T:ObjectiveTA.Objects.Output.MovingAverageConvergenceDivergence"/> class.
 /// </summary>
 /// <param name="macd">Macd.</param>
 /// <param name="length">Length.</param>
 public MovingAverageConvergenceDivergence(double[] macd, int length)
 {
     this.length    = length;
     MACD           = macd;
     macdSignalLine = MovingAverages.EMA(macd, length).MA;
     macdHistogram  = SubtractArray(MACD, MACDSignalLine);
 }
Exemplo n.º 2
0
        private void SMAPeriod_ValueChanged(object sender, EventArgs e)
        {
            if (SMAPeriod.Value == 0)
            {
                chart.ClearSMA();
            }

            if (SMAPeriod.Value > 0)
            {
                if (selectedPair == null)
                {
                    MessageBox.Show("Pair is not selected.");
                }
                else if (SMAPeriod.Value > selectedPair.DeltaValues.Count())
                {
                    MessageBox.Show("maximum value = " + selectedPair.DeltaValues.Count());
                }
                else
                {
                    chart.SetSMA(
                        MovingAverages.SMA(selectedPair.DeltaValues.ToArray(), (int)SMAPeriod.Value),
                        (int)SMAPeriod.Value);
                }
            }
        }
Exemplo n.º 3
0
        public void WMATest()
        {
            decimal[] values = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 1, 2, 3, 4, 5 };

            try
            {
                var smaResult = MovingAverages.WMA(values, 0);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("period <= 0", ex.Message);
            }


            try
            {
                var result = MovingAverages.WMA(values, values.Length + 1);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("period > values.Lenght", ex.Message);
            }


            var wma3Result = MovingAverages.WMA(values, 3);

            double[] expectedValues = { 2.33, 3.33, 4.33, 5.33, 6.33, 7.33, 8.33, 4.83, 2.83, 2.33, 3.33, 4.33 };

            Assert.AreEqual(expectedValues.Length, wma3Result.Length);

            for (int i = 0; i < wma3Result.Length; i++)
            {
                Assert.AreEqual(expectedValues[i], (double)wma3Result[i], 0.01);
            }
        }
Exemplo n.º 4
0
        public void SMATest()
        {
            decimal[] values = { 1, 3, 5, 7, 9, 2, 4, 6, 8, 11, 13, 15, 24, 46, 68 };

            try
            {
                var smaResult = MovingAverages.SMA(values, 0);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("period <= 0", ex.Message);
            }


            try
            {
                var result = MovingAverages.SMA(values, values.Length + 1);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("period > values.Lenght", ex.Message);
            }


            var sma5Result = MovingAverages.SMA(values, 5);

            decimal[] expectedValues = { 5, 5.2M, 5.4M, 5.6M, 5.8M, 6.2M, 8.4M, 10.6M, 14.2M, 21.8M, 33.2M };

            Assert.AreEqual(expectedValues.Length, sma5Result.Length);

            for (int i = 0; i < expectedValues.Length; i++)
            {
                Assert.AreEqual(expectedValues[i], sma5Result[i]);
            }
        }
Exemplo n.º 5
0
        public void Update(double[] values, string title, int SMAPeriod = 0)
        {
            PlotModel.Title = title;

            PlotModel.Series.Clear();

            AddLineSerie("Δ", OxyColor.Parse("#3399ff"), values, 0);

            if (SMAPeriod > 0 && SMAPeriod < values.Length)
            {
                var SMAValues = MovingAverages.SMA(values, SMAPeriod);
                AddLineSerie("SMA", OxyColor.Parse("#FF0000"), SMAValues, SMAPeriod);
            }
        }
Exemplo n.º 6
0
        public void VMATest()
        {
            decimal[] values  = { 11, 15, 19, 13, 14, 16, 23, 25, 29, 26, 35, 45 };
            long[]    volumes = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12 };

            Assert.AreEqual(true, values.Length == volumes.Length);

            try
            {
                var smaResult = MovingAverages.VMA(values, volumes, 0);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("period <= 0", ex.Message);
            }


            try
            {
                var smaResult = MovingAverages.VMA(values, new long[] { 1, 3, 5 }, -1);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("values.Length != volumes.Length", ex.Message);
            }


            try
            {
                var result = MovingAverages.VMA(values, volumes, values.Length + 1);
            }
            catch (ArgumentException ex)
            {
                Assert.AreEqual("period > values.Lenght", ex.Message);
            }


            var sresult = MovingAverages.VMA(values, volumes, 4);

            double[] expectedValues = { 15, 14.9285, 15.2777, 17.2272, 20.2692, 23.9333, 25.9411, 29.1052, 34.4285 };

            Assert.AreEqual(expectedValues.Length, sresult.Length);

            for (int i = 0; i < expectedValues.Length; i++)
            {
                Assert.AreEqual(expectedValues[i], (double)sresult[i], 0.0001);
            }
        }
Exemplo n.º 7
0
        public BollingerBands(CandleStickCollection candleSticks, int period = 20,
                              double multiplier = 2, PriceSource priceSource = PriceSource.Close)
        {
            int length = candleSticks.Count - period;

            double[]          prices = priceSource.GetArrayFromCandleStickCollection(candleSticks);
            StandardDeviation standardDeviation;

            LowerBand  = UpperBand = new double[length];
            MiddleBand = MovingAverages.SMA(candleSticks, period, priceSource).MA;

            for (int i = 0; i < length; i++)
            {
                standardDeviation = new StandardDeviation(prices.GetSegment(i, i + period), MiddleBand.GetSegment(i, i + period));
                UpperBand[i]      = MiddleBand[i] + multiplier * standardDeviation.Value;
                LowerBand[i]      = MiddleBand[i] - multiplier * standardDeviation.Value;
            }
        }
Exemplo n.º 8
0
 public MovingAveragesFixture()
 {
     this.MovingAverages = new MovingAverages();
 }