Exemple #1
0
        protected override decimal ComputeNextValue(TradeBar input)
        {
            _macd.Update(input.EndTime, input.Close);

            if (!IsReady)
            {
                return(0m);
            }

            var macdBar = new TradeBar
            {
                EndTime = input.EndTime,
                Close   = _macd
            };

            _frac1.Update(macdBar);

            var pfBar = new TradeBar
            {
                EndTime = input.EndTime,
                Close   = _frac1
            };

            _frac2.Update(pfBar);

            return(_frac2.StochD);
        }
Exemple #2
0
 public void HandlesEqualMinAndMax()
 {
     var reference = new DateTime(2015, 09, 01);
     var stochastics = new Stochastic("sto", 2, 2, 2);
     for (int i = 0; i < 4; i++)
     {
         var bar = new TradeBar{Time = reference.AddSeconds(i)};
         bar.Open = bar.Close = bar.High = bar.Low = bar.Volume = 1;
         stochastics.Update(bar);
         Assert.AreEqual(0m, stochastics.Current.Value);
     }
 }
Exemple #3
0
        protected override decimal ComputeNextValue(IBaseDataBar input)
        {
            _macd.Update(input.EndTime, input.Close);

            if (!_macd.IsReady)
            {
                return(0m);
            }

            var macdBar = new TradeBar
            {
                Time    = input.Time,
                EndTime = input.EndTime,
                Open    = _macd,
                High    = _macd,
                Low     = _macd,
                Close   = _macd
            };

            _frac1.Update(macdBar);

            if (!_frac1.IsReady)
            {
                return(0m);
            }

            var pf = _pf.IsReady ? _pf + (_factor * (_frac1.FastStoch - _pf)) : _frac1.FastStoch;

            _pf.Update(input.Time, pf);

            var pfBar = new TradeBar
            {
                Time    = input.Time,
                EndTime = input.EndTime,
                Open    = pf,
                High    = pf,
                Low     = pf,
                Close   = pf
            };

            _frac2.Update(pfBar);

            if (!_frac2.IsReady)
            {
                return(0m);
            }

            var pff = _pff.IsReady ? _pff + (_factor * (_frac2.FastStoch - _pff)) : _frac2.FastStoch;

            _pff.Update(input.Time, pff);

            return(pff);
        }
Exemple #4
0
        public void ResetsProperly()
        {
            var stochastics = new Stochastic("sto", 12, 3, 5);

            foreach (var bar in TestHelper.GetTradeBarStream("spy_with_stoch12k3.txt", false))
            {
                stochastics.Update(bar);
            }
            Assert.IsTrue(stochastics.IsReady);
            Assert.IsTrue(stochastics.FastStoch.IsReady);
            Assert.IsTrue(stochastics.StochK.IsReady);
            Assert.IsTrue(stochastics.StochD.IsReady);

            stochastics.Reset();

            TestHelper.AssertIndicatorIsInDefaultState(stochastics);
            TestHelper.AssertIndicatorIsInDefaultState(stochastics.FastStoch);
            TestHelper.AssertIndicatorIsInDefaultState(stochastics.StochK);
            TestHelper.AssertIndicatorIsInDefaultState(stochastics.StochD);
        }