예제 #1
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);
                }
            }
        }
예제 #2
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]);
            }
        }
예제 #3
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);
            }
        }
예제 #4
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;
            }
        }