@Test public void isSatisfiedWorksForSell() { final TradingRecord tradingRecord = new BaseTradingRecord(Order.OrderType.SELL); final Num tradedAmount = numOf(1); StopGainRule rule = new StopGainRule(closePrice, numOf(10)); assertFalse(rule.isSatisfied(0, null)); assertFalse(rule.isSatisfied(1, tradingRecord)); tradingRecord.enter(7, numOf(178), tradedAmount); assertFalse(rule.isSatisfied(7, tradingRecord)); assertFalse(rule.isSatisfied(8, tradingRecord)); assertTrue(rule.isSatisfied(9, tradingRecord)); tradingRecord.exit(10); tradingRecord.enter(3, numOf(119), tradedAmount); assertFalse(rule.isSatisfied(3, tradingRecord)); assertFalse(rule.isSatisfied(2, tradingRecord)); assertTrue(rule.isSatisfied(1, tradingRecord)); assertTrue(rule.isSatisfied(10, tradingRecord)); }
@Override public boolean isSatisfied(int index, TradingRecord tradingRecord) { boolean satisfied = false; if (tradingRecord != null) { Trade currentTrade = tradingRecord.getCurrentTrade(); if (currentTrade.isOpened()) { Num entryPrice = currentTrade.getEntry().getNetPrice(); Num currentPrice = closePrice.getValue(index); if (currentTrade.getEntry().isBuy()) { satisfied = isBuyGainSatisfied(entryPrice, currentPrice); } else { satisfied = isSellGainSatisfied(entryPrice, currentPrice); } } } traceIsSatisfied(index, satisfied); return satisfied; }
StopGainRule extends AbstractRule { @Override public boolean isSatisfied(int index, TradingRecord tradingRecord) { boolean satisfied = false; if (tradingRecord != null) { Trade currentTrade = tradingRecord.getCurrentTrade(); if (currentTrade.isOpened()) { Num entryPrice = currentTrade.getEntry().getNetPrice(); Num currentPrice = closePrice.getValue(index); if (currentTrade.getEntry().isBuy()) { satisfied = isBuyGainSatisfied(entryPrice, currentPrice); } else { satisfied = isSellGainSatisfied(entryPrice, currentPrice); } } } traceIsSatisfied(index, satisfied); return satisfied; } }
StopGainRule extends AbstractRule { @Override public boolean isSatisfied(int index, TradingRecord tradingRecord) { boolean satisfied = false; if (tradingRecord != null) { Trade currentTrade = tradingRecord.getCurrentTrade(); if (currentTrade.isOpened()) { Num entryPrice = currentTrade.getEntry().getNetPrice(); Num currentPrice = closePrice.getValue(index); if (currentTrade.getEntry().isBuy()) { satisfied = isBuyGainSatisfied(entryPrice, currentPrice); } else { satisfied = isSellGainSatisfied(entryPrice, currentPrice); } } } traceIsSatisfied(index, satisfied); return satisfied; } StopGainRule(ClosePriceIndicator closePrice, Number gainPercentage);  StopGainRule(ClosePriceIndicator closePrice, Num gainPercentage); }
StopGainRule extends AbstractRule { @Override public boolean isSatisfied(int index, TradingRecord tradingRecord) { boolean satisfied = false; if (tradingRecord != null) { Trade currentTrade = tradingRecord.getCurrentTrade(); if (currentTrade.isOpened()) { Num entryPrice = currentTrade.getEntry().getNetPrice(); Num currentPrice = closePrice.getValue(index); if (currentTrade.getEntry().isBuy()) { satisfied = isBuyGainSatisfied(entryPrice, currentPrice); } else { satisfied = isSellGainSatisfied(entryPrice, currentPrice); } } } traceIsSatisfied(index, satisfied); return satisfied; } StopGainRule(ClosePriceIndicator closePrice, Number gainPercentage);  StopGainRule(ClosePriceIndicator closePrice, Num gainPercentage); @Override boolean isSatisfied(int index, TradingRecord tradingRecord); }
StopGainRule extends AbstractRule { @Override public boolean isSatisfied(int index, TradingRecord tradingRecord) { boolean satisfied = false; if (tradingRecord != null) { Trade currentTrade = tradingRecord.getCurrentTrade(); if (currentTrade.isOpened()) { Num entryPrice = currentTrade.getEntry().getNetPrice(); Num currentPrice = closePrice.getValue(index); if (currentTrade.getEntry().isBuy()) { satisfied = isBuyGainSatisfied(entryPrice, currentPrice); } else { satisfied = isSellGainSatisfied(entryPrice, currentPrice); } } } traceIsSatisfied(index, satisfied); return satisfied; } StopGainRule(ClosePriceIndicator closePrice, Number gainPercentage);  StopGainRule(ClosePriceIndicator closePrice, Num gainPercentage); @Override boolean isSatisfied(int index, TradingRecord tradingRecord);  }