@Test public void emptyForFirstData() { assertThat(cut.indicate(new CandleStick(1.0, 1.0, 1.0, 1.0))).isEmpty(); }
@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);  }