@Override
    public Num calculate(BarSeries series, Position position) {
        if (position.isClosed()) {
            final int exitIndex = position.getExit().getIndex();
            final int entryIndex = position.getEntry().getIndex();
            return series.numOf(exitIndex - entryIndex + 1);
        }
        return series.zero();
    }
@Test
    public void calculateWithNoPositions() {
        MockBarSeries series = new MockBarSeries(numFunction, 100, 105, 110, 100, 95, 105);

        AnalysisCriterion numberOfBars = getCriterion();
        assertNumEquals(0, numberOfBars.calculate(series, new BaseTradingRecord()));
    }