Dukascopy
 
 
Wiki JStore Search Login

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

    Try to find an answer in Wiki before asking a question.
    Submit programming questions in this forum only.
    Off topics are strictly forbidden.

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

on bars method running multiple times
 Post subject: on bars method running multiple times Post rating: 0   New post Posted: Tue 31 Jul, 2018, 13:54 

User rating: 0
Joined: Fri 11 May, 2018, 14:08
Posts: 2
Location: CanadaCanada
hi, i'm running a strategy on daily bars, i can see at midnight that the onBar method is executed multiple times over a one minute period. is there a way to make sure that the onBar method runs only once on the first tick of the new bar?


 
 Post subject: Re: on bars method running multiple times Post rating: 0   New post Posted: Tue 31 Jul, 2018, 14:59 
User avatar

User rating: 70
Joined: Sat 22 Sep, 2012, 17:43
Posts: 118
Location: Brazil, Fortaleza, Ceará
Taken from the IStrategy interface information page:
void onBar(Instrument instrument,
           Period period,
           IBar askBar,
           IBar bidBar)
    throws JFException

Called on every bar for every basic period and instrument that application is subscribed on.

In order to only work with bars of a particular instrument and period consider bar filtering:

 public void onBar(Instrument instrument, Period period, IBar askBar, IBar bidBar) throws JFException {
     if (!instrument.equals(Instrument.EURUSD) || period.equals(Period.ONE_HOUR)){
         return;
     }
     //the strategy from here on only works with EURUSD ONE_HOUR bars
 }

Note that the onBar method has a Period parameter which informs you about the contents of the following IBar parameters.

Consider SOME the possible Period values you can use for filtering described above:

DAILY
FIFTEEN_MINS
FIVE_MINS
FOUR_HOURS
MONTHLY
ONE_HOUR
ONE_MIN
ONE_SEC
TEN_MINS
TEN_SECS
THIRTY_MINS
WEEKLY

Please note that the onBar is called AFTER the completion of a bar not on the creation or 'first tick of a new bar'.
onTick calls relate to ticks accumulating with respect to the CURRENT bar (the bar that once complete will trigger a call to onBar).

Hope this helps.


 

Jump to:  

  © 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