Search in sources :

Example 81 with Decimal

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

the class ChaikinMoneyFlowIndicator method calculate.

@Override
protected Decimal calculate(int index) {
    int startIndex = Math.max(0, index - timeFrame + 1);
    Decimal sumOfMoneyFlowVolume = Decimal.ZERO;
    for (int i = startIndex; i <= index; i++) {
        sumOfMoneyFlowVolume = sumOfMoneyFlowVolume.plus(getMoneyFlowVolume(i));
    }
    Decimal sumOfVolume = volumeIndicator.getValue(index);
    return sumOfMoneyFlowVolume.dividedBy(sumOfVolume);
}
Also used : Decimal(org.ta4j.core.Decimal)

Example 82 with Decimal

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

the class IIIIndicator method calculate.

@Override
protected Decimal calculate(int index) {
    if (index == getTimeSeries().getBeginIndex()) {
        return Decimal.ZERO;
    }
    Decimal doubleClosePrice = Decimal.valueOf(2).multipliedBy(closePriceIndicator.getValue(index));
    Decimal highmlow = maxPriceIndicator.getValue(index).minus(minPriceIndicator.getValue(index));
    Decimal highplow = maxPriceIndicator.getValue(index).plus(minPriceIndicator.getValue(index));
    return (doubleClosePrice.minus(highplow)).dividedBy(highmlow.multipliedBy(volumeIndicator.getValue(index)));
}
Also used : Decimal(org.ta4j.core.Decimal)

Example 83 with Decimal

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

the class DeMarkPivotPointIndicator method calcPivotPoint.

private Decimal calcPivotPoint(List<Integer> barsOfPreviousPeriod) {
    if (barsOfPreviousPeriod.isEmpty())
        return Decimal.NaN;
    Bar bar = getTimeSeries().getBar(barsOfPreviousPeriod.get(0));
    Decimal open = getTimeSeries().getBar(barsOfPreviousPeriod.get(barsOfPreviousPeriod.size() - 1)).getOpenPrice();
    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);
    }
    Decimal x;
    if (close.isLessThan(open)) {
        x = high.plus(Decimal.TWO.multipliedBy(low)).plus(close);
    } else if (close.isGreaterThan(open)) {
        x = Decimal.TWO.multipliedBy(high).plus(low).plus(close);
    } else {
        x = high.plus(low).plus(Decimal.TWO.multipliedBy(close));
    }
    return x.dividedBy(Decimal.valueOf(4));
}
Also used : Bar(org.ta4j.core.Bar) Decimal(org.ta4j.core.Decimal)

Example 84 with Decimal

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

the class DeMarkReversalIndicator method calculate.

@Override
protected Decimal calculate(int index) {
    Decimal x = pivotPointIndicator.getValue(index).multipliedBy(Decimal.valueOf(4));
    Decimal result;
    if (level == DeMarkPivotLevel.SUPPORT) {
        result = calculateSupport(x, index);
    } else {
        result = calculateResistance(x, index);
    }
    return result;
}
Also used : Decimal(org.ta4j.core.Decimal)

Example 85 with Decimal

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

the class DeMarkReversalIndicator method calculateSupport.

private Decimal calculateSupport(Decimal x, int index) {
    List<Integer> barsOfPreviousPeriod = pivotPointIndicator.getBarsOfPreviousPeriod(index);
    if (barsOfPreviousPeriod.isEmpty()) {
        return Decimal.NaN;
    }
    Bar bar = getTimeSeries().getBar(barsOfPreviousPeriod.get(0));
    Decimal high = bar.getMaxPrice();
    for (int i : barsOfPreviousPeriod) {
        high = getTimeSeries().getBar(i).getMaxPrice().max(high);
    }
    return x.dividedBy(Decimal.TWO).minus(high);
}
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