Search in sources :

Example 1 with BollingerBandsUpperIndicator

use of org.ta4j.core.indicators.bollinger.BollingerBandsUpperIndicator 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 2 with BollingerBandsUpperIndicator

use of org.ta4j.core.indicators.bollinger.BollingerBandsUpperIndicator in project ta4j by ta4j.

the class IndicatorsToChart method main.

public static void main(String[] args) {
    /*
          Getting time series
         */
    TimeSeries series = CsvBarsLoader.loadAppleIncSeries();
    /*
          Creating indicators
         */
    // Close price
    ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
    EMAIndicator avg14 = new EMAIndicator(closePrice, 14);
    StandardDeviationIndicator sd14 = new StandardDeviationIndicator(closePrice, 14);
    // Bollinger bands
    BollingerBandsMiddleIndicator middleBBand = new BollingerBandsMiddleIndicator(avg14);
    BollingerBandsLowerIndicator lowBBand = new BollingerBandsLowerIndicator(middleBBand, sd14);
    BollingerBandsUpperIndicator upBBand = new BollingerBandsUpperIndicator(middleBBand, sd14);
    /*
          Building chart dataset
         */
    TimeSeriesCollection dataset = new TimeSeriesCollection();
    dataset.addSeries(buildChartTimeSeries(series, closePrice, "Apple Inc. (AAPL) - NASDAQ GS"));
    dataset.addSeries(buildChartTimeSeries(series, lowBBand, "Low Bollinger Band"));
    dataset.addSeries(buildChartTimeSeries(series, upBBand, "High Bollinger Band"));
    /*
          Creating the chart
         */
    JFreeChart chart = ChartFactory.createTimeSeriesChart(// title
    "Apple Inc. 2013 Close Prices", // x-axis label
    "Date", // y-axis label
    "Price Per Unit", // 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("yyyy-MM-dd"));
    /*
          Displaying the chart
         */
    displayChart(chart);
}
Also used : DateAxis(org.jfree.chart.axis.DateAxis) TimeSeries(org.ta4j.core.TimeSeries) EMAIndicator(org.ta4j.core.indicators.EMAIndicator) BollingerBandsLowerIndicator(org.ta4j.core.indicators.bollinger.BollingerBandsLowerIndicator) XYPlot(org.jfree.chart.plot.XYPlot) TimeSeriesCollection(org.jfree.data.time.TimeSeriesCollection) BollingerBandsMiddleIndicator(org.ta4j.core.indicators.bollinger.BollingerBandsMiddleIndicator) StandardDeviationIndicator(org.ta4j.core.indicators.statistics.StandardDeviationIndicator) BollingerBandsUpperIndicator(org.ta4j.core.indicators.bollinger.BollingerBandsUpperIndicator) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator) SimpleDateFormat(java.text.SimpleDateFormat) JFreeChart(org.jfree.chart.JFreeChart)

Aggregations

BollingerBandsMiddleIndicator (org.ta4j.core.indicators.bollinger.BollingerBandsMiddleIndicator)2 BollingerBandsUpperIndicator (org.ta4j.core.indicators.bollinger.BollingerBandsUpperIndicator)2 ClosePriceIndicator (org.ta4j.core.indicators.helpers.ClosePriceIndicator)2 StandardDeviationIndicator (org.ta4j.core.indicators.statistics.StandardDeviationIndicator)2 SimpleDateFormat (java.text.SimpleDateFormat)1 JFreeChart (org.jfree.chart.JFreeChart)1 DateAxis (org.jfree.chart.axis.DateAxis)1 XYPlot (org.jfree.chart.plot.XYPlot)1 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)1 BaseStrategy (org.ta4j.core.BaseStrategy)1 Rule (org.ta4j.core.Rule)1 TimeSeries (org.ta4j.core.TimeSeries)1 EMAIndicator (org.ta4j.core.indicators.EMAIndicator)1 SMAIndicator (org.ta4j.core.indicators.SMAIndicator)1 BollingerBandsLowerIndicator (org.ta4j.core.indicators.bollinger.BollingerBandsLowerIndicator)1 OverIndicatorRule (org.ta4j.core.trading.rules.OverIndicatorRule)1 StopLossRule (org.ta4j.core.trading.rules.StopLossRule)1 UnderIndicatorRule (org.ta4j.core.trading.rules.UnderIndicatorRule)1