Guys,
I ran into a weird issue. Below is the code that governs my stop losses. As
you see, the stop loss is about to be moved to secure about 20 PIPS, once
the price is about 40 PIPS above (for longs) and 40 PIPS below (for shorts)
the open price of the deal. On the hist tester this works perfectly - if
there are 10 long deals for example, all of their SLs get improved once the
rule is true. However, on the live, the only deal SL that gets improved is
the last one filled...please advise.
//stop loss long deals
for (IOrder order : engine.getOrders(instrument)) {
if (order.getState() == IOrder.State.FILLED && order.isLong()) {
if (order.getProfitLossInPips() > 40) {
order.setStopLossPrice(order.getOpenPrice() + 0.0020);
}
}
}
//stop loss short deals
for (IOrder order : engine.getOrders(instrument)) {
if (order.getState() == IOrder.State.FILLED && !order.isLong()) {
if(order.getProfitLossInPips() > 40) {
order.setStopLossPrice(order.getOpenPrice() - 0.0020);
}
}
}
Thanks for the help!