use of org.ta4j.core.Bar in project ta4j by ta4j.
the class ThreeWhiteSoldiersIndicator method isGrowing.
/**
* @param index the current bar/candle index
* @return true if the current bar/candle is growing, false otherwise
*/
private boolean isGrowing(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.isGreaterThan(prevOpenPrice) && currOpenPrice.isLessThan(prevClosePrice) && // Closes above the previous close price
currClosePrice.isGreaterThan(prevClosePrice);
}
use of org.ta4j.core.Bar in project ta4j by ta4j.
the class UpperShadowIndicator 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 t.getMaxPrice().minus(closePrice);
} else {
// Bearish
return t.getMaxPrice().minus(openPrice);
}
}
use of org.ta4j.core.Bar 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.Bar 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);
}
use of org.ta4j.core.Bar 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;
}
Aggregations