@Override
public void onBarUpdate(OrderContext ctx) {
Instrument instr = ctx.getInstrument();
float qty = (getSettings().getTradeLots() * instr.getDefaultQuantityAsFloat());
if (ctx.getAccountPosition() > 0 && instr.round(ctx.getAvgEntryPrice() - instr.getSellPrice()) >= 25) {
//System.out.println("SL triggered at price decresed by " + instr.round(ctx.getAvgEntryPrice() - instr.getSellPrice()) +"the account position " + ctx.getAccountPosition());
ctx.sell(qty);
}
if (ctx.getAccountPosition() < 0 && instr.round(instr.getBuyPrice() - ctx.getAvgEntryPrice()) >= 25) {
//System.out.println("SL triggered as price incresed by " + instr.round(instr.getBuyPrice() - ctx.getAvgEntryPrice()) +"the account position " + ctx.getAccountPosition());
ctx.buy(qty);
}
}