Пример #1
0
        public virtual void IsSatisfied()
        {
            Decimal tradedAmount = Decimal.One;

            // 30% stop-gain
            _rule = new StopGainRule(_closePrice, Decimal.ValueOf("30"));

            Assert.IsFalse(_rule.IsSatisfied(0, null));
            Assert.IsFalse(_rule.IsSatisfied(1, _tradingRecord));

            // Enter at 108
            _tradingRecord.Enter(2, Decimal.ValueOf("108"), tradedAmount);
            Assert.IsFalse(_rule.IsSatisfied(2, _tradingRecord));
            Assert.IsFalse(_rule.IsSatisfied(3, _tradingRecord));
            Assert.IsTrue(_rule.IsSatisfied(4, _tradingRecord));
            // Exit
            _tradingRecord.Exit(5);

            // Enter at 118
            _tradingRecord.Enter(5, Decimal.ValueOf("118"), tradedAmount);
            Assert.IsFalse(_rule.IsSatisfied(5, _tradingRecord));
            Assert.IsTrue(_rule.IsSatisfied(6, _tradingRecord));
            Assert.IsTrue(_rule.IsSatisfied(7, _tradingRecord));
        }
Пример #2
0
        public void IsSatisfied()
        {
            decimal tradedAmount = Decimals.ONE;

            // 30% stop-gain
            StopGainRule rule = new StopGainRule(closePrice, 30);

            Assert.IsFalse(rule.IsSatisfied(0, null));
            Assert.IsFalse(rule.IsSatisfied(1, tradingRecord));

            // Enter at 108
            tradingRecord.Enter(2, 108, tradedAmount);
            Assert.IsFalse(rule.IsSatisfied(2, tradingRecord));
            Assert.IsFalse(rule.IsSatisfied(3, tradingRecord));
            Assert.IsTrue(rule.IsSatisfied(4, tradingRecord));
            // Exit
            tradingRecord.Exit(5);

            // Enter at 118
            tradingRecord.Enter(5, 118, tradedAmount);
            Assert.IsFalse(rule.IsSatisfied(5, tradingRecord));
            Assert.IsTrue(rule.IsSatisfied(6, tradingRecord));
            Assert.IsTrue(rule.IsSatisfied(7, tradingRecord));
        }