Search in sources :

Example 6 with UnderIndicatorRule

use of org.ta4j.core.trading.rules.UnderIndicatorRule in project crypto-bot by jnidzwetzki.

the class ForexStrategy01 method getStrategy.

public Strategy getStrategy() {
    EMAIndicator sma1 = new EMAIndicator(closePriceIndicator, 5);
    EMAIndicator sma2 = new EMAIndicator(closePriceIndicator, 10);
    RSIIndicator rsi = new RSIIndicator(closePriceIndicator, 14);
    StochasticOscillatorKIndicator stochK = new StochasticOscillatorKIndicator(timeSeries, 14);
    StochasticOscillatorDIndicator stochD = new StochasticOscillatorDIndicator(stochK);
    Rule buyingRule = new CrossedUpIndicatorRule(sma1, sma2).and(new OverIndicatorRule(rsi, Decimal.valueOf(50))).and(new OverIndicatorRule(stochK, stochD)).and(new UnderIndicatorRule(stochD, Decimal.valueOf(80)));
    Rule sellingRule = new CrossedDownIndicatorRule(sma1, sma2).or(new CrossedDownIndicatorRule(rsi, Decimal.valueOf(50)));
    final BaseStrategy strategy = new BaseStrategy(buyingRule, sellingRule);
    return strategy;
}
Also used : StochasticOscillatorDIndicator(org.ta4j.core.indicators.StochasticOscillatorDIndicator) OverIndicatorRule(org.ta4j.core.trading.rules.OverIndicatorRule) EMAIndicator(org.ta4j.core.indicators.EMAIndicator) UnderIndicatorRule(org.ta4j.core.trading.rules.UnderIndicatorRule) CrossedUpIndicatorRule(org.ta4j.core.trading.rules.CrossedUpIndicatorRule) CrossedDownIndicatorRule(org.ta4j.core.trading.rules.CrossedDownIndicatorRule) RSIIndicator(org.ta4j.core.indicators.RSIIndicator) BaseStrategy(org.ta4j.core.BaseStrategy) StochasticOscillatorKIndicator(org.ta4j.core.indicators.StochasticOscillatorKIndicator) Rule(org.ta4j.core.Rule) OverIndicatorRule(org.ta4j.core.trading.rules.OverIndicatorRule) UnderIndicatorRule(org.ta4j.core.trading.rules.UnderIndicatorRule) CrossedDownIndicatorRule(org.ta4j.core.trading.rules.CrossedDownIndicatorRule) CrossedUpIndicatorRule(org.ta4j.core.trading.rules.CrossedUpIndicatorRule)

Example 7 with UnderIndicatorRule

use of org.ta4j.core.trading.rules.UnderIndicatorRule in project ta4j by ta4j.

the class TradingBotOnMovingTimeSeries method buildStrategy.

/**
 * @param series a time series
 * @return a dummy strategy
 */
private static Strategy buildStrategy(TimeSeries series) {
    if (series == null) {
        throw new IllegalArgumentException("Series cannot be null");
    }
    ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
    SMAIndicator sma = new SMAIndicator(closePrice, 12);
    // Sell when close price goes over SMA
    return new BaseStrategy(new OverIndicatorRule(sma, closePrice), new UnderIndicatorRule(sma, closePrice));
}
Also used : SMAIndicator(org.ta4j.core.indicators.SMAIndicator) OverIndicatorRule(org.ta4j.core.trading.rules.OverIndicatorRule) UnderIndicatorRule(org.ta4j.core.trading.rules.UnderIndicatorRule) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator)

Example 8 with UnderIndicatorRule

use of org.ta4j.core.trading.rules.UnderIndicatorRule 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)8 UnderIndicatorRule (org.ta4j.core.trading.rules.UnderIndicatorRule)8 ClosePriceIndicator (org.ta4j.core.indicators.helpers.ClosePriceIndicator)5 BaseStrategy (org.ta4j.core.BaseStrategy)3 SMAIndicator (org.ta4j.core.indicators.SMAIndicator)3 CrossedDownIndicatorRule (org.ta4j.core.trading.rules.CrossedDownIndicatorRule)3 CrossedUpIndicatorRule (org.ta4j.core.trading.rules.CrossedUpIndicatorRule)3 Rule (org.ta4j.core.Rule)2 EMAIndicator (org.ta4j.core.indicators.EMAIndicator)2 RSIIndicator (org.ta4j.core.indicators.RSIIndicator)2 StochasticOscillatorKIndicator (org.ta4j.core.indicators.StochasticOscillatorKIndicator)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 MACDIndicator (org.ta4j.core.indicators.MACDIndicator)1 StochasticOscillatorDIndicator (org.ta4j.core.indicators.StochasticOscillatorDIndicator)1 BollingerBandsMiddleIndicator (org.ta4j.core.indicators.bollinger.BollingerBandsMiddleIndicator)1 BollingerBandsUpperIndicator (org.ta4j.core.indicators.bollinger.BollingerBandsUpperIndicator)1 StandardDeviationIndicator (org.ta4j.core.indicators.statistics.StandardDeviationIndicator)1