Search in sources :

Example 1 with EMAIndicator

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

use of org.ta4j.core.indicators.EMAIndicator in project crypto-bot by jnidzwetzki.

the class DonchianChannelStrategy method getStrategy.

@Override
public Strategy getStrategy() {
    final MACDIndicator macd = new MACDIndicator(closePriceIndicator, 9, 26);
    final EMAIndicator emaMacd = new EMAIndicator(macd, 9);
    final Rule buyingRule = new AndRule(new IsRisingRule(donchianChannelUpper, 1), new OverIndicatorRule(macd, Decimal.valueOf(0)));
    final // new OrRule(
    Rule sellingRule = new IsFallingRule(donchianChannelLower, 1);
    // new UnderIndicatorRule(macd, emaMacd));
    final BaseStrategy strategy = new BaseStrategy(buyingRule, sellingRule);
    return strategy;
}
Also used : AndRule(org.ta4j.core.trading.rules.AndRule) OverIndicatorRule(org.ta4j.core.trading.rules.OverIndicatorRule) IsFallingRule(org.ta4j.core.trading.rules.IsFallingRule) EMAIndicator(org.ta4j.core.indicators.EMAIndicator) IsRisingRule(org.ta4j.core.trading.rules.IsRisingRule) MACDIndicator(org.ta4j.core.indicators.MACDIndicator) BaseStrategy(org.ta4j.core.BaseStrategy) Rule(org.ta4j.core.Rule) IsFallingRule(org.ta4j.core.trading.rules.IsFallingRule) OverIndicatorRule(org.ta4j.core.trading.rules.OverIndicatorRule) AndRule(org.ta4j.core.trading.rules.AndRule) IsRisingRule(org.ta4j.core.trading.rules.IsRisingRule)

Example 3 with EMAIndicator

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

use of org.ta4j.core.indicators.EMAIndicator in project ta4j by ta4j.

the class PreviousValueIndicatorTest method setUp.

@Before
public void setUp() {
    Random r = new Random();
    List<Bar> bars = new ArrayList<>();
    for (int i = 0; i < 1000; i++) {
        double open = r.nextDouble();
        double close = r.nextDouble();
        double max = Math.max(close + r.nextDouble(), open + r.nextDouble());
        double min = Math.min(0, Math.min(close - r.nextDouble(), open - r.nextDouble()));
        ZonedDateTime dateTime = ZonedDateTime.now();
        Bar bar = new BaseBar(dateTime, open, close, max, min, i);
        bars.add(bar);
    }
    this.series = new BaseTimeSeries("test", bars);
    this.openPriceIndicator = new OpenPriceIndicator(this.series);
    this.minPriceIndicator = new MinPriceIndicator(this.series);
    this.maxPriceIndicator = new MaxPriceIndicator(this.series);
    this.volumeIndicator = new VolumeIndicator(this.series);
    ClosePriceIndicator closePriceIndicator = new ClosePriceIndicator(this.series);
    this.emaIndicator = new EMAIndicator(closePriceIndicator, 20);
}
Also used : EMAIndicator(org.ta4j.core.indicators.EMAIndicator) BaseBar(org.ta4j.core.BaseBar) ArrayList(java.util.ArrayList) BaseBar(org.ta4j.core.BaseBar) Bar(org.ta4j.core.Bar) Random(java.util.Random) ZonedDateTime(java.time.ZonedDateTime) BaseTimeSeries(org.ta4j.core.BaseTimeSeries) Before(org.junit.Before)

Example 5 with EMAIndicator

use of org.ta4j.core.indicators.EMAIndicator in project ta4j by ta4j.

the class MovingMomentumStrategy method buildStrategy.

/**
 * @param series a time series
 * @return a moving momentum strategy
 */
public static Strategy buildStrategy(TimeSeries series) {
    if (series == null) {
        throw new IllegalArgumentException("Series cannot be null");
    }
    ClosePriceIndicator closePrice = new ClosePriceIndicator(series);
    // The bias is bullish when the shorter-moving average moves above the longer moving average.
    // The bias is bearish when the shorter-moving average moves below the longer moving average.
    EMAIndicator shortEma = new EMAIndicator(closePrice, 9);
    EMAIndicator longEma = new EMAIndicator(closePrice, 26);
    StochasticOscillatorKIndicator stochasticOscillK = new StochasticOscillatorKIndicator(series, 14);
    MACDIndicator macd = new MACDIndicator(closePrice, 9, 26);
    EMAIndicator emaMacd = new EMAIndicator(macd, 18);
    // Entry rule
    Rule entryRule = // Trend
    new OverIndicatorRule(shortEma, longEma).and(// Signal 1
    new CrossedDownIndicatorRule(stochasticOscillK, Decimal.valueOf(20))).and(// Signal 2
    new OverIndicatorRule(macd, emaMacd));
    // Exit rule
    Rule exitRule = // Trend
    new UnderIndicatorRule(shortEma, longEma).and(// Signal 1
    new CrossedUpIndicatorRule(stochasticOscillK, Decimal.valueOf(80))).and(// Signal 2
    new UnderIndicatorRule(macd, emaMacd));
    return new BaseStrategy(entryRule, exitRule);
}
Also used : OverIndicatorRule(org.ta4j.core.trading.rules.OverIndicatorRule) EMAIndicator(org.ta4j.core.indicators.EMAIndicator) UnderIndicatorRule(org.ta4j.core.trading.rules.UnderIndicatorRule) CrossedDownIndicatorRule(org.ta4j.core.trading.rules.CrossedDownIndicatorRule) CrossedUpIndicatorRule(org.ta4j.core.trading.rules.CrossedUpIndicatorRule) MACDIndicator(org.ta4j.core.indicators.MACDIndicator) StochasticOscillatorKIndicator(org.ta4j.core.indicators.StochasticOscillatorKIndicator) OverIndicatorRule(org.ta4j.core.trading.rules.OverIndicatorRule) CrossedDownIndicatorRule(org.ta4j.core.trading.rules.CrossedDownIndicatorRule) UnderIndicatorRule(org.ta4j.core.trading.rules.UnderIndicatorRule) CrossedUpIndicatorRule(org.ta4j.core.trading.rules.CrossedUpIndicatorRule) ClosePriceIndicator(org.ta4j.core.indicators.helpers.ClosePriceIndicator)

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