Example #1
0
        public void OnlyFullPeriodTest()
        {
            int fullPeriod = 10;
            MomersionIndicator Momersion = new MomersionIndicator(fullPeriod);
            DateTime time = DateTime.Now;

            #region Array input

            decimal[] expected = new decimal[30]
            {
                50m, 50m   , 50m  , 50m, 50m, 50m  , 50m, 50m,
                50m, 50m   , 50m  , 50m, 60m, 50m  , 40m, 30m,
                40m, 50m   , 60m  , 50m, 50m, 40m  , 30m, 30m,
                40m, 44.44m, 37.5m, 25m, 25m, 37.5m,
            };

            #endregion Array input

            decimal[] actual = new decimal[prices.Length];

            for (int i = 0; i < prices.Length; i++)
            {
                Momersion.Update(new IndicatorDataPoint(time, prices[i]));
                decimal momersionValue = Math.Round(Momersion.Current.Value, 2);
                actual[i] = momersionValue;

                Console.WriteLine(string.Format("Bar : {0} | {1}, Is ready? {2}", i, Momersion.ToString(), Momersion.IsReady));
                time = time.AddMinutes(1);
            }
            Assert.AreEqual(expected, actual);
        }
Example #2
0
        public void OnlyFullPeriodTest()
        {
            const int fullPeriod = 10;
            var momersion = new MomersionIndicator(fullPeriod);

            RunTestIndicator(momersion, _expectedFullPeriod);
        }
Example #3
0
        public void MinPeriodTest()
        {
            int minPeriod  = 7;
            int fullPeriod = 20;
            MomersionIndicator Momersion = new MomersionIndicator(minPeriod, fullPeriod);
            DateTime           time      = DateTime.Now;

            #region Array input

            decimal[] expected = new decimal[30]
            {
                50.00m, 50.00m, 50.00m, 50.00m, 50.00m, 50.00m, 50.00m, 50.00m, 57.14m, 62.50m,
                55.56m, 60.00m, 63.64m, 58.33m, 53.85m, 50.00m, 53.33m, 56.25m, 58.82m, 55.56m,
                52.63m, 50.00m, 45.00m, 40.00m, 40.00m, 36.84m, 38.89m, 38.89m, 44.44m, 44.44m
            };

            #endregion Array input

            decimal[] actual = new decimal[prices.Length];

            for (int i = 0; i < prices.Length; i++)
            {
                Momersion.Update(new IndicatorDataPoint(time, prices[i]));
                decimal momersionValue = Math.Round(Momersion.Current.Value, 2);
                actual[i] = momersionValue;

                Console.WriteLine(string.Format("Bar : {0} | {1}, Is ready? {2}", i, Momersion.ToString(), Momersion.IsReady));
                time = time.AddMinutes(1);
            }
            Assert.AreEqual(expected, actual);
        }
Example #4
0
        public void ComputesCorrectly(int?minPeriod, int fullPeriod)
        {
            var momersion = new MomersionIndicator(minPeriod, fullPeriod);
            var expected  = minPeriod.HasValue ? _expectedMinPeriod : _expectedFullPeriod;

            RunTestIndicator(momersion, expected);
        }
        public DIFStrategy(Indicator Price, int DecyclePeriod = 20, int InvFisherPeriod = 40, decimal Threshold = 0.9m, decimal Tolerance = 0.001m)
        {
            // Initialize the fields.
            _decyclePeriod   = DecyclePeriod;
            _invFisherPeriod = InvFisherPeriod;
            _threshold       = Threshold;
            _tolerance       = Tolerance;

            // Initialize the indicators used by the Strategy.
            _price        = Price;
            DecycleTrend  = new Decycle(_decyclePeriod).Of(Price);
            InverseFisher = new InverseFisherTransform(_invFisherPeriod).Of(DecycleTrend);
            InvFisherRW   = new RollingWindow <decimal>(2);

            LightSmoothPrice = new Decycle(10).Of(Price);
            Momersion        = new MomersionIndicator(10, 30).Of(LightSmoothPrice, false);

            // Fill the Inverse Fisher rolling windows at every new InverseFisher observation.
            // Once the Inverse Fisher rolling windows is ready, at every InverseFisher update, the Check signal method will be called.
            InverseFisher.Updated += (object sender, IndicatorDataPoint updated) =>
            {
                if (InverseFisher.IsReady)
                {
                    InvFisherRW.Add(updated);
                }
                if (InvFisherRW.IsReady)
                {
                    CheckSignal();
                }
            };

            Position     = StockState.noInvested;
            EntryPrice   = null;
            ActualSignal = OrderSignal.doNothing;
        }
