@Override
    public boolean isSatisfied(int index, TradingRecord tradingRecord) {
        boolean satisfied = false;
        // No trading history or no position opened, no gain
        if (tradingRecord != null) {
            Position currentPosition = tradingRecord.getCurrentPosition();
            if (currentPosition.isOpened()) {

                Num entryPrice = currentPosition.getEntry().getNetPrice();
                Num currentPrice = referencePrice.getValue(index);
                Num gainThreshold = stopGainThreshold.getValue(index);

                if (currentPosition.getEntry().isBuy()) {
                    satisfied = currentPrice.isGreaterThanOrEqual(entryPrice.plus(gainThreshold));
                } else {
                    satisfied = currentPrice.isLessThanOrEqual(entryPrice.minus(gainThreshold));
                }
            }
        }

        return satisfied;
    }
@Test
    public void testStopGainTriggeredOnLongPosition() {
        TradingRecord tradingRecord = new BaseTradingRecord();
        tradingRecord.enter(0, series.getBar(0).getClosePrice(), series.numOf(1));

        AverageTrueRangeStopGainRule rule = new AverageTrueRangeStopGainRule(series, 3, 2.0);

        assertFalse(rule.isSatisfied(1, tradingRecord)); // Price is still below stop gain
        assertFalse(rule.isSatisfied(2, tradingRecord)); // Price is still below stop gain

        // Simulate a price rise to trigger stop gain
        series.addBar(series.getLastBar().getEndTime().plusDays(1), 16, 19, 15, 19, 1000);
        assertTrue(rule.isSatisfied(5, tradingRecord)); // Stop gain should trigger now
    }