Пример #1
0
        public void naNValuesInIntervall()
        {
            List <IBar> bars = new List <IBar>();

            for (long i = 0; i <= 10; i++)
            { // (NaN, 1, NaN, 2, NaN, 3, NaN, 4, ...)
                decimal closePrice = i % 2 == 0 ? i : Decimals.NaN;
                IBar    bar        = new BaseBar(DateTime.Now.AddDays(i), Decimals.NaN, Decimals.NaN, Decimals.NaN, Decimals.NaN, Decimals.NaN);
                bars.Add(bar);
            }

            BaseTimeSeries       series      = new BaseTimeSeries("NaN test", bars);
            LowestValueIndicator lowestValue = new LowestValueIndicator(new ClosePriceIndicator(series), 2);

            for (int i = series.GetBeginIndex(); i <= series.GetEndIndex(); i++)
            {
                if (i % 2 != 0)
                {
                    Assert.AreEqual(series.GetBar(i - 1).ClosePrice.ToString(), lowestValue.GetValue(i).ToString());
                }
                else
                {
                    Assert.AreEqual(series.GetBar(Math.Max(0, i - 1)).ClosePrice.ToString(), lowestValue.GetValue(i).ToString());
                }
            }
        }
Пример #2
0
        public void naNValuesInIntervall()
        {
            List <IBar> bars = new List <IBar>();

            for (long i = 0; i <= 10; i++)
            { // (0, NaN, 2, NaN, 3, NaN, 4, NaN, 5, ...)
                decimal closePrice = i % 2 == 0 ? i : Decimals.NaN;
                IBar    bar        = new BaseBar(DateTime.Now.AddDays(i), Decimals.NaN, Decimals.NaN, Decimals.NaN, closePrice, Decimals.NaN);
                bars.Add(bar);
            }

            BaseTimeSeries        series       = new BaseTimeSeries("NaN test", bars);
            HighestValueIndicator highestValue = new HighestValueIndicator(new ClosePriceIndicator(series), 2);

            // index is the biggest of (index, index-1)
            for (int i = series.GetBeginIndex(); i <= series.GetEndIndex(); i++)
            {
                if (i % 2 != 0) // current is NaN take the previous as highest
                {
                    Assert.AreEqual(series.GetBar(i - 1).ClosePrice.ToString(), highestValue.GetValue(i).ToString());
                }
                else // current is not NaN but previous, take the current
                {
                    Assert.AreEqual(series.GetBar(i).ClosePrice.ToString(), highestValue.GetValue(i).ToString());
                }
            }
        }
Пример #3
0
        public void naNValuesInIntervall()
        {
            List <IBar> bars = new List <IBar>();

            for (long i = 0; i <= 10; i++)
            { // (0, NaN, 2, NaN, 4, NaN, 6, NaN, 8, ...)
                decimal maxPrice = i % 2 == 0 ? i : Decimals.NaN;
                IBar    bar      = new BaseBar(DateTime.Now.AddDays(i), Decimals.NaN, maxPrice, Decimals.NaN, Decimals.NaN, Decimals.NaN);
                bars.Add(bar);
            }
            BaseTimeSeries   series           = new BaseTimeSeries("NaN test", bars);
            AroonUpIndicator aroonUpIndicator = new AroonUpIndicator(series, 5);

            for (int i = series.GetBeginIndex(); i <= series.GetEndIndex(); i++)
            {
                if (i % 2 != 0)
                {
                    Assert.AreEqual(Decimals.NaN, aroonUpIndicator.GetValue(i));
                }
                else
                {
                    Assert.AreEqual(Decimals.HUNDRED, aroonUpIndicator.GetValue(i));
                }
            }
        }
Пример #4
0
        public void naNValuesInIntervall()
        {
            List <IBar> bars = new List <IBar>();

            for (long i = 10; i >= 0; i--)
            { // (10, NaN, 9, NaN, 8, NaN, 7, NaN)
                decimal minPrice = i % 2 == 0 ? i : Decimals.NaN;
                IBar    bar      = new BaseBar(DateTime.Now.AddDays(10 - i), Decimals.NaN, Decimals.NaN, minPrice, Decimals.NaN, Decimals.NaN);
                bars.Add(bar);
            }
            bars.Add(new BaseBar(DateTime.Now.AddDays(11), Decimals.NaN, Decimals.NaN, Decimals.TEN, Decimals.NaN, Decimals.NaN));
            BaseTimeSeries     series             = new BaseTimeSeries("NaN test", bars);
            AroonDownIndicator aroonDownIndicator = new AroonDownIndicator(series, 5);

            for (int i = series.GetBeginIndex(); i <= series.GetEndIndex(); i++)
            {
                if (i % 2 != 0 && i < 11)
                {
                    Assert.AreEqual(Decimals.NaN.ToString(), aroonDownIndicator.GetValue(i).ToString());
                }
                else if (i < 11)
                {
                    Assert.AreEqual(aroonDownIndicator.GetValue(i), Decimals.HUNDRED);
                }
                else
                {
                    Assert.AreEqual(aroonDownIndicator.GetValue(i), 80);
                }
            }
        }
Пример #5
0
        public void onlyNaNValues()
        {
            List <IBar> bars = new List <IBar>();

            for (long i = 0; i <= 10000; i++)
            {
                IBar bar = new BaseBar(DateTime.Now.AddDays(i), Decimals.NaN, Decimals.NaN, Decimals.NaN, Decimals.NaN, Decimals.NaN);
                bars.Add(bar);
            }

            BaseTimeSeries       series      = new BaseTimeSeries("NaN test", bars);
            LowestValueIndicator lowestValue = new LowestValueIndicator(new ClosePriceIndicator(series), 5);

            for (int i = series.GetBeginIndex(); i <= series.GetEndIndex(); i++)
            {
                Assert.AreEqual(Decimals.NaN.ToString(), lowestValue.GetValue(i).ToString());
            }
        }