Exemplo n.º 1
0
 /// <summary>
 /// Resets this indicator to its initial state
 /// </summary>
 public override void Reset()
 {
     _ema1.Reset();
     _ema2.Reset();
     _ema3.Reset();
     base.Reset();
 }
        public override void OnSecuritiesChanged(SecurityChanges changes)
        {
            if (changes.RemovedSecurities.Count > 0)
            {
                // Remove the consolidator for the previous contract
                // and reset the indicators
                if (_symbol != null && _consolidator != null)
                {
                    SubscriptionManager.RemoveConsolidator(_symbol, _consolidator);
                    _fast.Reset();
                    _slow.Reset();
                }
                // We don't need to call Liquidate(_symbol),
                // since its positions are liquidated because the contract has expired.
            }

            // Only one security will be added: the new front contract
            _symbol = changes.AddedSecurities.SingleOrDefault().Symbol;

            // Create a new consolidator and register the indicators to it
            _consolidator = ResolveConsolidator(_symbol, Resolution.Minute);
            RegisterIndicator(_symbol, _fast, _consolidator);
            RegisterIndicator(_symbol, _slow, _consolidator);

            // Warm up the indicators
            WarmUpIndicator(_symbol, _fast, Resolution.Minute);
            WarmUpIndicator(_symbol, _slow, Resolution.Minute);

            PlotEma();
        }
        public override void ResetsProperly()
        {
            // ema reset is just setting the value and samples back to 0
            var ema = new ExponentialMovingAverage(3);

            foreach (var data in TestHelper.GetDataStream(5))
            {
                ema.Update(data);
            }
            Assert.IsTrue(ema.IsReady);
            Assert.AreNotEqual(0m, ema.Current.Value);
            Assert.AreNotEqual(0, ema.Samples);

            ema.Reset();

            TestHelper.AssertIndicatorIsInDefaultState(ema);
        }
Exemplo n.º 4
0
        // This is almost a direct rip from Mirror's NetworkTime.OnClientPong(...), but at least I understand how it works.
        /// <summary>
        ///		Finishes an offset update.
        /// </summary>
        /// <param name="message">The times sent by the server, including the original send time.</param>
        public void ProcessPong(Timestamped <PingMessage> message)
        {
            var offset = ProcessPong(message, out var rtt, out var offsetBounds);

            _offsetBounds = _offsetBounds.Clamp(offsetBounds);

            if (!_offsetBounds.IsWithin(_offsetAverage.Value))             // Average does not exist or is out of known bounds.
            {
                _offsetAverage.Reset(_offsetBounds.Clamp(offset));
            }
            else if (_offsetBounds.IsWithin(offset))             // New offset is within bounds.
            {
                _offsetAverage.Push(offset);
            }

            _rttAverage.Push(rtt);

            Received?.Invoke(offset, rtt);
        }
Exemplo n.º 5
0
        public void ResetsProperly()
        {
            // ema reset is just setting the value and samples back to 0
            var ema = new ExponentialMovingAverage(3);

            foreach (var data in TestHelper.GetDataStream(5))
            {
                ema.Update(data);
            }
            Assert.IsTrue(ema.IsReady);
            Assert.AreNotEqual(0m, ema.Current.Value);
            Assert.AreNotEqual(0, ema.Samples);

            ema.Reset();

            Assert.IsFalse(ema.IsReady);
            Assert.AreEqual(0, ema.Samples);
            Assert.AreEqual(0m, ema.Current.Value);
            Assert.AreEqual(DateTime.MinValue, ema.Current.Time);
        }
Exemplo n.º 6
0
 /// <summary>
 /// Resets this instance.
 /// </summary>
 public void Reset()
 {
     fastEMA.Reset();
     slowEMA.Reset();
     EMADiffRW.Reset();
 }