Search in sources :

Example 71 with Bar

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);
}
Also used : Bar(org.ta4j.core.Bar) Decimal(org.ta4j.core.Decimal)

Example 72 with Bar

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);
    }
}
Also used : Bar(org.ta4j.core.Bar) Decimal(org.ta4j.core.Decimal)

Example 73 with Bar

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));
}
Also used : Bar(org.ta4j.core.Bar) Decimal(org.ta4j.core.Decimal)

Example 74 with Bar

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);
}
Also used : Bar(org.ta4j.core.Bar) Decimal(org.ta4j.core.Decimal)

Example 75 with Bar

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;
}
Also used : Bar(org.ta4j.core.Bar) Decimal(org.ta4j.core.Decimal)

Aggregations

Bar (org.ta4j.core.Bar)104 ArrayList (java.util.ArrayList)60 MockBar (org.ta4j.core.mocks.MockBar)48 MockTimeSeries (org.ta4j.core.mocks.MockTimeSeries)42 Before (org.junit.Before)37 Test (org.junit.Test)33 Decimal (org.ta4j.core.Decimal)20 IOException (java.io.IOException)16 BaseTimeSeries (org.ta4j.core.BaseTimeSeries)16 BitfinexCurrencyPair (com.github.jnidzwetzki.bitfinex.v2.entity.BitfinexCurrencyPair)15 Timeframe (com.github.jnidzwetzki.bitfinex.v2.entity.Timeframe)15 ZonedDateTime (java.time.ZonedDateTime)15 CountDownLatch (java.util.concurrent.CountDownLatch)15 BiConsumer (java.util.function.BiConsumer)15 BarMerger (com.github.jnidzwetzki.cryptobot.util.BarMerger)14 ParseException (java.text.ParseException)14 SimpleDateFormat (java.text.SimpleDateFormat)14 Assert (org.junit.Assert)14 BaseBar (org.ta4j.core.BaseBar)12 TimeSeries (org.ta4j.core.TimeSeries)9