Search in sources :

Example 1 with Decimal

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

the class EMABot method openOrder.

/**
 * Execute a new open position order
 * @param symbol
 * @param endIndex
 * @throws APIException
 */
private void openOrder(final BitfinexCurrencyPair symbol, final int endIndex) throws APIException {
    final Decimal lastClosePrice = timeSeries.get(symbol).getLastBar().getClosePrice();
    final Trade openTrade = getOpenTrade(symbol);
    if (openTrade != null) {
        logger.debug("Unable to open new trade, there is already one active {}", openTrade);
        return;
    }
    final double amount = PositionSizeManager.getPositionSize(symbol, OrderType.BUY, bitfinexApiBroker.getWalletManager().getWallets());
    final Trade trade = new Trade("EMA Strategy", TradeDirection.LONG, symbol, amount);
    trade.setExpectedPriceOpen(lastClosePrice.doubleValue());
    addTradeToOpenTradeList(trade);
    orderManager.openTrade(trade);
}
Also used : Trade(com.github.jnidzwetzki.cryptobot.entity.Trade) Decimal(org.ta4j.core.Decimal)

Example 2 with Decimal

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

the class DonchianChannelUpper method calculate.

@Override
protected Decimal calculate(int index) {
    int startIndex = Math.max(0, index - timeFrame + 1);
    Decimal result = indicator.getValue(index);
    for (int pos = startIndex; pos <= index; pos++) {
        final Decimal value = indicator.getValue(pos);
        if (value.isGreaterThan(result)) {
            result = value;
        }
    }
    return result;
}
Also used : Decimal(org.ta4j.core.Decimal)

Example 3 with Decimal

use of org.ta4j.core.Decimal in project ta4j by ta4j.

the class BullishEngulfingIndicator method calculate.

@Override
protected Boolean calculate(int index) {
    if (index < 1) {
        // Engulfing is a 2-candle pattern
        return false;
    }
    Bar prevBar = series.getBar(index - 1);
    Bar currBar = series.getBar(index);
    if (prevBar.isBearish() && currBar.isBullish()) {
        final Decimal prevOpenPrice = prevBar.getOpenPrice();
        final Decimal prevClosePrice = prevBar.getClosePrice();
        final Decimal currOpenPrice = currBar.getOpenPrice();
        final Decimal currClosePrice = currBar.getClosePrice();
        return currOpenPrice.isLessThan(prevOpenPrice) && currOpenPrice.isLessThan(prevClosePrice) && currClosePrice.isGreaterThan(prevOpenPrice) && currClosePrice.isGreaterThan(prevClosePrice);
    }
    return false;
}
Also used : Bar(org.ta4j.core.Bar) Decimal(org.ta4j.core.Decimal)

Example 4 with Decimal

use of org.ta4j.core.Decimal in project ta4j by ta4j.

the class BullishHaramiIndicator method calculate.

@Override
protected Boolean calculate(int index) {
    if (index < 1) {
        // Harami is a 2-candle pattern
        return false;
    }
    Bar prevBar = series.getBar(index - 1);
    Bar currBar = series.getBar(index);
    if (prevBar.isBearish() && currBar.isBullish()) {
        final Decimal prevOpenPrice = prevBar.getOpenPrice();
        final Decimal prevClosePrice = prevBar.getClosePrice();
        final Decimal currOpenPrice = currBar.getOpenPrice();
        final Decimal currClosePrice = currBar.getClosePrice();
        return currOpenPrice.isLessThan(prevOpenPrice) && currOpenPrice.isGreaterThan(prevClosePrice) && currClosePrice.isLessThan(prevOpenPrice) && currClosePrice.isGreaterThan(prevClosePrice);
    }
    return false;
}
Also used : Bar(org.ta4j.core.Bar) Decimal(org.ta4j.core.Decimal)

Example 5 with Decimal

use of org.ta4j.core.Decimal in project ta4j by ta4j.

the class DojiIndicator method calculate.

@Override
protected Boolean calculate(int index) {
    if (index < 1) {
        return bodyHeightInd.getValue(index).isZero();
    }
    Decimal averageBodyHeight = averageBodyHeightInd.getValue(index - 1);
    Decimal currentBodyHeight = bodyHeightInd.getValue(index);
    return currentBodyHeight.isLessThan(averageBodyHeight.multipliedBy(factor));
}
Also used : Decimal(org.ta4j.core.Decimal)

Aggregations

Decimal (org.ta4j.core.Decimal)92 Bar (org.ta4j.core.Bar)20 Test (org.junit.Test)8 CorrelationCoefficientIndicator (org.ta4j.core.indicators.statistics.CorrelationCoefficientIndicator)4 Trade (org.ta4j.core.Trade)3 ClosePriceIndicator (org.ta4j.core.indicators.helpers.ClosePriceIndicator)3 Trade (com.github.jnidzwetzki.cryptobot.entity.Trade)2 CashFlow (org.ta4j.core.analysis.CashFlow)2 HighestValueIndicator (org.ta4j.core.indicators.helpers.HighestValueIndicator)2 LowestValueIndicator (org.ta4j.core.indicators.helpers.LowestValueIndicator)2 MockTimeSeries (org.ta4j.core.mocks.MockTimeSeries)2 DifferenceIndicator (org.ta4j.core.indicators.helpers.DifferenceIndicator)1