CandlestickHammerPredicate extends AbstractAdviserPredicate { @Override public boolean apply(PriceTick priceTick) { if (priceTick.getTimestamp() > barEndTimestamp) { if (isFirstBar) { if (barEndTimestamp > 0) { isFirstBar = false; } } else if(isHammerPattern(openPrice, closePrice, highPrice, lowPrice)) { return true; } prepareNewBar(priceTick); } updateBarValues(priceTick); return false; } CandlestickHammerPredicate(PredicateExecutionContext predicateExecutionContext); @Override boolean apply(PriceTick priceTick); @Override void init(); static final String PROPERTY_TIME_FRAME; static final String PROPERTY_MINIMUM_CANDLE_SIZE; }
@Test public void testInvalidShape() throws Exception { List<PriceTick> priceTicks = createPriceTicks( INSTRUMENT, DATE_RANGE, 9928.3, 9932.5, 9920.0, 9925.5); CandlestickHammerPredicate candlestickHammerPredicate = createCandlestickHammerPredicate(); for (PriceTick priceTick : priceTicks) { if (candlestickHammerPredicate.apply(priceTick)) { fail("Predicate triggered."); } } }
@Test public void testValidHammerCandlestick() throws Exception { List<PriceTick> priceTicks = createPriceTicks( INSTRUMENT, DATE_RANGE, 9905.0, 9914.0, 9985.5, 9909.8); CandlestickHammerPredicate candlestickHammerPredicate = createCandlestickHammerPredicate(); for (PriceTick priceTick : priceTicks) { if (candlestickHammerPredicate.apply(priceTick)) { return; } } fail("Predicate not triggered."); }
@Test public void testTooSmallHammerCandlestick() throws Exception { List<PriceTick> priceTicks = createPriceTicks( INSTRUMENT, DATE_RANGE, 9909.3, 9910.3, 9902.5, 9908.0); CandlestickHammerPredicate candlestickHammerPredicate = createCandlestickHammerPredicate(); for (PriceTick priceTick : priceTicks) { if (candlestickHammerPredicate.apply(priceTick)) { fail("Predicate triggered."); } } }
@Test public void testValidInvertedHammerCandlestick() throws Exception { List<PriceTick> priceTicks = createPriceTicks( INSTRUMENT, DATE_RANGE, 10022.5, 10040.3, 10016.3, 10020.0); CandlestickHammerPredicate candlestickHammerPredicate = createCandlestickHammerPredicate(); for (PriceTick priceTick : priceTicks) { if (candlestickHammerPredicate.apply(priceTick)) { return; } } fail("Predicate not triggered."); }
@Test public void testTooSmallInvertedHammerCandlestick() throws Exception { List<PriceTick> priceTicks = createPriceTicks( INSTRUMENT, DATE_RANGE, 9965.8, 9969.0, 9963.8, 9965.0); CandlestickHammerPredicate candlestickHammerPredicate = createCandlestickHammerPredicate(); for (PriceTick priceTick : priceTicks) { if (candlestickHammerPredicate.apply(priceTick)) { fail("Predicate triggered."); } } }