Search in sources :

Example 21 with Decimal

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

the class PercentBIndicator method calculate.

@Override
protected Decimal calculate(int index) {
    Decimal value = indicator.getValue(index);
    Decimal upValue = bbu.getValue(index);
    Decimal lowValue = bbl.getValue(index);
    return value.minus(lowValue).dividedBy(upValue.minus(lowValue));
}
Also used : Decimal(org.ta4j.core.Decimal)

Example 22 with Decimal

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

the class BearishEngulfingIndicator 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.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.isGreaterThan(prevClosePrice) && currClosePrice.isLessThan(prevOpenPrice) && currClosePrice.isLessThan(prevClosePrice);
    }
    return false;
}
Also used : Bar(org.ta4j.core.Bar) Decimal(org.ta4j.core.Decimal)

Example 23 with Decimal

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

the class CashFlow method fillToTheEnd.

/**
 * Fills with last value till the end of the series.
 */
private void fillToTheEnd() {
    if (timeSeries.getEndIndex() >= values.size()) {
        Decimal lastValue = values.get(values.size() - 1);
        values.addAll(Collections.nCopies(timeSeries.getEndIndex() - values.size() + 1, lastValue));
    }
}
Also used : Decimal(org.ta4j.core.Decimal)

Example 24 with Decimal

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

the class PivotPointIndicator method calcPivotPoint.

private Decimal calcPivotPoint(List<Integer> barsOfPreviousPeriod) {
    if (barsOfPreviousPeriod.isEmpty())
        return Decimal.NaN;
    Bar bar = getTimeSeries().getBar(barsOfPreviousPeriod.get(0));
    Decimal close = bar.getClosePrice();
    Decimal high = bar.getMaxPrice();
    Decimal low = bar.getMinPrice();
    for (int i : barsOfPreviousPeriod) {
        high = (getTimeSeries().getBar(i).getMaxPrice()).max(high);
        low = (getTimeSeries().getBar(i).getMinPrice()).min(low);
    }
    return (high.plus(low).plus(close)).dividedBy(Decimal.THREE);
}
Also used : Bar(org.ta4j.core.Bar) Decimal(org.ta4j.core.Decimal)

Example 25 with Decimal

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

the class StandardReversalIndicator method calculateS3.

private Decimal calculateS3(List<Integer> barsOfPreviousPeriod, int index) {
    Bar bar = getTimeSeries().getBar(barsOfPreviousPeriod.get(0));
    Decimal high = bar.getMaxPrice();
    Decimal low = bar.getMinPrice();
    for (int i : barsOfPreviousPeriod) {
        high = (getTimeSeries().getBar(i).getMaxPrice()).max(high);
        low = (getTimeSeries().getBar(i).getMinPrice()).min(low);
    }
    return low.minus(Decimal.TWO.multipliedBy((high.minus(pivotPointIndicator.getValue(index)))));
}
Also used : Bar(org.ta4j.core.Bar) 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