Hi,
I have a lot of experience writing strategies, so I wanted a
10 second onBar driven by the Instrument.EURUSD.
I just wanted the onBar logic to execute every 10 seconds
and only once per each 10 second period.
I subscribed to the instrument, as usual. In my onBar I rejected periods
which were not Period.TEN_SECS and also I rejected
instruments which were not my Instrument.EURUSD.
But... My logic never executed. On investigation, I found that
callbacks to onBar were happening for many other
instruments, but my subscribed instrument was not
one of them ! I wonder did I subscribe correctly?
So I just used a technique of allowing ANY instrument to
call onBar, but rejecting if a saved timestamp was
equal to the current bar timestamp.
Code snippets.
// member variables
final Instrument permanentInstrument = Instrument.EURUSD;
final Period barPeriod = Period.TEN_SECS;
final Set<Instrument> subscribedInstruments = new HashSet<Instrument>();
.............
// @Override
// final public void onStart(final IContext context) throws JFException {
// in onStart, I subscribed as usual like this
subscribedInstruments.add(permanentInstrument);
context.setSubscribedInstruments(subscribedInstruments, true);
// in onBar I received the usual period callbacks for multiple instruments
// the Period.TEN_SECS was included, as well as other periods,
// and lots of platform instruments, except for my subscribed one
// member variable
long lastBarTimestamp = 0;
// @Override
// final public void onBar(final Instrument instrument, final Period period, final IBar askBar,
// final IBar bidBar) throws JFException {
// so the following logic in onBar rejected every callback, as the permanentInstrument
// Instrument.EURUSD never had a callback event ?... !
//log("onBar... period "+period+" instrument: "+instrument);
if ( !period.equals(barPeriod)) return; // this is fine
// WORKAROUND just use bar timestamps
if ( bidBar.getTime() == lastBarTimestamp ) return;
//if ( !instrument.equals(permanentInstrument)) return;
// TODO: our subscribed permanentInstrument never appeared !! ??
// WORKAROUND simply use bar timestamps
lastBarTimestamp = bidBar.getTime(); // save timestamp for next time
This is platform Dukascopy Bank ver. 2.32.2 JForex API ver. 2.9.6.2 .
Seems like a bug to me.
HyperScalper