Search in sources :

Example 91 with Decimal

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

the class MinusDMIndicator 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 (downMove.isGreaterThan(upMove) && downMove.isGreaterThan(Decimal.ZERO)) {
        return downMove;
    } else {
        return Decimal.ZERO;
    }
}
Also used : Decimal(org.ta4j.core.Decimal)

Example 92 with Decimal

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

the class TypicalPriceIndicatorTest method indicatorShouldRetrieveBarMaxPrice.

@Test
public void indicatorShouldRetrieveBarMaxPrice() {
    for (int i = 0; i < 10; i++) {
        Bar bar = timeSeries.getBar(i);
        Decimal typicalPrice = bar.getMaxPrice().plus(bar.getMinPrice()).plus(bar.getClosePrice()).dividedBy(Decimal.THREE);
        assertEquals(typicalPrice, typicalPriceIndicator.getValue(i));
    }
}
Also used : Bar(org.ta4j.core.Bar) Decimal(org.ta4j.core.Decimal) Test(org.junit.Test)

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