Search in sources :

Example 41 with Decimal

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

the class LowestValueIndicator method calculate.

@Override
protected Decimal calculate(int index) {
    if (indicator.getValue(index).isNaN() && timeFrame != 1)
        return new LowestValueIndicator(indicator, timeFrame - 1).getValue(index - 1);
    int end = Math.max(0, index - timeFrame + 1);
    Decimal lowest = indicator.getValue(index);
    for (int i = index - 1; i >= end; i--) {
        if (lowest.isGreaterThan(indicator.getValue(i))) {
            lowest = indicator.getValue(i);
        }
    }
    return lowest;
}
Also used : Decimal(org.ta4j.core.Decimal)

Example 42 with Decimal

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

the class PlusDMIndicator method calculate.

@Override
protected Decimal calculate(int index) {
    if (index == 0) {
        return Decimal.ZERO;
    }
    Decimal upMove = series.getBar(index).getMaxPrice().minus(series.getBar(index - 1).getMaxPrice());
    Decimal downMove = series.getBar(index - 1).getMinPrice().minus(series.getBar(index).getMinPrice());
    if (upMove.isGreaterThan(downMove) && upMove.isGreaterThan(Decimal.ZERO)) {
        return upMove;
    } else {
        return Decimal.ZERO;
    }
}
Also used : Decimal(org.ta4j.core.Decimal)

Example 43 with Decimal

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

the class PriceVariationIndicator method calculate.

@Override
protected Decimal calculate(int index) {
    Decimal previousBarClosePrice = series.getBar(Math.max(0, index - 1)).getClosePrice();
    Decimal currentBarClosePrice = series.getBar(index).getClosePrice();
    return currentBarClosePrice.dividedBy(previousBarClosePrice);
}
Also used : Decimal(org.ta4j.core.Decimal)

Example 44 with Decimal

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

the class TypicalPriceIndicator method calculate.

@Override
protected Decimal calculate(int index) {
    Decimal maxPrice = series.getBar(index).getMaxPrice();
    Decimal minPrice = series.getBar(index).getMinPrice();
    Decimal closePrice = series.getBar(index).getClosePrice();
    return maxPrice.plus(minPrice).plus(closePrice).dividedBy(Decimal.THREE);
}
Also used : Decimal(org.ta4j.core.Decimal)

Example 45 with Decimal

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

the class VolumeIndicator method calculate.

@Override
protected Decimal calculate(int index) {
    int startIndex = Math.max(0, index - timeFrame + 1);
    Decimal sumOfVolume = Decimal.ZERO;
    for (int i = startIndex; i <= index; i++) {
        sumOfVolume = sumOfVolume.plus(series.getBar(i).getVolume());
    }
    return sumOfVolume;
}
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