Example #6
0
        public void OnlyFullPeriodTest()
        {
            int fullPeriod = 10;
            MomersionIndicator Momersion = new MomersionIndicator(fullPeriod);
            DateTime           time      = DateTime.Now;

            #region Array input

            decimal[] expected = new decimal[30]
            {
                50m, 50m, 50m, 50m, 50m, 50m, 50m, 50m,
                50m, 50m, 50m, 50m, 60m, 50m, 40m, 30m,
                40m, 50m, 60m, 50m, 50m, 40m, 30m, 30m,
                40m, 44.44m, 37.5m, 25m, 25m, 37.5m,
            };

            #endregion Array input

            decimal[] actual = new decimal[prices.Length];

            for (int i = 0; i < prices.Length; i++)
            {
                Momersion.Update(new IndicatorDataPoint(time, prices[i]));
                decimal momersionValue = Math.Round(Momersion.Current.Value, 2);
                actual[i] = momersionValue;

                Console.WriteLine(string.Format("Bar : {0} | {1}, Is ready? {2}", i, Momersion.ToString(), Momersion.IsReady));
                time = time.AddMinutes(1);
            }
            Assert.AreEqual(expected, actual);
        }
        public DIFStrategy(Indicator Price, int DecyclePeriod = 20, int InvFisherPeriod = 40, decimal Threshold = 0.9m, decimal Tolerance = 0.001m)
        {
            // Initialize the fields.
            _decyclePeriod = DecyclePeriod;
            _invFisherPeriod = InvFisherPeriod;
            _threshold = Threshold;
            _tolerance = Tolerance;

            // Initialize the indicators used by the Strategy.
            _price = Price;
            DecycleTrend = new Decycle(_decyclePeriod).Of(Price);
            InverseFisher = new InverseFisherTransform(_invFisherPeriod).Of(DecycleTrend);
            InvFisherRW = new RollingWindow<decimal>(2);

            LightSmoothPrice = new Decycle(10).Of(Price);
            Momersion = new MomersionIndicator(10, 30).Of(LightSmoothPrice, false);

            // Fill the Inverse Fisher rolling windows at every new InverseFisher observation.
            // Once the Inverse Fisher rolling windows is ready, at every InverseFisher update, the Check signal method will be called.
            InverseFisher.Updated += (object sender, IndicatorDataPoint updated) =>
            {
                if (InverseFisher.IsReady) InvFisherRW.Add(updated);
                if (InvFisherRW.IsReady) CheckSignal();
            };

            Position = StockState.noInvested;
            EntryPrice = null;
            ActualSignal = OrderSignal.doNothing;
        }
Example #8
0
        public void OnlyFullPeriodTest()
        {
            const int fullPeriod = 10;
            var       momersion  = new MomersionIndicator(fullPeriod);

            RunTestIndicator(momersion, _expectedFullPeriod);
        }
Example #9
0
        public void MinPeriodTest()
        {
            int minPeriod = 7;
            int fullPeriod = 20;
            MomersionIndicator Momersion = new MomersionIndicator(minPeriod, fullPeriod);
            DateTime time = DateTime.Now;

            #region Array input

            decimal[] expected = new decimal[30]
            {
                50.00m, 50.00m, 50.00m, 50.00m, 50.00m, 50.00m, 50.00m, 50.00m, 57.14m, 62.50m,
                55.56m, 60.00m, 63.64m, 58.33m, 53.85m, 50.00m, 53.33m, 56.25m, 58.82m, 55.56m,
                52.63m, 50.00m, 45.00m, 40.00m, 40.00m, 36.84m, 38.89m, 38.89m, 44.44m, 44.44m
            };

            #endregion Array input

            decimal[] actual = new decimal[prices.Length];

            for (int i = 0; i < prices.Length; i++)
            {
                Momersion.Update(new IndicatorDataPoint(time, prices[i]));
                decimal momersionValue = Math.Round(Momersion.Current.Value, 2);
                actual[i] = momersionValue;

                Console.WriteLine(string.Format("Bar : {0} | {1}, Is ready? {2}", i, Momersion.ToString(), Momersion.IsReady));
                time = time.AddMinutes(1);
            }
            Assert.AreEqual(expected, actual);
        }
