use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class PercentBIndicator method calculate.
@Override
protected Decimal calculate(int index) {
Decimal value = indicator.getValue(index);
Decimal upValue = bbu.getValue(index);
Decimal lowValue = bbl.getValue(index);
return value.minus(lowValue).dividedBy(upValue.minus(lowValue));
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class BearishEngulfingIndicator method calculate.
@Override
protected Boolean calculate(int index) {
if (index < 1) {
// Engulfing 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.isGreaterThan(prevClosePrice) && currClosePrice.isLessThan(prevOpenPrice) && currClosePrice.isLessThan(prevClosePrice);
}
return false;
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class CashFlow method fillToTheEnd.
/**
* Fills with last value till the end of the series.
*/
private void fillToTheEnd() {
if (timeSeries.getEndIndex() >= values.size()) {
Decimal lastValue = values.get(values.size() - 1);
values.addAll(Collections.nCopies(timeSeries.getEndIndex() - values.size() + 1, lastValue));
}
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class PivotPointIndicator method calcPivotPoint.
private Decimal calcPivotPoint(List<Integer> barsOfPreviousPeriod) {
if (barsOfPreviousPeriod.isEmpty())
return Decimal.NaN;
Bar bar = getTimeSeries().getBar(barsOfPreviousPeriod.get(0));
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);
}
return (high.plus(low).plus(close)).dividedBy(Decimal.THREE);
}
use of org.ta4j.core.Decimal in project ta4j by ta4j.
the class StandardReversalIndicator method calculateS3.
private Decimal calculateS3(List<Integer> barsOfPreviousPeriod, int index) {
Bar bar = getTimeSeries().getBar(barsOfPreviousPeriod.get(0));
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);
}
return low.minus(Decimal.TWO.multipliedBy((high.minus(pivotPointIndicator.getValue(index)))));
}
Aggregations