Search in sources :

Example 1 with CCIIndicator

use of org.ta4j.core.indicators.CCIIndicator in project ta4j by ta4j.

the class CCICorrectionStrategy method buildStrategy.

/**
 * @param series a time series
 * @return a CCI correction strategy
 */
public static Strategy buildStrategy(TimeSeries series) {
    if (series == null) {
        throw new IllegalArgumentException("Series cannot be null");
    }
    CCIIndicator longCci = new CCIIndicator(series, 200);
    CCIIndicator shortCci = new CCIIndicator(series, 5);
    Decimal plus100 = Decimal.HUNDRED;
    Decimal minus100 = Decimal.valueOf(-100);
    Rule entryRule = // Bull trend
    new OverIndicatorRule(longCci, plus100).and(// Signal
    new UnderIndicatorRule(shortCci, minus100));
    Rule exitRule = // Bear trend
    new UnderIndicatorRule(longCci, minus100).and(// Signal
    new OverIndicatorRule(shortCci, plus100));
    Strategy strategy = new BaseStrategy(entryRule, exitRule);
    strategy.setUnstablePeriod(5);
    return strategy;
}
Also used : OverIndicatorRule(org.ta4j.core.trading.rules.OverIndicatorRule) UnderIndicatorRule(org.ta4j.core.trading.rules.UnderIndicatorRule) CCIIndicator(org.ta4j.core.indicators.CCIIndicator) OverIndicatorRule(org.ta4j.core.trading.rules.OverIndicatorRule) UnderIndicatorRule(org.ta4j.core.trading.rules.UnderIndicatorRule)

Aggregations

CCIIndicator (org.ta4j.core.indicators.CCIIndicator)1 OverIndicatorRule (org.ta4j.core.trading.rules.OverIndicatorRule)1 UnderIndicatorRule (org.ta4j.core.trading.rules.UnderIndicatorRule)1