1. How do you plan to use the price intervals in the strategy?
2. Open long and short based on previous candle open price and current price:
public void onTick(Instrument instrument, ITick tick) throws JFException {
if (instrument != this.instrument) {
return;
}
IBar previousBar = history.getBar(instrument, selectedPeriod, offerSide, 1);
if(previousBar.getOpen() < tick.getAsk()){
engine.submitOrder("order1", instrument, OrderCommand.BUY, amount, 0, slippage);
} else if(previousBar.getOpen() < tick.getBid()){
engine.submitOrder("order2", instrument, OrderCommand.SELL, amount, 0, slippage);
}
}
3. There is a strategy that uses Stochastic:
viewtopic.php?f=7&t=42704&p=60193&hilit=stochastic#p601934. Close position after some time preriod:
@Configurable("Order duration")
public int duration = 0;
@Configurable("Order duration period")
public Period period = Period.ONE_MIN;
public void onTick(Instrument instrument, ITick tick) throws JFException {
if (instrument != this.instrument) {
return;
}
if((order.getState().equals(IOrder.State.FILLED) || order.getState().equals(IOrder.State.OPENED))
&& order.getFillTime() + period.getInterval() * duration < tick.getTime()) {
order.close();
}
}
5. partial close
if(order.getProfitLossInPips() > takeProfitPips) {
if(order.getState() == IOrder.State.FILLED){
order.close(order.getAmount() / 2);
order.waitForUpdate(2000);
order.setStopLossPrice(order.getOpenPrice());
order.waitForUpdate(2000);
}
} else if (order.getProfitLossInPips() > takeProfitPips_2) {
if(order.getState() == IOrder.State.FILLED){
order.close();
}
}