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.

How to make sure that data has been loaded in onStart?
 Post subject: How to make sure that data has been loaded in onStart? Post rating: 0   New post Posted: Wed 13 Jul, 2011, 01:50 

User rating: 0
Joined: Wed 13 Jul, 2011, 01:19
Posts: 8
Location: DE
Hello,

I want to automatically start a strategy with the platform.
The problem is that when the strategy immediately gets started the platform hasn't enough time to receive historical data.
This means that methods like getStartTimeOfCurrentBar() or getLastTick() return null when called from onStart().
When I manually start the strategy I don't have this problem.

Now my question is: How can I make sure that the data is ready when I'm in the onStart() method?


 
 Post subject: Re: How to make sure that data has been loaded in onStart? Post rating: 0   New post Posted: Wed 13 Jul, 2011, 12:46 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
consider the following onStart method:
   private Instrument instrument = Instrument.EURUSD;
   private IConsole console;
   private IHistory history;

   @Override
   public void onStart(IContext context) throws JFException {
      this.console = context.getConsole();
      this.history = context.getHistory();
      console.getOut().println("Start");

      // wait max 5 seconds for the tick to get loaded
      ITick lastTick = history.getLastTick(instrument);
      int i = 5;
      while (lastTick == null) {
         console.getOut().println("tick not loaded yet");
         lastTick = history.getLastTick(instrument);
         try {
            Thread.sleep(1000);
         } catch (InterruptedException e) {
            console.getOut().println(e.getMessage());
         }
         i--;
      }
   }


 

Jump to:  

  © 1998-2025 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