Search in sources :

Example 36 with Decimal

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

the class ROCVIndicator method calculate.

@Override
protected Decimal calculate(int index) {
    int nIndex = Math.max(index - timeFrame, 0);
    Decimal nPeriodsAgoValue = series.getBar(nIndex).getVolume();
    Decimal currentValue = series.getBar(index).getVolume();
    return currentValue.minus(nPeriodsAgoValue).dividedBy(nPeriodsAgoValue).multipliedBy(Decimal.HUNDRED);
}
Also used : Decimal(org.ta4j.core.Decimal)

Example 37 with Decimal

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

the class DeMarkReversalIndicator method calculateResistance.

private Decimal calculateResistance(Decimal x, int index) {
    List<Integer> barsOfPreviousPeriod = pivotPointIndicator.getBarsOfPreviousPeriod(index);
    if (barsOfPreviousPeriod.isEmpty()) {
        return Decimal.NaN;
    }
    Bar bar = getTimeSeries().getBar(barsOfPreviousPeriod.get(0));
    Decimal low = bar.getMinPrice();
    for (int i : barsOfPreviousPeriod) {
        low = getTimeSeries().getBar(i).getMinPrice().min(low);
    }
    return x.dividedBy(Decimal.TWO).minus(low);
}
Also used : Bar(org.ta4j.core.Bar) Decimal(org.ta4j.core.Decimal)

Example 38 with Decimal

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

the class InSlopeRule method isSatisfied.

@Override
public boolean isSatisfied(int index, TradingRecord tradingRecord) {
    DifferenceIndicator diff = new DifferenceIndicator(ref, prev);
    Decimal val = diff.getValue(index);
    boolean minSlopeSatisfied = minSlope.isNaN() || val.isGreaterThanOrEqual(minSlope);
    boolean maxSlopeSatisfied = maxSlope.isNaN() || val.isLessThanOrEqual(maxSlope);
    boolean isNaN = minSlope.isNaN() && maxSlope.isNaN();
    final boolean satisfied = minSlopeSatisfied && maxSlopeSatisfied && !isNaN;
    traceIsSatisfied(index, satisfied);
    return satisfied;
}
Also used : Decimal(org.ta4j.core.Decimal) DifferenceIndicator(org.ta4j.core.indicators.helpers.DifferenceIndicator)

Example 39 with Decimal

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

the class IsHighestRule method isSatisfied.

@Override
public boolean isSatisfied(int index, TradingRecord tradingRecord) {
    HighestValueIndicator highest = new HighestValueIndicator(ref, timeFrame);
    Decimal highestVal = highest.getValue(index);
    Decimal refVal = ref.getValue(index);
    final boolean satisfied = !refVal.isNaN() && !highestVal.isNaN() && refVal.equals(highestVal);
    traceIsSatisfied(index, satisfied);
    return satisfied;
}
Also used : Decimal(org.ta4j.core.Decimal) HighestValueIndicator(org.ta4j.core.indicators.helpers.HighestValueIndicator)

Example 40 with Decimal

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

the class StopGainRule method isSatisfied.

@Override
public boolean isSatisfied(int index, TradingRecord tradingRecord) {
    boolean satisfied = false;
    // No trading history or no trade opened, no gain
    if (tradingRecord != null) {
        Trade currentTrade = tradingRecord.getCurrentTrade();
        if (currentTrade.isOpened()) {
            Decimal entryPrice = currentTrade.getEntry().getPrice();
            Decimal currentPrice = closePrice.getValue(index);
            Decimal threshold = entryPrice.multipliedBy(gainRatioThreshold);
            if (currentTrade.getEntry().isBuy()) {
                satisfied = currentPrice.isGreaterThanOrEqual(threshold);
            } else {
                satisfied = currentPrice.isLessThanOrEqual(threshold);
            }
        }
    }
    traceIsSatisfied(index, satisfied);
    return satisfied;
}
Also used : Trade(org.ta4j.core.Trade) 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