You can select bars and ticks from arbitrary historical periods by using
IHisotry interface. Consider the following snippet which, for example, can be placed in in
IIindicator.onStart() method:
IConsole console = context.getConsole();
IHistory history = context.getHistory();
try {
// custom historical interval
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
Date dateFrom = dateFormat.parse("2011-07-11 11:29:00");
Date dateTo = dateFormat.parse("2011-07-11 11:30:00");
List<ITick> ticks = history.getTicks(Instrument.EURUSD, dateFrom.getTime(), dateTo.getTime());
List<IBar> bars = history.getBars(Instrument.EURUSD, Period.TEN_SECS, OfferSide.BID, dateFrom.getTime(), dateTo.getTime());
for (ITick tick : ticks)
console.getOut().println("Tick: " + tick);
for (IBar bar : bars)
console.getOut().println("Bar: " + bar);
} catch (ParseException e) {
console.getErr().println(e);
} catch (JFException e) {
console.getErr().println(e);
}
Mind to keep retrieved
List<ITick> and
List<IBar> sizes relatively low (e.g. a list of ticks over a week period will likely cause an
OutOfMemoryError, more concrete heap size limit is regulated by java settings). So if you need to work with large time intervals, but small bar periods (or ticks), it is advisable to divide your time interval in smaller ones.