Ejemplo n.º 1
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());
                }
            }
        }
Ejemplo n.º 2
0
        protected override decimal Calculate(int index)
        {
            decimal MinRsiValue = _minRsi.GetValue(index);

            return(_rsi.GetValue(index).Minus(MinRsiValue)
                   .DividedBy(_maxRsi.GetValue(index).Minus(MinRsiValue)));
        }
Ejemplo n.º 3
0
        public void highestValueUsingTimeFrame5UsingClosePrice()
        {
            HighestValueIndicator highestValue = new HighestValueIndicator(new ClosePriceIndicator(data), 5);

            Assert.AreEqual(highestValue.GetValue(4), 4M);
            Assert.AreEqual(highestValue.GetValue(5), 4M);
            Assert.AreEqual(highestValue.GetValue(6), 5M);
            Assert.AreEqual(highestValue.GetValue(7), 6M);
            Assert.AreEqual(highestValue.GetValue(8), 6M);
            Assert.AreEqual(highestValue.GetValue(9), 6M);
            Assert.AreEqual(highestValue.GetValue(10), 6M);
            Assert.AreEqual(highestValue.GetValue(11), 6M);
            Assert.AreEqual(highestValue.GetValue(12), 4M);
        }
Ejemplo n.º 4
0
        public void HighestValueUsingTimeFrame5UsingClosePrice()
        {
            var highestValue = new HighestValueIndicator(new ClosePriceIndicator(_data), 5);

            TaTestsUtils.AssertDecimalEquals(highestValue.GetValue(4), "4");
            TaTestsUtils.AssertDecimalEquals(highestValue.GetValue(5), "4");
            TaTestsUtils.AssertDecimalEquals(highestValue.GetValue(6), "5");
            TaTestsUtils.AssertDecimalEquals(highestValue.GetValue(7), "6");
            TaTestsUtils.AssertDecimalEquals(highestValue.GetValue(8), "6");
            TaTestsUtils.AssertDecimalEquals(highestValue.GetValue(9), "6");
            TaTestsUtils.AssertDecimalEquals(highestValue.GetValue(10), "6");
            TaTestsUtils.AssertDecimalEquals(highestValue.GetValue(11), "6");
            TaTestsUtils.AssertDecimalEquals(highestValue.GetValue(12), "4");
        }
Ejemplo n.º 5
0
        public override bool IsSatisfied(int index, ITradingRecord tradingRecord)
        {
            HighestValueIndicator highest = new HighestValueIndicator(_indicator, _timeFrame);
            decimal highestVal            = highest.GetValue(index);
            decimal refVal = _indicator.GetValue(index);

            bool satisfied = !refVal.IsNaN() && !highestVal.IsNaN() && refVal.Equals(highestVal);

            traceIsSatisfied(index, satisfied);
            return(satisfied);
        }
Ejemplo n.º 6
0
        protected override decimal Calculate(int index)
        {
            HighestValueIndicator highestHigh = new HighestValueIndicator(_maxPriceIndicator, _timeFrame);
            LowestValueIndicator  lowestMin   = new LowestValueIndicator(_minPriceIndicator, _timeFrame);

            decimal highestHighPrice = highestHigh.GetValue(index);
            decimal lowestLowPrice   = lowestMin.GetValue(index);

            return(_indicator.GetValue(index).Minus(lowestLowPrice)
                   .DividedBy(highestHighPrice.Minus(lowestLowPrice))
                   .MultipliedBy(Decimals.HUNDRED));
        }
Ejemplo n.º 7
0
        protected override decimal Calculate(int index)
        {
            int     startIndex           = Math.Max(0, index - _timeFrame + 1);
            int     numberOfObservations = index - startIndex + 1;
            decimal squaredAverage       = Decimals.Zero;

            for (int i = startIndex; i <= index; i++)
            {
                decimal currentValue       = _indicator.GetValue(i);
                decimal highestValue       = _highestValueInd.GetValue(i);
                decimal percentageDrawdown = currentValue.Minus(highestValue).DividedBy(highestValue).MultipliedBy(Decimals.HUNDRED);
                squaredAverage = squaredAverage.Plus(percentageDrawdown.Pow(2));
            }
            squaredAverage = squaredAverage.DividedBy(numberOfObservations);
            return(squaredAverage.Sqrt());
        }
