Hey.
I've added a condition to a strategy, that it should close an open order if onTick carries a tick.getAsk() or tick.getBid() past high/low of a stored bar.
Somehow it don't trigger half the time tho.
heres the close order trigger:
public void onTick(Instrument instrument, ITick tick) throws JFException {
if (!instrument.equals(this.instrument) || buyBar == null) {
return;
}
.........
if (enableShort && isActive(orderShort)) {
// Short Exit:
if (tick.getAsk() > buyBar.getHigh()) {
exitShort = true;
print("trigger! :"+orderShort.getLabel()+":"+buyBar.getHigh() + ":"+tick.getAsk() + ":"+tick.getTime());
}
// Exit
// Short exit
if (exitShort) {
closeOrder(orderShort);
print("kicker! :"+orderShort.getLabel()+":"+buyBar.getHigh() + ":"+tick.getAsk() + ":"+tick.getTime());
orderShort = null;
exitShort = false;
}
}
}
The buyBar is set under onBar() as follows:
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
if (!instrument.equals(this.instrument) || !period.equals(selectedPeriod)) {
return;
}
....
// Begin Short
if (enableShort ){
// Short Open: Open if bar close under ma0
if (askBar.getClose() < ma0) {
enterShort = true;
}
// Open order
if (enterShort && !isActive(orderShort)) {
orderShort = submitOrder(OrderCommand.SELL);
buyBar = askBar;
print(":"+ buyBar.getHigh());
}
enterShort = false;
// Short Exit: Bar closing past MA 0
if (askBar.getClose() > ma0) {
exitShort = true;
}
// Close order
if (exitShort) {
closeOrder(orderShort);
orderShort = null;
exitShort = false;
}
}
}
When i run this on USDJPY 1H from 4th april 2012 and till today, it'll open an order at 10:00 4/4 2012 but wont close it till 15:00 4/4 2012.
And im pretty sure even the next bar at 11:00 has a high well over 10:00 high.
Is it not reliable to store the bar I've opened an order at, and if so, how would you recommend it done instead?
Filip