public void IsReadyAfterPeriodUpdates()
        {
            var ind = new VolumeWeightedAveragePriceIndicator(3);

            ind.Update(new TradeBar(DateTime.UtcNow, "SPY", 1m, 1m, 1m, 1m, 1));
            ind.Update(new TradeBar(DateTime.UtcNow, "SPY", 1m, 1m, 1m, 1m, 1));
            Assert.IsFalse(ind.IsReady);
            ind.Update(new TradeBar(DateTime.UtcNow, "SPY", 1m, 1m, 1m, 1m, 1));
            Assert.IsTrue(ind.IsReady);
        }
        public void ResetsProperly()
        {
            var ind = new VolumeWeightedAveragePriceIndicator(50);

            foreach (var data in TestHelper.GetTradeBarStream("spy_with_vwap.txt"))
            {
                ind.Update(data);
            }
            Assert.IsTrue(ind.IsReady);

            ind.Reset();

            TestHelper.AssertIndicatorIsInDefaultState(ind);
            ind.Update(new TradeBar(DateTime.UtcNow, Symbols.SPY, 2m, 2m, 2m, 2m, 1));
            Assert.AreEqual(ind.Current.Value, 2m);
        }
Exemplo n.º 3
0
        public void Scan(TradeBar data)
        {
            _vwap.Update(data);

            if (_vwap > data.Price && !_securityHolding.Invested)
            {
                Signal = SignalType.Long;
            }
            else if (_vwap < data.Price && !_securityHolding.Invested)
            {
                Signal = SignalType.Short;
            }
            else
            {
                Signal = SignalType.NoSignal;
            }
        }
        public void VwapComputesCorrectly()
        {
            const int period = 4;
            const int volume = 100;
            var       ind    = new VolumeWeightedAveragePriceIndicator(period);
            var       data   = new[] { 1d, 10d, 100d, 1000d, 10000d, 1234d, 56789d };

            var seen = new List <double>();

            for (var i = 0; i < data.Length; i++)
            {
                var datum = data[i];
                seen.Add(datum);
                ind.Update(DateTime.Now.AddSeconds(i), new TradeBarValue(datum, datum, datum, datum, volume));
                // When volume is constant, VWAP is a simple moving average
                Assert.AreEqual(Enumerable.Reverse(seen).Take(period).Average(), ind.Current.Value);
            }
        }
        public void VWAPComputesCorrectly()
        {
            const int period = 4;
            const int volume = 100;
            var       ind    = new VolumeWeightedAveragePriceIndicator(period);
            var       data   = new[] { 1m, 10m, 100m, 1000m, 10000m, 1234m, 56789m };

            var seen = new List <decimal>();

            for (int i = 0; i < data.Length; i++)
            {
                var datum = data[i];
                seen.Add(datum);
                ind.Update(new TradeBar(DateTime.Now.AddSeconds(i), TimeZone.Utc, Props.TickerSymbol, datum, datum, datum, datum, volume));
                // When volume is constant, VWAP is a simple moving average
                Assert.Equal(Enumerable.Reverse(seen).Take(period).Average(), ind.Current.Price);
            }
        }
Exemplo n.º 6
0
        public bool Update(TradeBar data, decimal holdings)
        {
            _data     = data;
            _holdings = holdings;

            var isReady = _ich.Update(data) && _adx.Update(data) && _vwap.Update(data);

            _consolidation.RollConsolidationWindow();
            _consolidation.Consolidate(data, _ich);

            //_volume.Add(data.Volume);

            TrendDirection = IsBullishTrend()
                ? Direction.Bullish
                : IsBearishTrend() ? Direction.Bearish : Direction.None;

            return(isReady);
        }