Search in sources :

Example 1 with CrossedDownIndicatorRule

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

the class EMAStrategy03 method getStrategy.

public Strategy getStrategy() {
    ClosePriceIndicator closePrice = new ClosePriceIndicator(timeSeries);
    EMAIndicator sma1 = new EMAIndicator(closePrice, sma1Value);
    EMAIndicator sma2 = new EMAIndicator(closePrice, sma2Value);
    EMAIndicator sma3 = new EMAIndicator(closePrice, sma3Value);
    RSIIndicator rsi = new RSIIndicator(closePrice, 14);
    Rule buyingRule = new OverIndicatorRule(sma1, sma2).and(new OverIndicatorRule(sma2, sma3)).and(new OverIndicatorRule(rsi, Decimal.valueOf(50)));
    Rule sellingRule = new CrossedDownIndicatorRule(sma1, sma3).or(new CrossedDownIndicatorRule(sma2, sma3)).or(new StopLossRule(closePrice, Decimal.valueOf("3")));
    final BaseStrategy strategy = new BaseStrategy(buyingRule, sellingRule);
    return strategy;
}
Also used : OverIndicatorRule(org.ta4j.core.trading.rules.OverIndicatorRule) EMAIndicator(org.ta4j.core.indicators.EMAIndicator) CrossedDownIndicatorRule(org.ta4j.core.trading.rules.CrossedDownIndicatorRule) RSIIndicator(org.ta4j.core.indicators.RSIIndicator) BaseStrategy(org.ta4j.core.BaseStrategy) StopLossRule(org.ta4j.core.trading.rules.StopLossRule) Rule(org.ta4j.core.Rule) StopLossRule(org.ta4j.core.trading.rules.StopLossRule) OverIndicatorRule(org.ta4j.core.trading.rules.OverIndicatorRule) CrossedDownIndicatorRule(org.ta4j.core.trading.rules.CrossedDownIndicatorRule) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator)

Example 2 with CrossedDownIndicatorRule

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

Example 3 with CrossedDownIndicatorRule

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

the class RSI2Strategy method buildStrategy.

/**
 * @param series a time series
 * @return a 2-period RSI strategy
 */
public static Strategy buildStrategy(TimeSeries series) {
    if (series == null) {
        throw new IllegalArgumentException("Series cannot be null");
    }
    ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
    SMAIndicator shortSma = new SMAIndicator(closePrice, 5);
    SMAIndicator longSma = new SMAIndicator(closePrice, 200);
    // We use a 2-period RSI indicator to identify buying
    // or selling opportunities within the bigger trend.
    RSIIndicator rsi = new RSIIndicator(closePrice, 2);
    // Entry rule
    // The long-term trend is up when a security is above its 200-period SMA.
    Rule entryRule = // Trend
    new OverIndicatorRule(shortSma, longSma).and(// Signal 1
    new CrossedDownIndicatorRule(rsi, Decimal.valueOf(5))).and(// Signal 2
    new OverIndicatorRule(shortSma, closePrice));
    // Exit rule
    // The long-term trend is down when a security is below its 200-period SMA.
    Rule exitRule = // Trend
    new UnderIndicatorRule(shortSma, longSma).and(// Signal 1
    new CrossedUpIndicatorRule(rsi, Decimal.valueOf(95))).and(// Signal 2
    new UnderIndicatorRule(shortSma, closePrice));
    return new BaseStrategy(entryRule, exitRule);
}
Also used : SMAIndicator(org.ta4j.core.indicators.SMAIndicator) 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) RSIIndicator(org.ta4j.core.indicators.RSIIndicator) 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)

Example 4 with CrossedDownIndicatorRule

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

the class EMAStrategy01 method getStrategy.

