use of org.ta4j.core.Decimal in project crypto-bot by jnidzwetzki.
the class EMABot method openOrder.
/**
* Execute a new open position order
* @param symbol
* @param endIndex
* @throws APIException
*/
private void openOrder(final BitfinexCurrencyPair symbol, final int endIndex) throws APIException {
final Decimal lastClosePrice = timeSeries.get(symbol).getLastBar().getClosePrice();
final Trade openTrade = getOpenTrade(symbol);
if (openTrade != null) {
logger.debug("Unable to open new trade, there is already one active {}", openTrade);
return;
}
final double amount = PositionSizeManager.getPositionSize(symbol, OrderType.BUY, bitfinexApiBroker.getWalletManager().getWallets());
final Trade trade = new Trade("EMA Strategy", TradeDirection.LONG, symbol, amount);
trade.setExpectedPriceOpen(lastClosePrice.doubleValue());
addTradeToOpenTradeList(trade);
orderManager.openTrade(trade);
}
use of org.ta4j.core.Decimal in project crypto-bot by jnidzwetzki.
the class DonchianChannelUpper method calculate.
@Override
protected Decimal calculate(int index) {
int startIndex = Math.max(0, index - timeFrame + 1);
Decimal result = indicator.getValue(index);
for (int pos = startIndex; pos <= index; pos++) {
final Decimal value = indicator.getValue(pos);
if (value.isGreaterThan(result)) {
result = value;
}
}
return result;
}
use of org.ta4j.core.Decimal 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.Decimal 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.Decimal in project ta4j by ta4j.
the class DojiIndicator method calculate.
@Override
protected Boolean calculate(int index) {
if (index < 1) {
return bodyHeightInd.getValue(index).isZero();
}
Decimal averageBodyHeight = averageBodyHeightInd.getValue(index - 1);
Decimal currentBodyHeight = bodyHeightInd.getValue(index);
return currentBodyHeight.isLessThan(averageBodyHeight.multipliedBy(factor));
}
Aggregations