public void TestMethod1() { //Входные данные //Создать 2 условия int index1 = 0, index2 = 0; int curIndex = 60; ParameterCondition par1 = ParameterCondition.PriceClose; ParameterCondition par2 = ParameterCondition.PriceOpen; Predicate predicate = Predicate.Less; Condition cond = new Condition(index1, index2, par1, par2, null, null, 0.0, 0.0, predicate); int index1_ = 1, index2_ = 1; ParameterCondition par1_ = ParameterCondition.Indicator; ParameterCondition par2_ = ParameterCondition.Indicator; Predicate predicate_ = Predicate.MoreEqual; Indicator ind1 = new SMA(14); Indicator ind2 = new SMA(28); Condition cond2 = new Condition(index1_, index2_, par1_, par2_, ind1, ind2, 0.0, 0.0, predicate_); //Накопить данные для индикаторов for (int i = 0; i < curIndex; i++) { ind1.update_value(i, instrument); ind2.update_value(i, instrument); } //Создать правило TradingRule rule = new TradingRule(); rule.add_condition(cond); rule.add_condition(cond2); string name = "TestStrategy1"; DateTime dateTime = DateTime.Now; TradingStrategy strat = new TradingStrategy(name); strat.add_rule(rule); strat.save_to_xml(); controller.add_strategy(new CaretakerStrategy(strat)); TradingStrategy strat1 = controller.get_strategy(name).Originator; File.Delete("Strategies\\TestStrategy1.xml"); Assert.AreEqual(strat.Loaded && strat.Name == name && strat.DateOfChange == dateTime && strat.DateOfCreation == dateTime, true); }
//Тест проверяет правильно ли срабатывает TradingRule public void test_TradingRule() { //Входные данные //Создать 2 условия int index1 = 0, index2 = 0; int curIndex = 60; ParameterCondition par1 = ParameterCondition.PriceMax; ParameterCondition par2 = ParameterCondition.PriceMin; Predicate predicate = Predicate.Less; Condition cond = new Condition(index1, index2, par1, par2, null, null, 0.0, 0.0, predicate); int index1_ = 1, index2_ = 1; ParameterCondition par1_ = ParameterCondition.Indicator; ParameterCondition par2_ = ParameterCondition.Indicator; Predicate predicate_ = Predicate.MoreEqual; Indicator ind1 = new SMA(14); Indicator ind2 = new MACD(28); Condition cond2 = new Condition(index1_, index2_, par1_, par2_, ind1, ind2, 0.0, 0.0, predicate_); //Накопить данные для индикаторов for (int i = 0; i < curIndex; i++) { ind1.update_value(i, instrument); ind2.update_value(i, instrument); } //Создать правило TradingRule rule = new TradingRule(Signal.Buy); rule.add_condition(cond); rule.add_condition(cond2); bool expected = instrument.get_interval(curIndex, index1).ClosingPrice < instrument.get_interval(curIndex, index1).OpeningPrice&& ind1.get_value(curIndex, index1_) >= ind2.get_value(curIndex, index2_); Assert.AreEqual(expected, rule.check(curIndex, instrument)); }