Search in sources :

Example 6 with Decimal

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

the class LowerShadowIndicator method calculate.

@Override
protected Decimal calculate(int index) {
    Bar t = series.getBar(index);
    final Decimal openPrice = t.getOpenPrice();
    final Decimal closePrice = t.getClosePrice();
    if (closePrice.isGreaterThan(openPrice)) {
        // Bullish
        return openPrice.minus(t.getMinPrice());
    } else {
        // Bearish
        return closePrice.minus(t.getMinPrice());
    }
}
Also used : Bar(org.ta4j.core.Bar) Decimal(org.ta4j.core.Decimal)

Example 7 with Decimal

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

the class ThreeBlackCrowsIndicator method isDeclining.

/**
 * @param index the current bar/candle index
 * @return true if the current bar/candle is declining, false otherwise
 */
private boolean isDeclining(int index) {
    Bar prevBar = series.getBar(index - 1);
    Bar currBar = series.getBar(index);
    final Decimal prevOpenPrice = prevBar.getOpenPrice();
    final Decimal prevClosePrice = prevBar.getClosePrice();
    final Decimal currOpenPrice = currBar.getOpenPrice();
    final Decimal currClosePrice = currBar.getClosePrice();
    // Opens within the body of the previous candle
    return currOpenPrice.isLessThan(prevOpenPrice) && currOpenPrice.isGreaterThan(prevClosePrice) && // Closes below the previous close price
    currClosePrice.isLessThan(prevClosePrice);
}
Also used : Bar(org.ta4j.core.Bar) Decimal(org.ta4j.core.Decimal)

Example 8 with Decimal

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

the class KAMAIndicator method calculate.

@Override
protected Decimal calculate(int index) {
    Decimal currentPrice = price.getValue(index);
    if (index < timeFrameEffectiveRatio) {
        return currentPrice;
    }
    /*
         * Efficiency Ratio (ER)
         * ER = Change/Volatility
         * Change = ABS(Close - Close (10 periods ago))
         * Volatility = Sum10(ABS(Close - Prior Close))
         * Volatility is the sum of the absolute value of the last ten price changes (Close - Prior Close).
         */
    int startChangeIndex = Math.max(0, index - timeFrameEffectiveRatio);
    Decimal change = currentPrice.minus(price.getValue(startChangeIndex)).abs();
    Decimal volatility = Decimal.ZERO;
    for (int i = startChangeIndex; i < index; i++) {
        volatility = volatility.plus(price.getValue(i + 1).minus(price.getValue(i)).abs());
    }
    Decimal er = change.dividedBy(volatility);
    /*
         * Smoothing Constant (SC)
         * SC = [ER x (fastest SC - slowest SC) + slowest SC]2
         * SC = [ER x (2/(2+1) - 2/(30+1)) + 2/(30+1)]2
         */
    Decimal sc = er.multipliedBy(fastest.minus(slowest)).plus(slowest).pow(2);
    /*
         * KAMA
         * Current KAMA = Prior KAMA + SC x (Price - Prior KAMA)
         */
    Decimal priorKAMA = getValue(index - 1);
    return priorKAMA.plus(sc.multipliedBy(currentPrice.minus(priorKAMA)));
}
Also used : Decimal(org.ta4j.core.Decimal)

Example 9 with Decimal

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

the class MassIndexIndicator method calculate.

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

Example 10 with Decimal

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

the class PPOIndicator method calculate.

@Override
protected Decimal calculate(int index) {
    Decimal shortEmaValue = shortTermEma.getValue(index);
    Decimal longEmaValue = longTermEma.getValue(index);
    return shortEmaValue.minus(longEmaValue).dividedBy(longEmaValue).multipliedBy(Decimal.HUNDRED);
}
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