Example #10
0
        public void MinPeriodTest()
        {
            const int minPeriod = 7;
            const int fullPeriod = 20;
            var momersion = new MomersionIndicator(minPeriod, fullPeriod);

            RunTestIndicator(momersion, _expectedMinPeriod);
        }
Example #11
0
        public void MinPeriodTest()
        {
            const int minPeriod  = 7;
            const int fullPeriod = 20;
            var       momersion  = new MomersionIndicator(minPeriod, fullPeriod);

            RunTestIndicator(momersion, _expectedMinPeriod);
        }
Example #12
0
        public void WarmsUpProperly(int?minPeriod, int fullPeriod)
        {
            var momersion  = new MomersionIndicator(minPeriod, fullPeriod);
            var period     = ((IIndicatorWarmUpPeriodProvider)momersion).WarmUpPeriod;
            var dataStream = TestHelper.GetDataStream(period).ToArray();

            for (var i = 0; i < period; i++)
            {
                momersion.Update(dataStream[i]);
                Assert.AreEqual(i == period - 1, momersion.IsReady);
            }
        }
Example #13
0
        public void ResetsProperly()
        {
            var momersion = new MomersionIndicator(7, 20);

            RunTestIndicator(momersion, _expectedMinPeriod);

            Assert.True(momersion.IsReady);

            momersion.Reset();

            TestHelper.AssertIndicatorIsInDefaultState(momersion);
        }
Example #14
0
        public void ResetsProperly()
        {
            var momersion = new MomersionIndicator(7, 20);

            RunTestIndicator(momersion, _expectedMinPeriod);

            Assert.IsTrue(momersion.IsReady);

            momersion.Reset();

            TestHelper.AssertIndicatorIsInDefaultState(momersion);
        }
Example #15
0
        public void ResetsProperly(int?minPeriod, int fullPeriod)
        {
            var momersion = new MomersionIndicator(minPeriod, fullPeriod);
            var expected  = minPeriod.HasValue ? _expectedMinPeriod : _expectedFullPeriod;

            RunTestIndicator(momersion, expected);

            Assert.IsTrue(momersion.IsReady);

            momersion.Reset();

            TestHelper.AssertIndicatorIsInDefaultState(momersion);
        }
Example #16
0
        private void RunTestIndicator(MomersionIndicator momersion, IEnumerable expected)
        {
            var time   = DateTime.Now;
            var actual = new decimal[_prices.Length];

            for (var i = 0; i < _prices.Length; i++)
            {
                momersion.Update(time.AddMinutes(i), _prices[i]);
                actual[i] = Math.Round(momersion.Current.Value, 2);

                Console.WriteLine($"Bar : {i} | {momersion}, Is ready? {momersion.IsReady}");
            }
            Assert.AreEqual(expected, actual);
        }
Example #17
0
        private void RunTestIndicator(MomersionIndicator momersion, decimal[] expected)
        {
            var time   = DateTime.Now;
            var actual = new decimal[_prices.Length];

            for (var i = 0; i < _prices.Length; i++)
            {
                momersion.Update(new IndicatorDataPoint(time, TimeZone.Utc, _prices[i]));
                var momersionValue = Math.Round(momersion.Current.Price, 2);
                actual[i] = momersionValue;

                Console.WriteLine("Bar : {0} | {1}, Is ready? {2}", i, momersion, momersion.IsReady);
                time = time.AddMinutes(1);
            }
            Assert.Equal(expected, actual);
        }
Example #18
0
        private void RunTestIndicator(MomersionIndicator momersion, decimal[] expected)
        {
            var time = DateTime.Now;
            var actual = new decimal[_prices.Length];

            for (var i = 0; i < _prices.Length; i++)
            {
                momersion.Update(new IndicatorDataPoint(time, _prices[i]));
                var momersionValue = Math.Round(momersion.Current.Value, 2);
                actual[i] = momersionValue;

                Console.WriteLine("Bar : {0} | {1}, Is ready? {2}", i, momersion, momersion.IsReady);
                time = time.AddMinutes(1);
            }
            Assert.AreEqual(expected, actual);
        }