PriceSpikePredicate extends AbstractAdviserPredicate { @Override public boolean apply(PriceTick priceTick) { if (barOpenTimestamp <= 0 || priceTick.getTimestamp() > barCloseTimestamp) { prepareNewBar(priceTick); return false; } final double pipsVariation = getPricePips( priceTick.getClosePriceAsk() - openPriceAsk, priceMinimalDecimalPosition); if (pipsVariation >= minimumPips && ! eventDispatched) { eventDispatched = true; return true; } return false; } PriceSpikePredicate(PredicateExecutionContext predicateExecutionContext); @Override boolean apply(PriceTick priceTick); @Override void init(); static final String PROPERTY_MINIMUM_PIPS; }
@Test public void testPredicateTriggeredEURUSD() throws Exception { Iterable<PriceTick> priceTicks = TestingPriceFactory.createPriceTicks( TestingConstants.INSTRUMENT_EURUSD_ID, Range.closed( TestingConstants.DEFAULT_START_DATE.getMillis(), TestingConstants.DEFAULT_START_DATE.plusMinutes(1).getMillis()), Range.closed(1.23101, 1.23211), 1); PriceSpikePredicate priceSpikePredicate = createPriceSpikePredicate(TestingConstants.INSTRUMENT_EURUSD_ID); for (PriceTick priceTick : priceTicks) { if (priceSpikePredicate.apply(priceTick)) { return; } } fail("Predicate not triggered."); }
@Test public void testPredicateNotTriggeredEURUSD() throws Exception { Iterable<PriceTick> priceTicks = TestingPriceFactory.createPriceTicks( TestingConstants.INSTRUMENT_EURUSD_ID, Range.closed( TestingConstants.DEFAULT_START_DATE.getMillis(), TestingConstants.DEFAULT_START_DATE.plusMinutes(1).getMillis()), Range.closed(1.23101, 1.23172), 1); PriceSpikePredicate priceSpikePredicate = createPriceSpikePredicate(TestingConstants.INSTRUMENT_EURUSD_ID); for (PriceTick priceTick : priceTicks) { if (priceSpikePredicate.apply(priceTick)) { fail("Predicate triggered."); } } }
@Test public void testPredicateTriggeredDAX() throws Exception { Iterable<PriceTick> priceTicks = TestingPriceFactory.createPriceTicks( TestingConstants.INSTRUMENT_DAX_ID, Range.closed( TestingConstants.DEFAULT_START_DATE.getMillis(), TestingConstants.DEFAULT_START_DATE.plusMinutes(1).getMillis()), Range.closed(9983.16, 9993.17), 1); PriceSpikePredicate priceSpikePredicate = createPriceSpikePredicate(TestingConstants.INSTRUMENT_DAX_ID); for (PriceTick priceTick : priceTicks) { if (priceSpikePredicate.apply(priceTick)) { return; } } fail("Predicate not triggered."); }
@Test public void testEventNotTriggeredDAX() throws Exception { Iterable<PriceTick> priceTicks = TestingPriceFactory.createPriceTicks( TestingConstants.INSTRUMENT_DAX_ID, Range.closed( TestingConstants.DEFAULT_START_DATE.getMillis(), TestingConstants.DEFAULT_START_DATE.plusMinutes(1).getMillis()), Range.closed(9983.16, 9985.26), 1); PriceSpikePredicate priceSpikePredicate = createPriceSpikePredicate(TestingConstants.INSTRUMENT_DAX_ID); for (PriceTick priceTick : priceTicks) { if (priceSpikePredicate.apply(priceTick)) { fail("Predicate triggered."); } } }