@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);

            int barsSinceEntry = index - tradingRecord.getCurrentPosition().getEntry().getIndex() + 1;

            if (tradingRecord.getCurrentPosition().getEntry().isBuy()) {
                HighestValueIndicator highestPrice = new HighestValueIndicator(this.referencePrice, barsSinceEntry);
                Num thresholdPrice = entryPrice.max(highestPrice.getValue(index)).minus(threshold);
                return currentPrice.isLessThan(thresholdPrice);
            } else {
                LowestValueIndicator lowestPrice = new LowestValueIndicator(this.referencePrice, barsSinceEntry);
                Num thresholdPrice = entryPrice.min(lowestPrice.getValue(index)).plus(threshold);
                return currentPrice.isGreaterThan(thresholdPrice);
            }
        }
        return false;
    }
@Test
    public void testEdgeCaseNoTrade() {
        AverageTrueRangeTrailingStopLossRule rule = new AverageTrueRangeTrailingStopLossRule(series, 3, 1.0);

        TradingRecord tradingRecord = new BaseTradingRecord();

        // No trade, so the rule should never be satisfied
        assertFalse(rule.isSatisfied(0, tradingRecord));
        assertFalse(rule.isSatisfied(1, tradingRecord));
        assertFalse(rule.isSatisfied(2, tradingRecord));
    }