Search in sources :

Example 86 with Decimal

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

the class BearishHaramiIndicator 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.isBullish() && currBar.isBearish()) {
        final Decimal prevOpenPrice = prevBar.getOpenPrice();
        final Decimal prevClosePrice = prevBar.getClosePrice();
        final Decimal currOpenPrice = currBar.getOpenPrice();
        final Decimal currClosePrice = currBar.getClosePrice();
        return currOpenPrice.isGreaterThan(prevOpenPrice) && currOpenPrice.isLessThan(prevClosePrice) && currClosePrice.isGreaterThan(prevOpenPrice) && currClosePrice.isLessThan(prevClosePrice);
    }
    return false;
}
Also used : Bar(org.ta4j.core.Bar) Decimal(org.ta4j.core.Decimal)

Example 87 with Decimal

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

the class PVIIndicator method calculate.

@Override
protected Decimal calculate(int index) {
    if (index == 0) {
        return Decimal.THOUSAND;
    }
    Bar currentBar = series.getBar(index);
    Bar previousBar = series.getBar(index - 1);
    Decimal previousValue = getValue(index - 1);
    if (currentBar.getVolume().isGreaterThan(previousBar.getVolume())) {
        Decimal currentPrice = currentBar.getClosePrice();
        Decimal previousPrice = previousBar.getClosePrice();
        Decimal priceChangeRatio = currentPrice.minus(previousPrice).dividedBy(previousPrice);
        return previousValue.plus(priceChangeRatio.multipliedBy(previousValue));
    }
    return previousValue;
}
Also used : Bar(org.ta4j.core.Bar) Decimal(org.ta4j.core.Decimal)

Example 88 with Decimal

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

the class VWAPIndicator method calculate.

@Override
protected Decimal calculate(int index) {
    if (index <= 0) {
        return typicalPrice.getValue(index);
    }
    int startIndex = Math.max(0, index - timeFrame + 1);
    Decimal cumulativeTPV = Decimal.ZERO;
    Decimal cumulativeVolume = Decimal.ZERO;
    for (int i = startIndex; i <= index; i++) {
        Decimal currentVolume = volume.getValue(i);
        cumulativeTPV = cumulativeTPV.plus(typicalPrice.getValue(i).multipliedBy(currentVolume));
        cumulativeVolume = cumulativeVolume.plus(currentVolume);
    }
    return cumulativeTPV.dividedBy(cumulativeVolume);
}
Also used : Decimal(org.ta4j.core.Decimal)

Example 89 with Decimal

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

the class TRIndicator method calculate.

@Override
protected Decimal calculate(int index) {
    Decimal ts = series.getBar(index).getMaxPrice().minus(series.getBar(index).getMinPrice());
    Decimal ys = index == 0 ? Decimal.ZERO : series.getBar(index).getMaxPrice().minus(series.getBar(index - 1).getClosePrice());
    Decimal yst = index == 0 ? Decimal.ZERO : series.getBar(index - 1).getClosePrice().minus(series.getBar(index).getMinPrice());
    return ts.abs().max(ys.abs()).max(yst.abs());
}
Also used : Decimal(org.ta4j.core.Decimal)

Example 90 with Decimal

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

the class HighestValueIndicator method calculate.

@Override
protected Decimal calculate(int index) {
    if (indicator.getValue(index).isNaN() && timeFrame != 1)
        return new HighestValueIndicator(indicator, timeFrame - 1).getValue(index - 1);
    int end = Math.max(0, index - timeFrame + 1);
    Decimal highest = indicator.getValue(index);
    for (int i = index - 1; i >= end; i--) {
        if (highest.isLessThan(indicator.getValue(i))) {
            highest = indicator.getValue(i);
        }
    }
    return highest;
}
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