use of org.ta4j.core.Bar in project crypto-bot by jnidzwetzki.
the class BarMerger method closeBar.
protected void closeBar() {
if (prices.isEmpty()) {
return;
}
final double open = prices.get(0);
final double close = prices.get(prices.size() - 1);
final double high = prices.stream().mapToDouble(e -> e).max().orElse(-1);
final double low = prices.stream().mapToDouble(e -> e).min().orElse(-1);
final Instant i = Instant.ofEpochMilli(timeframeBegin + timeframe.getMilliSeconds() - 1);
final ZonedDateTime withTimezone = ZonedDateTime.ofInstant(i, Const.BITFINEX_TIMEZONE);
final Bar bar = new BaseBar(withTimezone, open, high, low, close, totalVolume);
try {
tickConsumer.accept(symbol, bar);
} catch (IllegalArgumentException e) {
// ignore time shift
}
totalVolume = 0;
prices.clear();
}
use of org.ta4j.core.Bar in project ta4j by ta4j.
the class BullishEngulfingIndicator 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.isBearish() && currBar.isBullish()) {
final Decimal prevOpenPrice = prevBar.getOpenPrice();
final Decimal prevClosePrice = prevBar.getClosePrice();
final Decimal currOpenPrice = currBar.getOpenPrice();
final Decimal currClosePrice = currBar.getClosePrice();
return currOpenPrice.isLessThan(prevOpenPrice) && currOpenPrice.isLessThan(prevClosePrice) && currClosePrice.isGreaterThan(prevOpenPrice) && currClosePrice.isGreaterThan(prevClosePrice);
}
return false;
}
use of org.ta4j.core.Bar in project ta4j by ta4j.
the class BullishHaramiIndicator 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.isBearish() && currBar.isBullish()) {
final Decimal prevOpenPrice = prevBar.getOpenPrice();
final Decimal prevClosePrice = prevBar.getClosePrice();
final Decimal currOpenPrice = currBar.getOpenPrice();
final Decimal currClosePrice = currBar.getClosePrice();
return currOpenPrice.isLessThan(prevOpenPrice) && currOpenPrice.isGreaterThan(prevClosePrice) && currClosePrice.isLessThan(prevOpenPrice) && currClosePrice.isGreaterThan(prevClosePrice);
}
return false;
}
use of org.ta4j.core.Bar in project ta4j by ta4j.
the class LowerShadowIndicator 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 openPrice.minus(t.getMinPrice());
} else {
// Bearish
return closePrice.minus(t.getMinPrice());
}
}
use of org.ta4j.core.Bar in project ta4j by ta4j.
the class ThreeBlackCrowsIndicator method isDeclining.
/**
* @param index the current bar/candle index
* @return true if the current bar/candle is declining, false otherwise
*/
private boolean isDeclining(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.isLessThan(prevOpenPrice) && currOpenPrice.isGreaterThan(prevClosePrice) && // Closes below the previous close price
currClosePrice.isLessThan(prevClosePrice);
}
Aggregations