Hello,
I have a strategy in place that needs some improvement for preventing false entries, could you please add the following to my code.
(the below is just an example for a sell signal, though both sides are required)

A trade entry should be avoided if the -di is not rising (which it is in the example) and the willr indicator is not touching the -20 line or below at the same time. This filter is valid until 4 bars after the trade entry signal of the strategy, otherwise the trade entry signal is to be cancelled.
For a buy signal, this would mean if the +di is not rising and the willr indicator is not touching the -80 line or above (at the same time) until 4 bars after the buy signal of the strategy, then this trade entry signal is to be ignored.
Below I provide the code snippets where I understand that the protection against false entries need to be added.
// PLACE ORDER
if (buySign) {
orderMgr.closeAllShortOdrers();
if(orderMgr.canAddOrder(OrderCommand.BUY)) {
if(useMinMaxStopLoss) {
orderMgr.submitOrder(OrderCommand.BUY, instrument, tick, min3);
} else {
orderMgr.submitOrder(OrderCommand.BUY, instrument, tick);
}
}
} else if (sellSign) {
orderMgr.closeAllLongOdrers();
if(orderMgr.canAddOrder(OrderCommand.SELL)) {
if(useMinMaxStopLoss) {
orderMgr.submitOrder(OrderCommand.SELL, instrument, tick, max3);
} else {
orderMgr.submitOrder(OrderCommand.SELL, instrument, tick);
}
}
}
}
public IOrder submitOrder(OrderCommand orderCommand, Instrument instr, ITick t) throws JFException {
if(!canAddOrder(orderCommand)) {
return null;
}
double stopLossPrice = 0.0;
/************************************************/
/* ORDER */
/************************************************/
private class MyOrder {
private IOrder order;
private Map<String, Object> properties;
MyOrder(IOrder order) {
this.order = order;
}
void setProperty(String key, Object value) {
if (properties == null) {
properties = new HashMap();
}
properties.put(key, value);
}
Object getProperty(String key) {
return properties.get(key);
}
void close() throws JFException {
if (order == null) {
return;
}
if (order.getState() == IOrder.State.CREATED) {
order.waitForUpdate();
}
if (order.getState() == IOrder.State.OPENED) {
order.close(); // close 1
order.waitForUpdate();
}
if (order.getState() == IOrder.State.FILLED) {
// order in state OPENNED -> close 1 -> order FILLED before CLOSED -> recieves message ORDER_ALREADY_FILLED -> close 2
order.close(); // close 2
order = null;
}
}
boolean isActive() throws JFException {
if (order != null && order.getState() != IOrder.State.CLOSED && order.getState() != IOrder.State.CANCELED) {
return true;
}
return false;
}
boolean inState(IOrder.State state) {
return order.getState() == state;
}