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.

get current bar always null?
 Post subject: get current bar always null? Post rating: 0   New post Posted: Wed 27 Jun, 2018, 14:20 

User rating: 0
Joined: Mon 09 Oct, 2017, 06:34
Posts: 15
Location: Hong Kong,
i try to get the current bar at Friday GMT 17:00
but it is always null, why?

code:
final Period myPeriod = Period.createCustomPeriod(Unit.Week, 1, JFTimeZone.EET);
final IBar myBar = this.history.getBar(instrument, myPeriod , OfferSide.ASK, 0);

^
myBar are always null


 
 Post subject: Re: get current bar always null? Post rating: 0   New post Posted: Thu 28 Jun, 2018, 10:10 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
If you want get InProgress Candles for custom period, you need to specify feeddescriptor and subscribe to feed.

public class MyStrategy implements IStrategy, IFeedListener {
    IConsole console;
    IHistory history;

    @Configurable("Instrument")
    public Instrument instrument = Instrument.EURUSD;

    @Configurable("OfferSide")
    public OfferSide offerSide = OfferSide.ASK;

    @Override
    public void onStart(IContext context) throws JFException {
        console = context.getConsole();
        history = context.getHistory();

        Period myPeriod = Period.createCustomPeriod(Unit.Week, 1, JFTimeZone.EET);
        IFeedDescriptor feedDescriptor = new TimePeriodAggregationFeedDescriptor(instrument, myPeriod, offerSide, Filter.WEEKENDS);

        context.subscribeToFeed(feedDescriptor, this);

        IBar myBar = history.getBar(instrument, myPeriod, offerSide, 0);
        console.getOut().println(myBar);
    }


 

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