use of org.ta4j.core.indicators.SMAIndicator in project crypto-bot by jnidzwetzki.
the class BBreakoutStrategy method getStrategy.
public Strategy getStrategy() {
final ClosePriceIndicator closePrice = new ClosePriceIndicator(timeSeries);
final SMAIndicator sma = new SMAIndicator(closePrice, bbPeriod);
final BollingerBandsMiddleIndicator bbmiddle = new BollingerBandsMiddleIndicator(sma);
final StandardDeviationIndicator sd = new StandardDeviationIndicator(closePrice, bbPeriod);
final BollingerBandsUpperIndicator bbup = new BollingerBandsUpperIndicator(bbmiddle, sd, Decimal.valueOf(deviationUp));
final BollingerBandsUpperIndicator bbdown = new BollingerBandsUpperIndicator(bbmiddle, sd, Decimal.valueOf(deviationDown));
final Rule buyingRule = new UnderIndicatorRule(closePrice, bbdown);
final Rule sellingRule = new OverIndicatorRule(closePrice, bbup).or(new StopLossRule(closePrice, Decimal.valueOf(2)));
final BaseStrategy strategy = new BaseStrategy(buyingRule, sellingRule);
return strategy;
}
use of org.ta4j.core.indicators.SMAIndicator 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);
}
use of org.ta4j.core.indicators.SMAIndicator in project ta4j by ta4j.
the class BollingerBandsMiddleIndicatorTest method bollingerBandsMiddleUsingSMA.
@Test
public void bollingerBandsMiddleUsingSMA() {
SMAIndicator sma = new SMAIndicator(new ClosePriceIndicator(data), 3);
BollingerBandsMiddleIndicator bbmSMA = new BollingerBandsMiddleIndicator(sma);
for (int i = 0; i < data.getBarCount(); i++) {
assertEquals(sma.getValue(i), bbmSMA.getValue(i));
}
}
use of org.ta4j.core.indicators.SMAIndicator in project ta4j by ta4j.
the class BollingerBandsUpperIndicatorTest method setUp.
@Before
public void setUp() {
TimeSeries data = new MockTimeSeries(1, 2, 3, 4, 3, 4, 5, 4, 3, 3, 4, 3, 2);
timeFrame = 3;
closePrice = new ClosePriceIndicator(data);
sma = new SMAIndicator(closePrice, timeFrame);
}
use of org.ta4j.core.indicators.SMAIndicator 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;
}
Aggregations