Dukascopy
 
 
Wiki JStore Search Login

Attention! Read the forum rules carefully before posting a topic.

    Submit JForex API bug reports in this forum only.
    Submit Converter issues in Converter Issues.
    Off topics are strictly forbidden.

Any topics which do not satisfy these rules will be deleted.

No onBar for subscribed instrument?
 Post subject: No onBar for subscribed instrument? Post rating: 0   New post Posted: Fri 07 Mar, 2014, 15:56 
User avatar

User rating: 98
Joined: Mon 23 Jul, 2012, 02:02
Posts: 656
Location: United States, Durham, NC
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


 
 Post subject: Re: No onBar for subscribed instrument? Post rating: 0   New post Posted: Mon 10 Mar, 2014, 17:54 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
Could you please provide a full example strategy which replicates this?


 

Jump to:  

cron
  © 1998-2024 Dukascopy® Bank SA
On-line Currency forex trading with Swiss Forex Broker - ECN Forex Brokerage,
Managed Forex Accounts, introducing forex brokers, Currency Forex Data Feed and News
Currency Forex Trading Platform provided on-line by Dukascopy.com