public Strategy getStrategy() {
    SMAIndicator shortSma = new SMAIndicator(closePriceIndicator, 5);
    SMAIndicator longSma = new SMAIndicator(closePriceIndicator, 30);
    Rule buyingRule = new CrossedUpIndicatorRule(shortSma, longSma);
    Rule sellingRule = new CrossedDownIndicatorRule(shortSma, longSma).or(new StopLossRule(closePriceIndicator, Decimal.valueOf("3"))).or(new StopGainRule(closePriceIndicator, Decimal.valueOf("2")));
    final BaseStrategy strategy = new BaseStrategy(buyingRule, sellingRule);
    return strategy;
}
Also used : SMAIndicator(org.ta4j.core.indicators.SMAIndicator) CrossedUpIndicatorRule(org.ta4j.core.trading.rules.CrossedUpIndicatorRule) CrossedDownIndicatorRule(org.ta4j.core.trading.rules.CrossedDownIndicatorRule) BaseStrategy(org.ta4j.core.BaseStrategy) StopLossRule(org.ta4j.core.trading.rules.StopLossRule) StopGainRule(org.ta4j.core.trading.rules.StopGainRule) Rule(org.ta4j.core.Rule) StopGainRule(org.ta4j.core.trading.rules.StopGainRule) StopLossRule(org.ta4j.core.trading.rules.StopLossRule) CrossedDownIndicatorRule(org.ta4j.core.trading.rules.CrossedDownIndicatorRule) CrossedUpIndicatorRule(org.ta4j.core.trading.rules.CrossedUpIndicatorRule)

Example 5 with CrossedDownIndicatorRule

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

the class EMAStrategy02 method getStrategy.

public Strategy getStrategy() {
    EMAIndicator sma1 = new EMAIndicator(closePriceIndicator, sma1Value);
    EMAIndicator sma2 = new EMAIndicator(closePriceIndicator, sma2Value);
    EMAIndicator sma3 = new EMAIndicator(closePriceIndicator, sma3Value);
    Rule buyingRule = new CrossedUpIndicatorRule(sma1, sma2).and(new OverIndicatorRule(sma2, sma3));
    Rule sellingRule = new CrossedDownIndicatorRule(sma1, sma3);
    // .or(new CrossedDownIndicatorRule(sma2, sma3));
    final BaseStrategy strategy = new BaseStrategy(buyingRule, sellingRule);
    return strategy;
}
Also used : OverIndicatorRule(org.ta4j.core.trading.rules.OverIndicatorRule) EMAIndicator(org.ta4j.core.indicators.EMAIndicator) CrossedUpIndicatorRule(org.ta4j.core.trading.rules.CrossedUpIndicatorRule) CrossedDownIndicatorRule(org.ta4j.core.trading.rules.CrossedDownIndicatorRule) BaseStrategy(org.ta4j.core.BaseStrategy) Rule(org.ta4j.core.Rule) OverIndicatorRule(org.ta4j.core.trading.rules.OverIndicatorRule) CrossedDownIndicatorRule(org.ta4j.core.trading.rules.CrossedDownIndicatorRule) CrossedUpIndicatorRule(org.ta4j.core.trading.rules.CrossedUpIndicatorRule)

Aggregations

CrossedDownIndicatorRule (org.ta4j.core.trading.rules.CrossedDownIndicatorRule)8 CrossedUpIndicatorRule (org.ta4j.core.trading.rules.CrossedUpIndicatorRule)7 OverIndicatorRule (org.ta4j.core.trading.rules.OverIndicatorRule)5 BaseStrategy (org.ta4j.core.BaseStrategy)4 Rule (org.ta4j.core.Rule)4 EMAIndicator (org.ta4j.core.indicators.EMAIndicator)4 ClosePriceIndicator (org.ta4j.core.indicators.helpers.ClosePriceIndicator)4 RSIIndicator (org.ta4j.core.indicators.RSIIndicator)3 SMAIndicator (org.ta4j.core.indicators.SMAIndicator)3 StopLossRule (org.ta4j.core.trading.rules.StopLossRule)3 UnderIndicatorRule (org.ta4j.core.trading.rules.UnderIndicatorRule)3 StochasticOscillatorKIndicator (org.ta4j.core.indicators.StochasticOscillatorKIndicator)2 StopGainRule (org.ta4j.core.trading.rules.StopGainRule)2 Test (org.junit.Test)1 CashFlow (org.ta4j.core.analysis.CashFlow)1 AverageProfitableTradesCriterion (org.ta4j.core.analysis.criteria.AverageProfitableTradesCriterion)1 RewardRiskRatioCriterion (org.ta4j.core.analysis.criteria.RewardRiskRatioCriterion)1 TotalProfitCriterion (org.ta4j.core.analysis.criteria.TotalProfitCriterion)1 VersusBuyAndHoldCriterion (org.ta4j.core.analysis.criteria.VersusBuyAndHoldCriterion)1 MACDIndicator (org.ta4j.core.indicators.MACDIndicator)1