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());
}
}
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);
}
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)));
}
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;
}
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);
}
Aggregations