@Test public void downFractalsPositiveCase2() { final Stream<CandleStick> candleData = candleStickStream(new double[][] { { 1.094, 1.10, 1.08, 1.096 }, { 1.096, 1.11, 1.07, 1.081 }, { 1.081, 1.08, 1.06, 1.080 }, { 1.080, 1.12, 1.08, 1.107 }, { 1.107, 1.11, 1.10, 1.108 }, { 1.108, 1.10, 1.08, 1.095 }, { 1.095, 1.11, 1.07, 1.070 }, { 1.070, 1.07, 1.05, 1.064 }, { 1.064, 1.07, 1.06, 1.069 }, { 1.081, 1.09, 1.08, 1.082 }, }); final List<Optional<MarketDirection>> fractals = candleData.map((stick) -> downFractals.indicate(stick)) .collect(Collectors.toList()); assertThat(fractals).containsExactly(UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, DOWN, UNKNOWN, UNKNOWN, UNKNOWN, UNKNOWN, DOWN); }
@Override public Optional<MarketDirection> indicate(final C candle) { sticks.add(candle); if (sticks.size() < 5) { return Optional.empty(); } final Price[] high = new Price[] { getBest(0), getBest(1), getBest(2), getBest(3), getBest(4) }; sticks.remove(0); final boolean isUpFractal = high[0].isWeakerThan(high[2], direction) && high[1].isWeakerThan(high[2], direction) && high[2].isStrongerThan(high[3], direction) && high[2].isStrongerThan(high[4], direction); return isUpFractal ? Optional.of(direction) : Optional.empty(); }
FractalIndicator implements Indicator<MarketDirection, C> { @Override public Optional<MarketDirection> indicate(final C candle) { sticks.add(candle); if (sticks.size() < 5) { return Optional.empty(); } final Price[] high = new Price[] { getBest(0), getBest(1), getBest(2), getBest(3), getBest(4) }; sticks.remove(0); final boolean isUpFractal = high[0].isWeakerThan(high[2], direction) && high[1].isWeakerThan(high[2], direction) && high[2].isStrongerThan(high[3], direction) && high[2].isStrongerThan(high[4], direction); return isUpFractal ? Optional.of(direction) : Optional.empty(); } }
FractalIndicator implements Indicator<MarketDirection, C> { @Override public Optional<MarketDirection> indicate(final C candle) { sticks.add(candle); if (sticks.size() < 5) { return Optional.empty(); } final Price[] high = new Price[] { getBest(0), getBest(1), getBest(2), getBest(3), getBest(4) }; sticks.remove(0); final boolean isUpFractal = high[0].isWeakerThan(high[2], direction) && high[1].isWeakerThan(high[2], direction) && high[2].isStrongerThan(high[3], direction) && high[2].isStrongerThan(high[4], direction); return isUpFractal ? Optional.of(direction) : Optional.empty(); } FractalIndicator(final MarketDirection direction); }
FractalIndicator implements Indicator<MarketDirection, C> { @Override public Optional<MarketDirection> indicate(final C candle) { sticks.add(candle); if (sticks.size() < 5) { return Optional.empty(); } final Price[] high = new Price[] { getBest(0), getBest(1), getBest(2), getBest(3), getBest(4) }; sticks.remove(0); final boolean isUpFractal = high[0].isWeakerThan(high[2], direction) && high[1].isWeakerThan(high[2], direction) && high[2].isStrongerThan(high[3], direction) && high[2].isStrongerThan(high[4], direction); return isUpFractal ? Optional.of(direction) : Optional.empty(); } FractalIndicator(final MarketDirection direction); @Override Optional<MarketDirection> indicate(final C candle); }
FractalIndicator implements Indicator<MarketDirection, C> { @Override public Optional<MarketDirection> indicate(final C candle) { sticks.add(candle); if (sticks.size() < 5) { return Optional.empty(); } final Price[] high = new Price[] { getBest(0), getBest(1), getBest(2), getBest(3), getBest(4) }; sticks.remove(0); final boolean isUpFractal = high[0].isWeakerThan(high[2], direction) && high[1].isWeakerThan(high[2], direction) && high[2].isStrongerThan(high[3], direction) && high[2].isStrongerThan(high[4], direction); return isUpFractal ? Optional.of(direction) : Optional.empty(); } FractalIndicator(final MarketDirection direction); @Override Optional<MarketDirection> indicate(final C candle);  }