Hello,
Recently I started learning Java in order to develop a strategy to reduce my screen time and while I eventually did make one that works I have a problem with the H4 bar start. I isolated my problem with this code. I'm near certain there's a very simple solution for this but god knows I can't figure it out. Please help.
Attached code determines at the start of each new H4 bar if the previous bar closed bullish or bearish, and if bullish it prints "Buy." or "Sell" if bearish. However both in historical tester and when I demo forward test it, these messages are typed at 4, 8 and 12 am/pm GMT, whereas I would like them to print at 2, 6 and 10 am/pm GMT to correspond the broker bar feed.
public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
if(!instrument.equals(Instrument.EURUSD) || !period.equals(Period.FOUR_HOURS)) return;
IBar lastBar = history.getBar(Instrument.EURUSD, Period.FOUR_HOURS, OfferSide.BID, 1);
if(lastBar.getClose() > lastBar.getOpen()){
console.getOut().println("Buy.");
}
else if(lastBar.getClose() < lastBar.getOpen()){
console.getOut().println("Sell.");
}
else;
}