@Test public void minusDMIsZeroWhenYesterdayLowHigherThanTodayLowButHighDifferenceToHigh() { dmMinus.indicate(new CandleStick(10, 15, 12, 10)); assertThat(dmMinus.indicate(new CandleStick(10, 25, 5, 10))).contains(new Price(0)); }
@Override public Optional<Price> indicate(final C candle) { if (lastCandle == null) { lastCandle = candle; return Optional.empty(); } final Price lastStrongest = lastCandle.getStrongest(direction); final Price lastWeakest = lastCandle.getWeakest(direction); final Price currentStrongest = candle.getStrongest(direction); lastCandle = candle; if (!currentStrongest.isStrongerThan(lastStrongest, direction)) { return ZERO; } final long strongestDiff = Math.abs(lastStrongest.asPipette() - currentStrongest.asPipette()); final Price currentWeakest = candle.getWeakest(direction); if (lastWeakest.isStrongerThan(currentWeakest, direction.inverted())) { return Optional.of(new Price(strongestDiff)); } final long weakestDiff = Math.abs(lastWeakest.asPipette() - currentWeakest.asPipette()); return weakestDiff > strongestDiff ? ZERO : Optional.of(new Price(strongestDiff)); }
DirectionalMovement implements Indicator<Price, C> { @Override public Optional<Price> indicate(final C candle) { if (lastCandle == null) { lastCandle = candle; return Optional.empty(); } final Price lastStrongest = lastCandle.getStrongest(direction); final Price lastWeakest = lastCandle.getWeakest(direction); final Price currentStrongest = candle.getStrongest(direction); lastCandle = candle; if (!currentStrongest.isStrongerThan(lastStrongest, direction)) { return ZERO; } final long strongestDiff = Math.abs(lastStrongest.asPipette() - currentStrongest.asPipette()); final Price currentWeakest = candle.getWeakest(direction); if (lastWeakest.isStrongerThan(currentWeakest, direction.inverted())) { return Optional.of(new Price(strongestDiff)); } final long weakestDiff = Math.abs(lastWeakest.asPipette() - currentWeakest.asPipette()); return weakestDiff > strongestDiff ? ZERO : Optional.of(new Price(strongestDiff)); } }
DirectionalMovement implements Indicator<Price, C> { @Override public Optional<Price> indicate(final C candle) { if (lastCandle == null) { lastCandle = candle; return Optional.empty(); } final Price lastStrongest = lastCandle.getStrongest(direction); final Price lastWeakest = lastCandle.getWeakest(direction); final Price currentStrongest = candle.getStrongest(direction); lastCandle = candle; if (!currentStrongest.isStrongerThan(lastStrongest, direction)) { return ZERO; } final long strongestDiff = Math.abs(lastStrongest.asPipette() - currentStrongest.asPipette()); final Price currentWeakest = candle.getWeakest(direction); if (lastWeakest.isStrongerThan(currentWeakest, direction.inverted())) { return Optional.of(new Price(strongestDiff)); } final long weakestDiff = Math.abs(lastWeakest.asPipette() - currentWeakest.asPipette()); return weakestDiff > strongestDiff ? ZERO : Optional.of(new Price(strongestDiff)); } DirectionalMovement(final MarketDirection direction); }
DirectionalMovement implements Indicator<Price, C> { @Override public Optional<Price> indicate(final C candle) { if (lastCandle == null) { lastCandle = candle; return Optional.empty(); } final Price lastStrongest = lastCandle.getStrongest(direction); final Price lastWeakest = lastCandle.getWeakest(direction); final Price currentStrongest = candle.getStrongest(direction); lastCandle = candle; if (!currentStrongest.isStrongerThan(lastStrongest, direction)) { return ZERO; } final long strongestDiff = Math.abs(lastStrongest.asPipette() - currentStrongest.asPipette()); final Price currentWeakest = candle.getWeakest(direction); if (lastWeakest.isStrongerThan(currentWeakest, direction.inverted())) { return Optional.of(new Price(strongestDiff)); } final long weakestDiff = Math.abs(lastWeakest.asPipette() - currentWeakest.asPipette()); return weakestDiff > strongestDiff ? ZERO : Optional.of(new Price(strongestDiff)); } DirectionalMovement(final MarketDirection direction); @Override Optional<Price> indicate(final C candle); }
DirectionalMovement implements Indicator<Price, C> { @Override public Optional<Price> indicate(final C candle) { if (lastCandle == null) { lastCandle = candle; return Optional.empty(); } final Price lastStrongest = lastCandle.getStrongest(direction); final Price lastWeakest = lastCandle.getWeakest(direction); final Price currentStrongest = candle.getStrongest(direction); lastCandle = candle; if (!currentStrongest.isStrongerThan(lastStrongest, direction)) { return ZERO; } final long strongestDiff = Math.abs(lastStrongest.asPipette() - currentStrongest.asPipette()); final Price currentWeakest = candle.getWeakest(direction); if (lastWeakest.isStrongerThan(currentWeakest, direction.inverted())) { return Optional.of(new Price(strongestDiff)); } final long weakestDiff = Math.abs(lastWeakest.asPipette() - currentWeakest.asPipette()); return weakestDiff > strongestDiff ? ZERO : Optional.of(new Price(strongestDiff)); } DirectionalMovement(final MarketDirection direction); @Override Optional<Price> indicate(final C candle);  }