Search in sources :

Example 6 with BaseStrategy

use of org.ta4j.core.BaseStrategy 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 7 with BaseStrategy

use of org.ta4j.core.BaseStrategy 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)

Example 8 with BaseStrategy

use of org.ta4j.core.BaseStrategy 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)

Aggregations

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