use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class ChaikinMoneyFlowIndicator method calculate.
@Override
protected Decimal calculate(int index) {
int startIndex = Math.max(0, index - timeFrame + 1);
Decimal sumOfMoneyFlowVolume = Decimal.ZERO;
for (int i = startIndex; i <= index; i++) {
sumOfMoneyFlowVolume = sumOfMoneyFlowVolume.plus(getMoneyFlowVolume(i));
}
Decimal sumOfVolume = volumeIndicator.getValue(index);
return sumOfMoneyFlowVolume.dividedBy(sumOfVolume);
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class IIIIndicator method calculate.
@Override
protected Decimal calculate(int index) {
if (index == getTimeSeries().getBeginIndex()) {
return Decimal.ZERO;
}
Decimal doubleClosePrice = Decimal.valueOf(2).multipliedBy(closePriceIndicator.getValue(index));
Decimal highmlow = maxPriceIndicator.getValue(index).minus(minPriceIndicator.getValue(index));
Decimal highplow = maxPriceIndicator.getValue(index).plus(minPriceIndicator.getValue(index));
return (doubleClosePrice.minus(highplow)).dividedBy(highmlow.multipliedBy(volumeIndicator.getValue(index)));
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class DeMarkPivotPointIndicator method calcPivotPoint.
private Decimal calcPivotPoint(List<Integer> barsOfPreviousPeriod) {
if (barsOfPreviousPeriod.isEmpty())
return Decimal.NaN;
Bar bar = getTimeSeries().getBar(barsOfPreviousPeriod.get(0));
Decimal open = getTimeSeries().getBar(barsOfPreviousPeriod.get(barsOfPreviousPeriod.size() - 1)).getOpenPrice();
Decimal close = bar.getClosePrice();
Decimal high = bar.getMaxPrice();
Decimal low = bar.getMinPrice();
for (int i : barsOfPreviousPeriod) {
high = (getTimeSeries().getBar(i).getMaxPrice()).max(high);
low = (getTimeSeries().getBar(i).getMinPrice()).min(low);
}
Decimal x;
if (close.isLessThan(open)) {
x = high.plus(Decimal.TWO.multipliedBy(low)).plus(close);
} else if (close.isGreaterThan(open)) {
x = Decimal.TWO.multipliedBy(high).plus(low).plus(close);
} else {
x = high.plus(low).plus(Decimal.TWO.multipliedBy(close));
}
return x.dividedBy(Decimal.valueOf(4));
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class DeMarkReversalIndicator method calculate.
@Override
protected Decimal calculate(int index) {
Decimal x = pivotPointIndicator.getValue(index).multipliedBy(Decimal.valueOf(4));
Decimal result;
if (level == DeMarkPivotLevel.SUPPORT) {
result = calculateSupport(x, index);
} else {
result = calculateResistance(x, index);
}
return result;
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class DeMarkReversalIndicator method calculateSupport.
private Decimal calculateSupport(Decimal x, int index) {
List<Integer> barsOfPreviousPeriod = pivotPointIndicator.getBarsOfPreviousPeriod(index);
if (barsOfPreviousPeriod.isEmpty()) {
return Decimal.NaN;
}
Bar bar = getTimeSeries().getBar(barsOfPreviousPeriod.get(0));
Decimal high = bar.getMaxPrice();
for (int i : barsOfPreviousPeriod) {
high = getTimeSeries().getBar(i).getMaxPrice().max(high);
}
return x.dividedBy(Decimal.TWO).minus(high);
}
Aggregations