Search in sources :

Example 1 with ClosePriceIndicator

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);
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) EMAIndicator(org.ta4j.core.indicators.EMAIndicator) XYPlot(org.jfree.chart.plot.XYPlot) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) SimpleDateFormat(java.text.SimpleDateFormat) JFreeChart(org.jfree.chart.JFreeChart)

Example 2 with ClosePriceIndicator

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;
}
Also used : SMAIndicator(org.ta4j.core.indicators.SMAIndicator) OverIndicatorRule(org.ta4j.core.trading.rules.OverIndicatorRule) UnderIndicatorRule(org.ta4j.core.trading.rules.UnderIndicatorRule) BollingerBandsMiddleIndicator(org.ta4j.core.indicators.bollinger.BollingerBandsMiddleIndicator) BaseStrategy(org.ta4j.core.BaseStrategy) StopLossRule(org.ta4j.core.trading.rules.StopLossRule) StandardDeviationIndicator(org.ta4j.core.indicators.statistics.StandardDeviationIndicator) BollingerBandsUpperIndicator(org.ta4j.core.indicators.bollinger.BollingerBandsUpperIndicator) Rule(org.ta4j.core.Rule) StopLossRule(org.ta4j.core.trading.rules.StopLossRule) OverIndicatorRule(org.ta4j.core.trading.rules.OverIndicatorRule) UnderIndicatorRule(org.ta4j.core.trading.rules.UnderIndicatorRule) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator)

Example 3 with ClosePriceIndicator

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;
}
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 4 with ClosePriceIndicator

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);
}
Also used : ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Example 5 with ClosePriceIndicator

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);
}
Also used : ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) Test(org.junit.Test)

Aggregations

ClosePriceIndicator (org.ta4j.core.indicators.helpers.ClosePriceIndicator)81 Test (org.junit.Test)55 MockTimeSeries (org.ta4j.core.mocks.MockTimeSeries)26 TimeSeries (org.ta4j.core.TimeSeries)16 Before (org.junit.Before)14 SMAIndicator (org.ta4j.core.indicators.SMAIndicator)7 OverIndicatorRule (org.ta4j.core.trading.rules.OverIndicatorRule)6 ArrayList (java.util.ArrayList)5 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)5 MockBar (org.ta4j.core.mocks.MockBar)5 UnderIndicatorRule (org.ta4j.core.trading.rules.UnderIndicatorRule)5 SimpleDateFormat (java.text.SimpleDateFormat)4 JFreeChart (org.jfree.chart.JFreeChart)4 DateAxis (org.jfree.chart.axis.DateAxis)4 XYPlot (org.jfree.chart.plot.XYPlot)4 EMAIndicator (org.ta4j.core.indicators.EMAIndicator)4 CrossedDownIndicatorRule (org.ta4j.core.trading.rules.CrossedDownIndicatorRule)4 BaseStrategy (org.ta4j.core.BaseStrategy)3 Decimal (org.ta4j.core.Decimal)3 MaxPriceIndicator (org.ta4j.core.indicators.helpers.MaxPriceIndicator)3