Hi,
please consider the following code:
package forum;
import java.util.*;
import com.dukascopy.api.*;
import com.dukascopy.api.IEngine.OrderCommand;
import com.dukascopy.api.IOrder.State;
public class ForumSandbox implements IStrategy {
private IEngine engine;
private IConsole console;
private IHistory history;
Period period = Period.ONE_HOUR;
Instrument instrument = Instrument.EURUSD;
IOrder order = null;
public void onStart(IContext context) throws JFException {
this.engine = context.getEngine();
this.console = context.getConsole();
this.history = context.getHistory();
this.order = engine.submitOrder("order", this.instrument, OrderCommand.SELL, 0.001);
}
public void onAccount(IAccount account) throws JFException {
}
public void onMessage(IMessage message) throws JFException {
}
public void onStop() throws JFException {
if (this.order.getState() != State.CREATED && this.order.getState() != State.CANCELED)
this.order.close();
}
public void onTick(Instrument instrument, ITick tick) throws JFException {
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
if (!instrument.equals(this.instrument) || period != this.period) return;
if (bidBar.getTime() < this.order.getCreationTime()) return;
console.getOut().println("Min high value: " + getMinHigh());
}
private double getMinHigh() throws JFException{
long orderBarTime = history.getBarStart(this.period, this.order.getCreationTime());
long lastClosedBarTime = history.getBar(this.instrument, this.period, OfferSide.BID, 1).getTime();
List<IBar> bars = history.getBars(this.instrument, this.period, OfferSide.BID, orderBarTime, lastClosedBarTime);
ArrayList<Double> barHighs = new ArrayList<Double>();
for (IBar bar : bars){
barHighs.add(bar.getHigh());
}
double lowestValue = barHighs.get(0);
for (Double barHigh : barHighs){
lowestValue = barHigh < lowestValue ? barHigh : lowestValue;
}
return lowestValue;
}
}