@Test public void isSatisfied() { final Decimal tradedAmount = Decimal.ONE; rule = new StopLossRule(closePrice, Decimal.valueOf("5")); assertFalse(rule.isSatisfied(0, null)); assertFalse(rule.isSatisfied(1, tradingRecord)); tradingRecord.enter(2, Decimal.valueOf("114"), tradedAmount); assertFalse(rule.isSatisfied(2, tradingRecord)); assertFalse(rule.isSatisfied(3, tradingRecord)); assertTrue(rule.isSatisfied(4, tradingRecord)); tradingRecord.exit(5); tradingRecord.enter(5, Decimal.valueOf("128"), tradedAmount); assertFalse(rule.isSatisfied(5, tradingRecord)); assertTrue(rule.isSatisfied(6, tradingRecord)); assertTrue(rule.isSatisfied(7, tradingRecord)); }
@Override public boolean isSatisfied(int index, TradingRecord tradingRecord) { boolean satisfied = false; if (tradingRecord != null) { Trade currentTrade = tradingRecord.getCurrentTrade(); if (currentTrade.isOpened()) { Decimal entryPrice = currentTrade.getEntry().getPrice(); Decimal currentPrice = closePrice.getValue(index); Decimal threshold = entryPrice.multipliedBy(lossRatioThreshold); if (currentTrade.getEntry().isBuy()) { satisfied = currentPrice.isLessThanOrEqual(threshold); } else { satisfied = currentPrice.isGreaterThanOrEqual(threshold); } } } traceIsSatisfied(index, satisfied); return satisfied; }
StopLossRule extends AbstractRule { @Override public boolean isSatisfied(int index, TradingRecord tradingRecord) { boolean satisfied = false; if (tradingRecord != null) { Trade currentTrade = tradingRecord.getCurrentTrade(); if (currentTrade.isOpened()) { Decimal entryPrice = currentTrade.getEntry().getPrice(); Decimal currentPrice = closePrice.getValue(index); Decimal threshold = entryPrice.multipliedBy(lossRatioThreshold); if (currentTrade.getEntry().isBuy()) { satisfied = currentPrice.isLessThanOrEqual(threshold); } else { satisfied = currentPrice.isGreaterThanOrEqual(threshold); } } } traceIsSatisfied(index, satisfied); return satisfied; } }
StopLossRule extends AbstractRule { @Override public boolean isSatisfied(int index, TradingRecord tradingRecord) { boolean satisfied = false; if (tradingRecord != null) { Trade currentTrade = tradingRecord.getCurrentTrade(); if (currentTrade.isOpened()) { Decimal entryPrice = currentTrade.getEntry().getPrice(); Decimal currentPrice = closePrice.getValue(index); Decimal threshold = entryPrice.multipliedBy(lossRatioThreshold); if (currentTrade.getEntry().isBuy()) { satisfied = currentPrice.isLessThanOrEqual(threshold); } else { satisfied = currentPrice.isGreaterThanOrEqual(threshold); } } } traceIsSatisfied(index, satisfied); return satisfied; } StopLossRule(ClosePriceIndicator closePrice, Decimal lossPercentage); }
StopLossRule extends AbstractRule { @Override public boolean isSatisfied(int index, TradingRecord tradingRecord) { boolean satisfied = false; if (tradingRecord != null) { Trade currentTrade = tradingRecord.getCurrentTrade(); if (currentTrade.isOpened()) { Decimal entryPrice = currentTrade.getEntry().getPrice(); Decimal currentPrice = closePrice.getValue(index); Decimal threshold = entryPrice.multipliedBy(lossRatioThreshold); if (currentTrade.getEntry().isBuy()) { satisfied = currentPrice.isLessThanOrEqual(threshold); } else { satisfied = currentPrice.isGreaterThanOrEqual(threshold); } } } traceIsSatisfied(index, satisfied); return satisfied; } StopLossRule(ClosePriceIndicator closePrice, Decimal lossPercentage); @Override boolean isSatisfied(int index, TradingRecord tradingRecord); }
StopLossRule extends AbstractRule { @Override public boolean isSatisfied(int index, TradingRecord tradingRecord) { boolean satisfied = false; if (tradingRecord != null) { Trade currentTrade = tradingRecord.getCurrentTrade(); if (currentTrade.isOpened()) { Decimal entryPrice = currentTrade.getEntry().getPrice(); Decimal currentPrice = closePrice.getValue(index); Decimal threshold = entryPrice.multipliedBy(lossRatioThreshold); if (currentTrade.getEntry().isBuy()) { satisfied = currentPrice.isLessThanOrEqual(threshold); } else { satisfied = currentPrice.isGreaterThanOrEqual(threshold); } } } traceIsSatisfied(index, satisfied); return satisfied; } StopLossRule(ClosePriceIndicator closePrice, Decimal lossPercentage); @Override boolean isSatisfied(int index, TradingRecord tradingRecord);  }