Please consider the attached code sample. I've been battling with the SAR, specifically the FOUR_HOURS Timeframe. The value it is returning is not what the chart is showing. When I do the ONE_HOUR it returns fine.
What am I missing?
Please help, I've spent a good 4 hours trying to figure this out.
import java.util.*;
import com.dukascopy.api.*;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
public class SARTestv2 implements IStrategy {
private IEngine engine;
private IConsole console;
private IHistory history;
private IContext context;
private IIndicators indicators;
private IUserInterface userInterface;
// these are strategy parameters
private Instrument myInstrument = Instrument.EURUSD;
private Period myPeriod = Period.FOUR_HOURS;
public void onStart(IContext context) throws JFException {
// we initialise interfaces in the onStart method
engine = context.getEngine();
indicators = context.getIndicators();
console = context.getConsole();
history = context.getHistory();
console.getOut().println("Started");
}
public void onAccount(IAccount account) throws JFException {
}
public void onMessage(IMessage message) throws JFException {
}
public void onStop() throws JFException {
}
public void onTick(Instrument instrument, ITick tick) throws JFException {
}
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
if (instrument == Instrument.EURUSD && period == myPeriod){
console.getOut().println("HOURSAR:" +indicators.sar(Instrument.EURUSD, Period.ONE_HOUR, OfferSide.BID, 0.01, 0.1, 0));
console.getOut().println("FOURHOURSAR:" +indicators.sar(Instrument.EURUSD, Period.FOUR_HOURS, OfferSide.BID, 0.01, 0.1, 0));
}
}
}