Search in sources :

Example 6 with Rule

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

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

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

use of org.ta4j.core.Rule in project ta4j by ta4j.

the class ConvergenceDivergenceIndicator method calculateNegativeConvergenceStrict.

/**
 * @param index the actual index
 * @return true, if strict negative convergent
 */
private Boolean calculateNegativeConvergenceStrict(int index) {
    Rule refIsFalling = new IsFallingRule(ref, timeFrame);
    Rule otherIsFalling = new IsFallingRule(ref, timeFrame);
    return (refIsFalling.and(otherIsFalling)).isSatisfied(index);
}
Also used : IsFallingRule(org.ta4j.core.trading.rules.IsFallingRule) Rule(org.ta4j.core.Rule) IsFallingRule(org.ta4j.core.trading.rules.IsFallingRule) IsRisingRule(org.ta4j.core.trading.rules.IsRisingRule)

Example 10 with Rule

use of org.ta4j.core.Rule in project ta4j by ta4j.

the class ConvergenceDivergenceIndicator method calculateNegativeDivergenceStrict.

/**
 * @param index the actual index
 * @return true, if negative divergent
 */
private Boolean calculateNegativeDivergenceStrict(int index) {
    Rule refIsFalling = new IsFallingRule(ref, timeFrame);
    Rule otherIsRising = new IsRisingRule(ref, timeFrame);
    return (refIsFalling.and(otherIsRising)).isSatisfied(index);
}
Also used : IsFallingRule(org.ta4j.core.trading.rules.IsFallingRule) IsRisingRule(org.ta4j.core.trading.rules.IsRisingRule) Rule(org.ta4j.core.Rule) IsFallingRule(org.ta4j.core.trading.rules.IsFallingRule) IsRisingRule(org.ta4j.core.trading.rules.IsRisingRule)

Aggregations

Rule (org.ta4j.core.Rule)10 BaseStrategy (org.ta4j.core.BaseStrategy)6 IsFallingRule (org.ta4j.core.trading.rules.IsFallingRule)5 IsRisingRule (org.ta4j.core.trading.rules.IsRisingRule)5 OverIndicatorRule (org.ta4j.core.trading.rules.OverIndicatorRule)5 EMAIndicator (org.ta4j.core.indicators.EMAIndicator)4 CrossedDownIndicatorRule (org.ta4j.core.trading.rules.CrossedDownIndicatorRule)4 CrossedUpIndicatorRule (org.ta4j.core.trading.rules.CrossedUpIndicatorRule)3 StopLossRule (org.ta4j.core.trading.rules.StopLossRule)3 RSIIndicator (org.ta4j.core.indicators.RSIIndicator)2 SMAIndicator (org.ta4j.core.indicators.SMAIndicator)2 ClosePriceIndicator (org.ta4j.core.indicators.helpers.ClosePriceIndicator)2 UnderIndicatorRule (org.ta4j.core.trading.rules.UnderIndicatorRule)2 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 StandardDeviationIndicator (org.ta4j.core.indicators.statistics.StandardDeviationIndicator)1 AndRule (org.ta4j.core.trading.rules.AndRule)1