### Question:
TrailingStopLossRule extends AbstractRule { @Override public boolean isSatisfied(int index, TradingRecord tradingRecord) { boolean satisfied = false; if (tradingRecord != null) { Trade currentTrade = tradingRecord.getCurrentTrade(); if (currentTrade.isOpened()) { Num currentPrice = priceIndicator.getValue(index); int tradeIndex = currentTrade.getEntry().getIndex(); if (currentTrade.getEntry().isBuy()) { satisfied = isBuySatisfied(currentPrice, index, tradeIndex); } else { satisfied = isSellSatisfied(currentPrice, index, tradeIndex); } } } traceIsSatisfied(index, satisfied); return satisfied; } TrailingStopLossRule(PriceIndicator priceIndicator, Num lossPercentage, int barCount);  TrailingStopLossRule(PriceIndicator priceIndicator, Num lossPercentage); @Override boolean isSatisfied(int index, TradingRecord tradingRecord); Num getCurrentStopLossLimitActivation();  }### Answer:
@Test public void isSatisfiedForBuyForBarCount() { BaseTradingRecord tradingRecord = new BaseTradingRecord(OrderType.BUY); ClosePriceIndicator closePrice = new ClosePriceIndicator( new MockBarSeries(numFunction, 100, 110, 120, 130, 120, 117.00, 117.00, 130, 116.99)); TrailingStopLossRule rule = new TrailingStopLossRule(closePrice, numOf(10), 3); assertFalse(rule.isSatisfied(0, null)); assertFalse(rule.isSatisfied(1, tradingRecord)); tradingRecord.enter(2, numOf(114), numOf(1)); assertFalse(rule.isSatisfied(2, tradingRecord)); assertFalse(rule.isSatisfied(3, tradingRecord)); assertFalse(rule.isSatisfied(4, tradingRecord)); assertTrue(rule.isSatisfied(5, tradingRecord)); assertFalse(rule.isSatisfied(6, tradingRecord)); tradingRecord.exit(7); tradingRecord.enter(7, numOf(128), numOf(1)); assertFalse(rule.isSatisfied(7, tradingRecord)); assertTrue(rule.isSatisfied(8, tradingRecord)); }
@Test public void isSatisfiedForSellForBarCount() { BaseTradingRecord tradingRecord = new BaseTradingRecord(OrderType.SELL); ClosePriceIndicator closePrice = new ClosePriceIndicator( new MockBarSeries(numFunction, 100, 90, 80, 70, 70, 73, 77.00, 90, 120, 132.01)); TrailingStopLossRule rule = new TrailingStopLossRule(closePrice, numOf(10), 3); assertFalse(rule.isSatisfied(0, null)); assertFalse(rule.isSatisfied(1, tradingRecord)); tradingRecord.enter(2, numOf(84), numOf(1)); assertFalse(rule.isSatisfied(2, tradingRecord)); assertFalse(rule.isSatisfied(3, tradingRecord)); assertFalse(rule.isSatisfied(4, tradingRecord)); assertFalse(rule.isSatisfied(5, tradingRecord)); assertTrue(rule.isSatisfied(6, tradingRecord)); tradingRecord.exit(7); tradingRecord.enter(7, numOf(91), numOf(1)); assertFalse(rule.isSatisfied(7, tradingRecord)); assertTrue(rule.isSatisfied(8, tradingRecord)); }