Пример #1
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);
            }
        }
Пример #2
0
        private void WMAPeriod_ValueChanged(object sender, EventArgs e)
        {
            if (WMAPeriod.Value == 0)
            {
                chart.ClearWMA();
            }

            if (WMAPeriod.Value > 0)
            {
                if (selectedPair == null)
                {
                    MessageBox.Show("Pair is not selected.");
                }
                else if (WMAPeriod.Value > selectedPair.DeltaValues.Count())
                {
                    MessageBox.Show("maximum value = " + selectedPair.DeltaValues.Count());
                }
                else
                {
                    double[] sma = MovingAverages.WMA(selectedPair.DeltaValues.ToArray(), (int)WMAPeriod.Value);
                    chart.SetWMA(sma, (int)WMAPeriod.Value);
                }
            }
        }