Search in sources :

Example 6 with EMAIndicator

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

use of org.ta4j.core.indicators.EMAIndicator 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 8 with EMAIndicator

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

EMAIndicator (org.ta4j.core.indicators.EMAIndicator)8 OverIndicatorRule (org.ta4j.core.trading.rules.OverIndicatorRule)5 BaseStrategy (org.ta4j.core.BaseStrategy)4 Rule (org.ta4j.core.Rule)4 ClosePriceIndicator (org.ta4j.core.indicators.helpers.ClosePriceIndicator)4 CrossedDownIndicatorRule (org.ta4j.core.trading.rules.CrossedDownIndicatorRule)4 CrossedUpIndicatorRule (org.ta4j.core.trading.rules.CrossedUpIndicatorRule)3 SimpleDateFormat (java.text.SimpleDateFormat)2 JFreeChart (org.jfree.chart.JFreeChart)2 DateAxis (org.jfree.chart.axis.DateAxis)2 XYPlot (org.jfree.chart.plot.XYPlot)2 TimeSeriesCollection (org.jfree.data.time.TimeSeriesCollection)2 MACDIndicator (org.ta4j.core.indicators.MACDIndicator)2 RSIIndicator (org.ta4j.core.indicators.RSIIndicator)2 StochasticOscillatorKIndicator (org.ta4j.core.indicators.StochasticOscillatorKIndicator)2 UnderIndicatorRule (org.ta4j.core.trading.rules.UnderIndicatorRule)2 ZonedDateTime (java.time.ZonedDateTime)1 ArrayList (java.util.ArrayList)1 Random (java.util.Random)1 Before (org.junit.Before)1