/// <param name="series">a time series </param>
        /// <returns> a moving momentum strategy </returns>
        public static Strategy BuildStrategy(TimeSeries series)
        {
            if (series == null)
            {
                throw new System.ArgumentException("Series cannot be null");
            }

            var closePrice = new ClosePriceIndicator(series);

            // The bias is bullish when the shorter-moving average moves above the longer moving average.
            // The bias is bearish when the shorter-moving average moves below the longer moving average.
            var shortEma = new EMAIndicator(closePrice, 9);
            var longEma  = new EMAIndicator(closePrice, 26);

            var stochasticOscillK = new StochasticOscillatorKIndicator(series, 14);

            var macd    = new MACDIndicator(closePrice, 9, 26);
            var emaMacd = new EMAIndicator(macd, 18);

            // Entry rule
            var entryRule = (new OverIndicatorRule(shortEma, longEma)).And(new CrossedDownIndicatorRule(stochasticOscillK, Decimal.ValueOf(20))).And(new OverIndicatorRule(macd, emaMacd));             // Signal 2 -  Signal 1 -  Trend

            // Exit rule
            var exitRule = (new UnderIndicatorRule(shortEma, longEma)).And(new CrossedUpIndicatorRule(stochasticOscillK, Decimal.ValueOf(80))).And(new UnderIndicatorRule(macd, emaMacd));             // Signal 2 -  Signal 1 -  Trend

            return(new Strategy(entryRule, exitRule));
        }
        public void StochasticOscilatorKParam14()
        {
            var sof = new StochasticOscillatorKIndicator(_data, 14);

            TaTestsUtils.AssertDecimalEquals(sof.GetValue(0), 313 / 3.5);
            TaTestsUtils.AssertDecimalEquals(sof.GetValue(12), 1000 / 10.81);
            TaTestsUtils.AssertDecimalEquals(sof.GetValue(13), 57.8168);
        }
        public void stochasticOscilatorKParam14()
        {
            StochasticOscillatorKIndicator sof = new StochasticOscillatorKIndicator(data, 14);

            Assert.AreEqual(sof.GetValue(0), 313M / 3.5M);
            Assert.AreEqual(sof.GetValue(12), 1000M / 10.81M);
            Assert.AreEqual(sof.GetValue(13), 57.816836262719703977798334880M);
        }
Exemple #4
0
        public void stochasticOscilatorDParam14UsingSMA3AndGenericConstructer()
        {
            StochasticOscillatorKIndicator sof = new StochasticOscillatorKIndicator(data, 14);
            SMAIndicator sma = new SMAIndicator(sof, 3);
            StochasticOscillatorDIndicator sos = new StochasticOscillatorDIndicator(sma);

            Assert.AreEqual(sma.GetValue(0), sos.GetValue(0));
            Assert.AreEqual(sma.GetValue(1), sos.GetValue(1));
            Assert.AreEqual(sma.GetValue(2), sos.GetValue(2));
        }
        public void StochasticOscilatorDParam14UsingSma3()
        {
            var sof = new StochasticOscillatorKIndicator(_data, 14);
            var sos = new StochasticOscillatorDIndicator(sof);
            var sma = new SmaIndicator(sof, 3);

            Assert.AreEqual(sma.GetValue(0), sos.GetValue(0));
            Assert.AreEqual(sma.GetValue(1), sos.GetValue(1));
            Assert.AreEqual(sma.GetValue(2), sos.GetValue(2));
            Assert.AreEqual(sma.GetValue(13), sos.GetValue(13));
        }