Ejemplo n.º 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());
                }
            }
        }
Ejemplo n.º 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());
                }
            }
        }