Пример #1
0
        /// <param name="series"> a time series </param>
        /// <returns> a global extrema strategy </returns>
        public static Strategy BuildStrategy(TimeSeries series)
        {
            if (series == null)
            {
                throw new ArgumentException("Series cannot be null");
            }

            var closePrices = new ClosePriceIndicator(series);

            // Getting the max price over the past week
            var maxPrices    = new MaxPriceIndicator(series);
            var weekMaxPrice = new HighestValueIndicator(maxPrices, NB_TICKS_PER_WEEK);
            // Getting the min price over the past week
            var minPrices    = new MinPriceIndicator(series);
            var weekMinPrice = new LowestValueIndicator(minPrices, NB_TICKS_PER_WEEK);

            // Going long if the close price goes below the min price
            var downWeek   = new MultiplierIndicator(weekMinPrice, Decimal.ValueOf("1.004"));
            var buyingRule = new UnderIndicatorRule(closePrices, downWeek);

            // Going short if the close price goes above the max price
            var upWeek      = new MultiplierIndicator(weekMaxPrice, Decimal.ValueOf("0.996"));
            var sellingRule = new OverIndicatorRule(closePrices, upWeek);

            return(new Strategy(buyingRule, sellingRule));
        }
Пример #2
0
 /**
  * Constructor.
  * @param indicator the indicator
  * @param timeFrame the time frame
  */
 public UlcerIndexIndicator(IIndicator <decimal> indicator, int timeFrame)
     : base(indicator)
 {
     _indicator       = indicator;
     _timeFrame       = timeFrame;
     _highestValueInd = new HighestValueIndicator(indicator, timeFrame);
 }
Пример #3
0
 /**
  * Constructor.
  * @param rsi the rsi indicator
  * @param timeFrame the time frame
  */
 public StochasticRSIIndicator(RSIIndicator rsi, int timeFrame)
     : base(rsi)
 {
     _rsi    = rsi;
     _minRsi = new LowestValueIndicator(rsi, timeFrame);
     _maxRsi = new HighestValueIndicator(rsi, timeFrame);
 }
 /**
  * Constructor.
  * @param series the time series
  * @param timeFrame the time frame (usually 22)
  * @param k the K multiplier for ATR (usually 3.0)
  */
 public ChandelierExitLongIndicator(ITimeSeries series, int timeFrame, decimal k)
     : base(series)
 {
     _high = new HighestValueIndicator(new MaxPriceIndicator(series), timeFrame);
     _atr  = new ATRIndicator(series, timeFrame);
     _k    = k;
 }
Пример #5
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());
                }
            }
        }
Пример #6
0
        /**
         * Constructor.
         * <p>
         * @param series the time series
         * @param MaxValueIndicator the indicator for the Maximum price ( {@link MaxPriceIndicator})
         * @param timeFrame the time frame
         */
        public AroonUpIndicator(ITimeSeries series, IIndicator <decimal> maxValueIndicator, int timeFrame)
            : base(series)
        {
            _timeFrame         = timeFrame;
            _maxValueIndicator = maxValueIndicator;

            // + 1 needed for last possible iteration in loop
            _highestMaxPriceIndicator = new HighestValueIndicator(maxValueIndicator, timeFrame + 1);
        }
Пример #7
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);
        }
Пример #8
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));
        }
Пример #9
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);
        }
Пример #10
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");
        }
Пример #11
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());
            }
        }
Пример #12
0
 public AroonUpIndicator(TimeSeries series, int timeFrame) : base(series)
 {
     _timeFrame                  = timeFrame;
     _closePriceIndicator        = new ClosePriceIndicator(series);
     _highestClosePriceIndicator = new HighestValueIndicator(_closePriceIndicator, timeFrame);
 }
Пример #13
0
        public void highestValueIndicatorWhenTimeFrameIsGreaterThanIndex()
        {
            HighestValueIndicator highestValue = new HighestValueIndicator(new ClosePriceIndicator(data), 500);

            Assert.AreEqual(highestValue.GetValue(12), 6M);
        }
Пример #14
0
        public void firstHighestValueIndicatorValueShouldBeEqualsToFirstDataValue()
        {
            HighestValueIndicator highestValue = new HighestValueIndicator(new ClosePriceIndicator(data), 5);

            Assert.AreEqual(highestValue.GetValue(0), 1M);
        }
Пример #15
0
        public void HighestValueIndicatorWhenTimeFrameIsGreaterThanIndex()
        {
            var highestValue = new HighestValueIndicator(new ClosePriceIndicator(_data), 500);

            TaTestsUtils.AssertDecimalEquals(highestValue.GetValue(12), "6");
        }
Пример #16
0
        public void FirstHighestValueIndicatorValueShouldBeEqualsToFirstDataValue()
        {
            var highestValue = new HighestValueIndicator(new ClosePriceIndicator(_data), 5);

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