Search in sources :

Example 1 with MACDIndicator

use of org.ta4j.core.indicators.MACDIndicator in project crypto-bot by jnidzwetzki.

the class DonchianChannelStrategy method getStrategy.

@Override
public Strategy getStrategy() {
    final MACDIndicator macd = new MACDIndicator(closePriceIndicator, 9, 26);
    final EMAIndicator emaMacd = new EMAIndicator(macd, 9);
    final Rule buyingRule = new AndRule(new IsRisingRule(donchianChannelUpper, 1), new OverIndicatorRule(macd, Decimal.valueOf(0)));
    final // new OrRule(
    Rule sellingRule = new IsFallingRule(donchianChannelLower, 1);
    // new UnderIndicatorRule(macd, emaMacd));
    final BaseStrategy strategy = new BaseStrategy(buyingRule, sellingRule);
    return strategy;
}
Also used : AndRule(org.ta4j.core.trading.rules.AndRule) OverIndicatorRule(org.ta4j.core.trading.rules.OverIndicatorRule) IsFallingRule(org.ta4j.core.trading.rules.IsFallingRule) EMAIndicator(org.ta4j.core.indicators.EMAIndicator) IsRisingRule(org.ta4j.core.trading.rules.IsRisingRule) MACDIndicator(org.ta4j.core.indicators.MACDIndicator) BaseStrategy(org.ta4j.core.BaseStrategy) Rule(org.ta4j.core.Rule) IsFallingRule(org.ta4j.core.trading.rules.IsFallingRule) OverIndicatorRule(org.ta4j.core.trading.rules.OverIndicatorRule) AndRule(org.ta4j.core.trading.rules.AndRule) IsRisingRule(org.ta4j.core.trading.rules.IsRisingRule)

Example 2 with MACDIndicator

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

the class MovingMomentumStrategy method buildStrategy.

/**
 * @param series a time series
 * @return a moving momentum strategy
 */
public static Strategy buildStrategy(TimeSeries series) {
    if (series == null) {
        throw new IllegalArgumentException("Series cannot be null");
    }
    ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
    // The bias is bullish when the shorter-moving average moves above the longer moving average.
    // The bias is bearish when the shorter-moving average moves below the longer moving average.
    EMAIndicator shortEma = new EMAIndicator(closePrice, 9);
    EMAIndicator longEma = new EMAIndicator(closePrice, 26);
    StochasticOscillatorKIndicator stochasticOscillK = new StochasticOscillatorKIndicator(series, 14);
    MACDIndicator macd = new MACDIndicator(closePrice, 9, 26);
    EMAIndicator emaMacd = new EMAIndicator(macd, 18);
    // Entry rule
    Rule entryRule = // Trend
    new OverIndicatorRule(shortEma, longEma).and(// Signal 1
    new CrossedDownIndicatorRule(stochasticOscillK, Decimal.valueOf(20))).and(// Signal 2
    new OverIndicatorRule(macd, emaMacd));
    // Exit rule
    Rule exitRule = // Trend
    new UnderIndicatorRule(shortEma, longEma).and(// Signal 1
    new CrossedUpIndicatorRule(stochasticOscillK, Decimal.valueOf(80))).and(// Signal 2
    new UnderIndicatorRule(macd, emaMacd));
    return new BaseStrategy(entryRule, exitRule);
}
Also used : OverIndicatorRule(org.ta4j.core.trading.rules.OverIndicatorRule) EMAIndicator(org.ta4j.core.indicators.EMAIndicator) UnderIndicatorRule(org.ta4j.core.trading.rules.UnderIndicatorRule) CrossedDownIndicatorRule(org.ta4j.core.trading.rules.CrossedDownIndicatorRule) CrossedUpIndicatorRule(org.ta4j.core.trading.rules.CrossedUpIndicatorRule) MACDIndicator(org.ta4j.core.indicators.MACDIndicator) StochasticOscillatorKIndicator(org.ta4j.core.indicators.StochasticOscillatorKIndicator) OverIndicatorRule(org.ta4j.core.trading.rules.OverIndicatorRule) CrossedDownIndicatorRule(org.ta4j.core.trading.rules.CrossedDownIndicatorRule) UnderIndicatorRule(org.ta4j.core.trading.rules.UnderIndicatorRule) CrossedUpIndicatorRule(org.ta4j.core.trading.rules.CrossedUpIndicatorRule) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator)

Aggregations

EMAIndicator (org.ta4j.core.indicators.EMAIndicator)2 MACDIndicator (org.ta4j.core.indicators.MACDIndicator)2 OverIndicatorRule (org.ta4j.core.trading.rules.OverIndicatorRule)2 BaseStrategy (org.ta4j.core.BaseStrategy)1 Rule (org.ta4j.core.Rule)1 StochasticOscillatorKIndicator (org.ta4j.core.indicators.StochasticOscillatorKIndicator)1 ClosePriceIndicator (org.ta4j.core.indicators.helpers.ClosePriceIndicator)1 AndRule (org.ta4j.core.trading.rules.AndRule)1 CrossedDownIndicatorRule (org.ta4j.core.trading.rules.CrossedDownIndicatorRule)1 CrossedUpIndicatorRule (org.ta4j.core.trading.rules.CrossedUpIndicatorRule)1 IsFallingRule (org.ta4j.core.trading.rules.IsFallingRule)1 IsRisingRule (org.ta4j.core.trading.rules.IsRisingRule)1 UnderIndicatorRule (org.ta4j.core.trading.rules.UnderIndicatorRule)1