@Test public void calculateWithOneTrade() { TimeSeries series = new MockTimeSeries(100d, 95d, 102d, 105d, 97d, 113d); Trade trade = new Trade(Order.buyAt(0), Order.sellAt(1)); AverageProfitableTradesCriterion average = new AverageProfitableTradesCriterion(); assertEquals(0d, average.calculate(series, trade), TATestsUtils.TA_OFFSET); trade = new Trade(Order.buyAt(1), Order.sellAt(2)); assertEquals(1d, average.calculate(series, trade), TATestsUtils.TA_OFFSET); }
@Override public double calculate(TimeSeries series, Trade trade) { int entryIndex = trade.getEntry().getIndex(); int exitIndex = trade.getExit().getIndex(); Decimal result; if (trade.getEntry().isBuy()) { result = series.getTick(exitIndex).getClosePrice().dividedBy(series.getTick(entryIndex).getClosePrice()); } else { result = series.getTick(entryIndex).getClosePrice().dividedBy(series.getTick(exitIndex).getClosePrice()); } return (result.isGreaterThan(Decimal.ONE)) ? 1d : 0d; }
AverageProfitableTradesCriterion extends AbstractAnalysisCriterion { @Override public double calculate(TimeSeries series, Trade trade) { int entryIndex = trade.getEntry().getIndex(); int exitIndex = trade.getExit().getIndex(); Decimal result; if (trade.getEntry().isBuy()) { result = series.getTick(exitIndex).getClosePrice().dividedBy(series.getTick(entryIndex).getClosePrice()); } else { result = series.getTick(entryIndex).getClosePrice().dividedBy(series.getTick(exitIndex).getClosePrice()); } return (result.isGreaterThan(Decimal.ONE)) ? 1d : 0d; } }
AverageProfitableTradesCriterion extends AbstractAnalysisCriterion { @Override public double calculate(TimeSeries series, Trade trade) { int entryIndex = trade.getEntry().getIndex(); int exitIndex = trade.getExit().getIndex(); Decimal result; if (trade.getEntry().isBuy()) { result = series.getTick(exitIndex).getClosePrice().dividedBy(series.getTick(entryIndex).getClosePrice()); } else { result = series.getTick(entryIndex).getClosePrice().dividedBy(series.getTick(exitIndex).getClosePrice()); } return (result.isGreaterThan(Decimal.ONE)) ? 1d : 0d; }  }
AverageProfitableTradesCriterion extends AbstractAnalysisCriterion { @Override public double calculate(TimeSeries series, Trade trade) { int entryIndex = trade.getEntry().getIndex(); int exitIndex = trade.getExit().getIndex(); Decimal result; if (trade.getEntry().isBuy()) { result = series.getTick(exitIndex).getClosePrice().dividedBy(series.getTick(entryIndex).getClosePrice()); } else { result = series.getTick(entryIndex).getClosePrice().dividedBy(series.getTick(exitIndex).getClosePrice()); } return (result.isGreaterThan(Decimal.ONE)) ? 1d : 0d; }  @Override double calculate(TimeSeries series, Trade trade); @Override double calculate(TimeSeries series, TradingRecord tradingRecord); @Override boolean betterThan(double criterionValue1, double criterionValue2); }
AverageProfitableTradesCriterion extends AbstractAnalysisCriterion { @Override public double calculate(TimeSeries series, Trade trade) { int entryIndex = trade.getEntry().getIndex(); int exitIndex = trade.getExit().getIndex(); Decimal result; if (trade.getEntry().isBuy()) { result = series.getTick(exitIndex).getClosePrice().dividedBy(series.getTick(entryIndex).getClosePrice()); } else { result = series.getTick(entryIndex).getClosePrice().dividedBy(series.getTick(exitIndex).getClosePrice()); } return (result.isGreaterThan(Decimal.ONE)) ? 1d : 0d; }  @Override double calculate(TimeSeries series, Trade trade); @Override double calculate(TimeSeries series, TradingRecord tradingRecord); @Override boolean betterThan(double criterionValue1, double criterionValue2);  }