@Override
    public boolean isSatisfied(int index, TradingRecord tradingRecord) {
        if (tradingRecord != null && !tradingRecord.isClosed()) {
            Num entryPrice = tradingRecord.getCurrentPosition().getEntry().getNetPrice();
            Num currentPrice = this.referencePrice.getValue(index);
            Num threshold = this.stopLossThreshold.getValue(index);

            if (tradingRecord.getCurrentPosition().getEntry().isBuy()) {
                return currentPrice.isLessThan(entryPrice.minus(threshold));
            } else {
                return currentPrice.isGreaterThan(entryPrice.plus(threshold));
            }
        }
        return false;
    }
@Test
    public void testCustomReferencePrice() {
        ZonedDateTime initialEndDateTime = ZonedDateTime.now();

        for (int i = 0; i < 10; i++) {
            series.addBar(initialEndDateTime.plusDays(i), 100, 105, 95, 100);
        }

        ClosePriceIndicator customReference = new ClosePriceIndicator(series);
        AverageTrueRangeStopLossRule rule = new AverageTrueRangeStopLossRule(series, customReference, 5, 2);

        // Enter long position
        TradingRecord tradingRecord = new BaseTradingRecord();
        tradingRecord.enter(0, series.numOf(100), series.numOf(1));

        // Price drops below stop loss
        series.addBar(series.getLastBar().getEndTime().plusDays(1), 90, 90, 73, 73);
        assertTrue(rule.isSatisfied(series.getEndIndex(), tradingRecord));
    }