Hello Support Team,
I have two strategies, which are working on one instrument. How to do that they works only with own orders (close and open orders). I try do this via ArrayList in onBar method, but it's not work right.
//......
private List<IOrder> ordersmystr1 = new ArrayList<IOrder>();
//............
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
.....
{
for (IOrder orderInMarket : engine.getOrders()) {
if (orderInMarket.isLong() && instrument.equals(selectedInstrument)) {
if (ordersmystr1.size() > 0){
for (IOrder order: ordersmystr1){
orderInMarket.close();
//order.close();
}
ordersmystr1.clear();
}
print("Closing Long position");
}
}
cmd = OrderCommand.SELL;
}
for (IOrder orderInMarket : engine.getOrders()) {
if (!orderInMarket.isLong() && instrument.equals(selectedInstrument)) {
if (ordersmystr1.size() > 0){
for (IOrder order: ordersmystr1){
orderInMarket.close();
//order.close();
}
ordersmystr1.clear();
}
print("Closing Short position");
}
}
cmd = OrderCommand.BUY;
}
if(cmd != null){
order = engine.submitOrder(getLabel(selectedInstrument), instrument, cmd, _lots);
ordersmystr1.add(order);
}
}
Could you provide sample with correct code?
Best regards,
vs_trade