@Test public void zeroWhenVolatilityIsZeroAndThereIsNoGap() { cut.indicate(new CandleStick(new Price(50), new Price(80), new Price(10), new Price(20))); final Optional<Price> tr = cut .indicate(new CandleStick(new Price(20), new Price(20), new Price(20), new Price(20))); assertThat(tr).contains(new Price(0)); }
@Override public Optional<Price> indicate(final C current) { if (lastClose == null) { lastClose = current.getClose(); return Optional.empty(); } final long volatility = current.getVolatility().asPipette(); final long closeToHigh = current.getHigh().asPipette() - lastClose.asPipette(); final long closeToLow = lastClose.asPipette() - current.getLow().asPipette(); lastClose = current.getClose(); return Optional.of(new Price(max(volatility, max(closeToHigh, closeToLow)))); }
TrueRange implements Indicator<Price, C> { @Override public Optional<Price> indicate(final C current) { if (lastClose == null) { lastClose = current.getClose(); return Optional.empty(); } final long volatility = current.getVolatility().asPipette(); final long closeToHigh = current.getHigh().asPipette() - lastClose.asPipette(); final long closeToLow = lastClose.asPipette() - current.getLow().asPipette(); lastClose = current.getClose(); return Optional.of(new Price(max(volatility, max(closeToHigh, closeToLow)))); } }
TrueRange implements Indicator<Price, C> { @Override public Optional<Price> indicate(final C current) { if (lastClose == null) { lastClose = current.getClose(); return Optional.empty(); } final long volatility = current.getVolatility().asPipette(); final long closeToHigh = current.getHigh().asPipette() - lastClose.asPipette(); final long closeToLow = lastClose.asPipette() - current.getLow().asPipette(); lastClose = current.getClose(); return Optional.of(new Price(max(volatility, max(closeToHigh, closeToLow)))); }  }
TrueRange implements Indicator<Price, C> { @Override public Optional<Price> indicate(final C current) { if (lastClose == null) { lastClose = current.getClose(); return Optional.empty(); } final long volatility = current.getVolatility().asPipette(); final long closeToHigh = current.getHigh().asPipette() - lastClose.asPipette(); final long closeToLow = lastClose.asPipette() - current.getLow().asPipette(); lastClose = current.getClose(); return Optional.of(new Price(max(volatility, max(closeToHigh, closeToLow)))); }  @Override Optional<Price> indicate(final C current); }
TrueRange implements Indicator<Price, C> { @Override public Optional<Price> indicate(final C current) { if (lastClose == null) { lastClose = current.getClose(); return Optional.empty(); } final long volatility = current.getVolatility().asPipette(); final long closeToHigh = current.getHigh().asPipette() - lastClose.asPipette(); final long closeToLow = lastClose.asPipette() - current.getLow().asPipette(); lastClose = current.getClose(); return Optional.of(new Price(max(volatility, max(closeToHigh, closeToLow)))); }  @Override Optional<Price> indicate(final C current);  }