public void GetValueWhenTimeFrameIs20() { var cci = new CciIndicator(_series, 20); // Incomplete time frame TaTestsUtils.AssertDecimalEquals(cci.GetValue(0), 0); TaTestsUtils.AssertDecimalEquals(cci.GetValue(1), -66.6667); TaTestsUtils.AssertDecimalEquals(cci.GetValue(2), -100d); TaTestsUtils.AssertDecimalEquals(cci.GetValue(10), 14.365); TaTestsUtils.AssertDecimalEquals(cci.GetValue(11), 54.2544); // Complete time frame var results20To30 = new[] { 101.9185, 31.1946, 6.5578, 33.6078, 34.9686, 13.6027, -10.6789, -11.471, -29.2567, -128.6, -72.7273 }; for (var i = 0; i < results20To30.Length; i++) { TaTestsUtils.AssertDecimalEquals(cci.GetValue(i + 19), results20To30[i]); } }
/// <param name="series"> a time series </param> /// <returns> a CCI correction strategy </returns> public static Strategy BuildStrategy(TimeSeries series) { if (series == null) { throw new ArgumentException("Series cannot be null"); } var longCci = new CciIndicator(series, 200); var shortCci = new CciIndicator(series, 5); var plus100 = Decimal.Hundred; var minus100 = Decimal.ValueOf(-100); var entryRule = (new OverIndicatorRule(longCci, plus100)).And(new UnderIndicatorRule(shortCci, minus100)); // Signal - Bull trend var exitRule = (new UnderIndicatorRule(longCci, minus100)).And(new OverIndicatorRule(shortCci, plus100)); // Signal - Bear trend var strategy = new Strategy(entryRule, exitRule) { UnstablePeriod = 5 }; return(strategy); }