Search in sources :

Example 11 with OverIndicatorRule

use of org.ta4j.core.trading.rules.OverIndicatorRule 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

OverIndicatorRule (org.ta4j.core.trading.rules.OverIndicatorRule)11 UnderIndicatorRule (org.ta4j.core.trading.rules.UnderIndicatorRule)8 BaseStrategy (org.ta4j.core.BaseStrategy)6 ClosePriceIndicator (org.ta4j.core.indicators.helpers.ClosePriceIndicator)6 Rule (org.ta4j.core.Rule)5 EMAIndicator (org.ta4j.core.indicators.EMAIndicator)5 CrossedDownIndicatorRule (org.ta4j.core.trading.rules.CrossedDownIndicatorRule)5 CrossedUpIndicatorRule (org.ta4j.core.trading.rules.CrossedUpIndicatorRule)4 RSIIndicator (org.ta4j.core.indicators.RSIIndicator)3 SMAIndicator (org.ta4j.core.indicators.SMAIndicator)3 MACDIndicator (org.ta4j.core.indicators.MACDIndicator)2 StochasticOscillatorKIndicator (org.ta4j.core.indicators.StochasticOscillatorKIndicator)2 StopLossRule (org.ta4j.core.trading.rules.StopLossRule)2 Test (org.junit.Test)1 Strategy (org.ta4j.core.Strategy)1 TimeSeries (org.ta4j.core.TimeSeries)1 CCIIndicator (org.ta4j.core.indicators.CCIIndicator)1 StochasticOscillatorDIndicator (org.ta4j.core.indicators.StochasticOscillatorDIndicator)1 BollingerBandsMiddleIndicator (org.ta4j.core.indicators.bollinger.BollingerBandsMiddleIndicator)1 BollingerBandsUpperIndicator (org.ta4j.core.indicators.bollinger.BollingerBandsUpperIndicator)1