use of org.ta4j.core.indicators.helpers.ClosePriceIndicator in project crypto-bot by jnidzwetzki.
the class Chart method showChart.
public void showChart() {
/**
* Building chart datasets
*/
TimeSeriesCollection dataset = new TimeSeriesCollection();
dataset.addSeries(buildChartTimeSeries(timeSeries, new ClosePriceIndicator(timeSeries), symbol));
dataset.addSeries(buildChartTimeSeries(timeSeries, new EMAIndicator(new ClosePriceIndicator(timeSeries), 5), "EMA5"));
dataset.addSeries(buildChartTimeSeries(timeSeries, new EMAIndicator(new ClosePriceIndicator(timeSeries), 10), "EMA10"));
dataset.addSeries(buildChartTimeSeries(timeSeries, new EMAIndicator(new ClosePriceIndicator(timeSeries), 40), "EMA40"));
/**
* Creating the chart
*/
JFreeChart chart = // title
ChartFactory.createTimeSeriesChart(// title
"BTC", // x-axis label
"Date", // y-axis label
"Price", // data
dataset, // create legend?
true, // generate tooltips?
true, // generate URLs?
false);
XYPlot plot = (XYPlot) chart.getPlot();
DateAxis axis = (DateAxis) plot.getDomainAxis();
axis.setDateFormatOverride(new SimpleDateFormat("MM-dd-yyyy HH:mm"));
addBuySellSignals(timeSeries, strategy, plot);
displayChart(chart);
}
use of org.ta4j.core.indicators.helpers.ClosePriceIndicator 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.helpers.ClosePriceIndicator 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;
}
use of org.ta4j.core.indicators.helpers.ClosePriceIndicator in project ta4j by ta4j.
the class KeltnerChannelMiddleIndicatorTest method keltnerChannelMiddleIndicatorTest.
@Test
public void keltnerChannelMiddleIndicatorTest() {
KeltnerChannelMiddleIndicator km = new KeltnerChannelMiddleIndicator(new ClosePriceIndicator(data), 14);
assertDecimalEquals(km.getValue(13), 11764.23);
assertDecimalEquals(km.getValue(14), 11793.0687);
assertDecimalEquals(km.getValue(15), 11817.6182);
assertDecimalEquals(km.getValue(16), 11839.9944);
assertDecimalEquals(km.getValue(17), 11859.9725);
assertDecimalEquals(km.getValue(18), 11864.2335);
assertDecimalEquals(km.getValue(19), 11887.6903);
assertDecimalEquals(km.getValue(20), 11908.2609);
assertDecimalEquals(km.getValue(21), 11928.7941);
assertDecimalEquals(km.getValue(22), 11950.5749);
assertDecimalEquals(km.getValue(23), 11978.7156);
assertDecimalEquals(km.getValue(24), 12012.6402);
assertDecimalEquals(km.getValue(25), 12042.9401);
assertDecimalEquals(km.getValue(26), 12067.7868);
assertDecimalEquals(km.getValue(27), 12095.1832);
assertDecimalEquals(km.getValue(28), 12118.2508);
assertDecimalEquals(km.getValue(29), 12132.7027);
}
use of org.ta4j.core.indicators.helpers.ClosePriceIndicator in project ta4j by ta4j.
the class KeltnerChannelUpperIndicatorTest method keltnerChannelUpperIndicatorTest.
@Test
public void keltnerChannelUpperIndicatorTest() {
KeltnerChannelMiddleIndicator km = new KeltnerChannelMiddleIndicator(new ClosePriceIndicator(data), 14);
KeltnerChannelUpperIndicator ku = new KeltnerChannelUpperIndicator(km, Decimal.valueOf(2), 14);
assertDecimalEquals(ku.getValue(13), 11971.9132);
assertDecimalEquals(ku.getValue(14), 12002.3402);
assertDecimalEquals(ku.getValue(15), 12024.4032);
assertDecimalEquals(ku.getValue(16), 12040.3933);
assertDecimalEquals(ku.getValue(17), 12052.8572);
assertDecimalEquals(ku.getValue(18), 12067.9050);
assertDecimalEquals(ku.getValue(19), 12099.5025);
assertDecimalEquals(ku.getValue(20), 12110.5722);
assertDecimalEquals(ku.getValue(21), 12130.8675);
assertDecimalEquals(ku.getValue(22), 12147.7344);
assertDecimalEquals(ku.getValue(23), 12175.5937);
assertDecimalEquals(ku.getValue(24), 12208.1327);
assertDecimalEquals(ku.getValue(25), 12233.9032);
assertDecimalEquals(ku.getValue(26), 12256.9596);
assertDecimalEquals(ku.getValue(27), 12285.9094);
assertDecimalEquals(ku.getValue(28), 12301.1108);
assertDecimalEquals(ku.getValue(29), 12313.2042);
}
Aggregations