Ejemplo n.º 8
0
        protected override Decimal Calculate(int index)
        {
            var startIndex           = Math.Max(0, index - _timeFrame + 1);
            var numberOfObservations = index - startIndex + 1;
            var squaredAverage       = Decimal.Zero;

            for (var i = startIndex; i <= index; i++)
            {
                var currentValue       = _indicator.GetValue(i);
                var highestValue       = _highestValueInd.GetValue(i);
                var percentageDrawdown = currentValue.Minus(highestValue).DividedBy(highestValue).MultipliedBy(Decimal.Hundred);
                squaredAverage = squaredAverage.Plus(percentageDrawdown.Pow(2));
            }
            squaredAverage = squaredAverage.DividedBy(Decimal.ValueOf(numberOfObservations));
            return(squaredAverage.Sqrt());
        }
Ejemplo n.º 9
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);
            HighestValueIndicator highestValue = new HighestValueIndicator(new ClosePriceIndicator(series), 5);

            for (int i = series.GetBeginIndex(); i <= series.GetEndIndex(); i++)
            {
                Assert.AreEqual(Decimals.NaN.ToString(), highestValue.GetValue(i).ToString());
            }
        }
Ejemplo n.º 10
0
        protected override Decimal Calculate(int index)
        {
            var realTimeFrame = Math.Min(_timeFrame, index + 1);

            // Getting the number of ticks since the highest close price
            var endIndex = index - realTimeFrame;
            var nbTicks  = 0;

            for (var i = index; i > endIndex; i--)
            {
                if (_closePriceIndicator.GetValue(i).IsEqual(_highestClosePriceIndicator.GetValue(index)))
                {
                    break;
                }
                nbTicks++;
            }

            return(Decimal.ValueOf(realTimeFrame - nbTicks).DividedBy(Decimal.ValueOf(realTimeFrame)).MultipliedBy(Decimal.Hundred));
        }
Ejemplo n.º 11
0
        protected override decimal Calculate(int index)
        {
            if (TimeSeries.GetBar(index).MaxPrice.IsNaN())
            {
                return(Decimals.NaN);
            }

            // Getting the number of bars since the highest close price
            int endIndex = Math.Max(0, index - _timeFrame);
            int nbBars   = 0;

            for (int i = index; i > endIndex; i--)
            {
                if (_maxValueIndicator.GetValue(i).Equals(_highestMaxPriceIndicator.GetValue(index)))
                {
                    break;
                }
                nbBars++;
            }

            return(((decimal)(_timeFrame - nbBars)).DividedBy(_timeFrame).MultipliedBy(Decimals.HUNDRED));
        }
Ejemplo n.º 12
0
 protected override decimal Calculate(int index)
 {
     return(_high.GetValue(index).Minus(_atr.GetValue(index).MultipliedBy(_k)));
 }
Ejemplo n.º 13
0
        public void highestValueIndicatorWhenTimeFrameIsGreaterThanIndex()
        {
            HighestValueIndicator highestValue = new HighestValueIndicator(new ClosePriceIndicator(data), 500);

            Assert.AreEqual(highestValue.GetValue(12), 6M);
        }
Ejemplo n.º 14
0
        public void firstHighestValueIndicatorValueShouldBeEqualsToFirstDataValue()
        {
            HighestValueIndicator highestValue = new HighestValueIndicator(new ClosePriceIndicator(data), 5);

            Assert.AreEqual(highestValue.GetValue(0), 1M);
        }
Ejemplo n.º 15
0
        public void HighestValueIndicatorWhenTimeFrameIsGreaterThanIndex()
        {
            var highestValue = new HighestValueIndicator(new ClosePriceIndicator(_data), 500);

            TaTestsUtils.AssertDecimalEquals(highestValue.GetValue(12), "6");
        }
Ejemplo n.º 16
0
        public void FirstHighestValueIndicatorValueShouldBeEqualsToFirstDataValue()
        {
            var highestValue = new HighestValueIndicator(new ClosePriceIndicator(_data), 5);

            TaTestsUtils.AssertDecimalEquals(highestValue.GetValue(0), "1");
        }