}
private void limitBTOTest(RelativeNumber buyBelow, RelativeNumber sellAbove, BigDecimal expectedBuy, BigDecimal expectedSell) {
BigDecimal startingCash = new BigDecimal("1000.00");
Portfolio portfolio = new SimplePortfolioFactory().createPortfolio(startingCash);
int id = 42;
long time = stop;
Instrument instrument = Instrument.Forex;
String symbol = "GG";
SignalAction action = SignalAction.BTO;
Integer quantity = 10;
QuantityComputable quantityComputable = new QuantityComputableFixed(quantity);
long cancelAtMs = Long.MAX_VALUE;
Duration timeInForce = Duration.GoodTilCancel;
OrderProcessorLimit processor = new OrderProcessorLimit(time, symbol, buyBelow);
Order order = new Order(null,id,instrument,symbol,action,quantityComputable,cancelAtMs,timeInForce,processor,null);
//test only the processor and do it outside the order
boolean processed = processor.process(dataProvider, portfolio, commission, order, action, quantityComputable,null);
assertTrue(processed);
BigDecimal expectedCash = startingCash.subtract(expectedBuy.multiply(new BigDecimal(quantity)).add(commission));
assertEquals(expectedBuy, processor.transactionPrice());
assertEquals(expectedCash, portfolio.cash());
assertEquals(quantity,portfolio.position("GG").quantity());
assertEquals(new BigDecimal("60"),portfolio.equity(dataProvider));
//sell to close this open position.
action = SignalAction.STC;
OrderProcessorLimit sellProcessor = new OrderProcessorLimit(time, symbol, sellAbove);
order = new Order(null, id,instrument,symbol,action,quantityComputable,cancelAtMs,timeInForce,sellProcessor,null);
//test only the processor and do it outside the order
processed = sellProcessor.process(dataProvider, portfolio, commission, order, action, quantityComputable,null);
assertTrue(processed);
expectedCash = expectedCash.add(expectedSell.multiply(new BigDecimal(quantity))).subtract(commission);
assertEquals(expectedSell, sellProcessor.transactionPrice());
assertEquals(expectedCash,portfolio.cash());
assertEquals(Integer.valueOf(0),portfolio.position("GG").quantity());
assertEquals(new BigDecimal("0"),portfolio.equity(dataProvider));
}