use of org.ta4j.core.Bar in project ta4j by ta4j.
the class ThreeWhiteSoldiersIndicator method isWhiteSoldier.
/**
* @param index the current bar/candle index
* @return true if the current bar/candle is a white soldier, false otherwise
*/
private boolean isWhiteSoldier(int index) {
Bar prevBar = series.getBar(index - 1);
Bar currBar = series.getBar(index);
if (currBar.isBullish()) {
if (prevBar.isBearish()) {
// First soldier case
return hasVeryShortUpperShadow(index) && currBar.getOpenPrice().isGreaterThan(prevBar.getMinPrice());
} else {
return hasVeryShortUpperShadow(index) && isGrowing(index);
}
}
return false;
}
use of org.ta4j.core.Bar 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.Bar 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.Bar in project ta4j by ta4j.
the class PivotPointIndicator method getBarsOfPreviousPeriod.
/**
* Calculates the indices of the bars of the previous period
* @param index index of the current bar
* @return list of indices of the bars of the previous period
*/
public List<Integer> getBarsOfPreviousPeriod(int index) {
List<Integer> previousBars = new ArrayList<>();
if (timeLevel == TimeLevel.BARBASED) {
previousBars.add(Math.max(0, index - 1));
return previousBars;
}
if (index == 0) {
return previousBars;
}
final Bar currentBar = getTimeSeries().getBar(index);
// step back while bar-1 in same period (day, week, etc):
while (index - 1 >= getTimeSeries().getBeginIndex() && getPeriod(getTimeSeries().getBar(index - 1)) == getPeriod(currentBar)) {
index--;
}
// index = last bar in same period, index-1 = first bar in previous period
long previousPeriod = getPreviousPeriod(currentBar, index - 1);
while (index - 1 >= getTimeSeries().getBeginIndex() && getPeriod(getTimeSeries().getBar(index - 1)) == previousPeriod) {
// while bar-n in previous period
index--;
previousBars.add(index);
}
return previousBars;
}
use of org.ta4j.core.Bar 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