use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class LowestValueIndicator method calculate.
@Override
protected Decimal calculate(int index) {
if (indicator.getValue(index).isNaN() && timeFrame != 1)
return new LowestValueIndicator(indicator, timeFrame - 1).getValue(index - 1);
int end = Math.max(0, index - timeFrame + 1);
Decimal lowest = indicator.getValue(index);
for (int i = index - 1; i >= end; i--) {
if (lowest.isGreaterThan(indicator.getValue(i))) {
lowest = indicator.getValue(i);
}
}
return lowest;
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class PlusDMIndicator method calculate.
@Override
protected Decimal calculate(int index) {
if (index == 0) {
return Decimal.ZERO;
}
Decimal upMove = series.getBar(index).getMaxPrice().minus(series.getBar(index - 1).getMaxPrice());
Decimal downMove = series.getBar(index - 1).getMinPrice().minus(series.getBar(index).getMinPrice());
if (upMove.isGreaterThan(downMove) && upMove.isGreaterThan(Decimal.ZERO)) {
return upMove;
} else {
return Decimal.ZERO;
}
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class PriceVariationIndicator method calculate.
@Override
protected Decimal calculate(int index) {
Decimal previousBarClosePrice = series.getBar(Math.max(0, index - 1)).getClosePrice();
Decimal currentBarClosePrice = series.getBar(index).getClosePrice();
return currentBarClosePrice.dividedBy(previousBarClosePrice);
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class TypicalPriceIndicator method calculate.
@Override
protected Decimal calculate(int index) {
Decimal maxPrice = series.getBar(index).getMaxPrice();
Decimal minPrice = series.getBar(index).getMinPrice();
Decimal closePrice = series.getBar(index).getClosePrice();
return maxPrice.plus(minPrice).plus(closePrice).dividedBy(Decimal.THREE);
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class VolumeIndicator method calculate.
@Override
protected Decimal calculate(int index) {
int startIndex = Math.max(0, index - timeFrame + 1);
Decimal sumOfVolume = Decimal.ZERO;
for (int i = startIndex; i <= index; i++) {
sumOfVolume = sumOfVolume.plus(series.getBar(i).getVolume());
}
return sumOfVolume;
}
Aggregations