use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class BearishHaramiIndicator method calculate.
@Override
protected Boolean calculate(int index) {
if (index < 1) {
// Harami is a 2-candle pattern
return false;
}
Bar prevBar = series.getBar(index - 1);
Bar currBar = series.getBar(index);
if (prevBar.isBullish() && currBar.isBearish()) {
final Decimal prevOpenPrice = prevBar.getOpenPrice();
final Decimal prevClosePrice = prevBar.getClosePrice();
final Decimal currOpenPrice = currBar.getOpenPrice();
final Decimal currClosePrice = currBar.getClosePrice();
return currOpenPrice.isGreaterThan(prevOpenPrice) && currOpenPrice.isLessThan(prevClosePrice) && currClosePrice.isGreaterThan(prevOpenPrice) && currClosePrice.isLessThan(prevClosePrice);
}
return false;
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class PVIIndicator method calculate.
@Override
protected Decimal calculate(int index) {
if (index == 0) {
return Decimal.THOUSAND;
}
Bar currentBar = series.getBar(index);
Bar previousBar = series.getBar(index - 1);
Decimal previousValue = getValue(index - 1);
if (currentBar.getVolume().isGreaterThan(previousBar.getVolume())) {
Decimal currentPrice = currentBar.getClosePrice();
Decimal previousPrice = previousBar.getClosePrice();
Decimal priceChangeRatio = currentPrice.minus(previousPrice).dividedBy(previousPrice);
return previousValue.plus(priceChangeRatio.multipliedBy(previousValue));
}
return previousValue;
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class VWAPIndicator method calculate.
@Override
protected Decimal calculate(int index) {
if (index <= 0) {
return typicalPrice.getValue(index);
}
int startIndex = Math.max(0, index - timeFrame + 1);
Decimal cumulativeTPV = Decimal.ZERO;
Decimal cumulativeVolume = Decimal.ZERO;
for (int i = startIndex; i <= index; i++) {
Decimal currentVolume = volume.getValue(i);
cumulativeTPV = cumulativeTPV.plus(typicalPrice.getValue(i).multipliedBy(currentVolume));
cumulativeVolume = cumulativeVolume.plus(currentVolume);
}
return cumulativeTPV.dividedBy(cumulativeVolume);
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class TRIndicator method calculate.
@Override
protected Decimal calculate(int index) {
Decimal ts = series.getBar(index).getMaxPrice().minus(series.getBar(index).getMinPrice());
Decimal ys = index == 0 ? Decimal.ZERO : series.getBar(index).getMaxPrice().minus(series.getBar(index - 1).getClosePrice());
Decimal yst = index == 0 ? Decimal.ZERO : series.getBar(index - 1).getClosePrice().minus(series.getBar(index).getMinPrice());
return ts.abs().max(ys.abs()).max(yst.abs());
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class HighestValueIndicator method calculate.
@Override
protected Decimal calculate(int index) {
if (indicator.getValue(index).isNaN() && timeFrame != 1)
return new HighestValueIndicator(indicator, timeFrame - 1).getValue(index - 1);
int end = Math.max(0, index - timeFrame + 1);
Decimal highest = indicator.getValue(index);
for (int i = index - 1; i >= end; i--) {
if (highest.isLessThan(indicator.getValue(i))) {
highest = indicator.getValue(i);
}
}
return highest;
}
Aggregations