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.

number of elements in input price array
 Post subject: number of elements in input price array Post rating: 0   New post Posted: Sat 16 Jul, 2011, 13:52 
User avatar

User rating: 1
Joined: Wed 06 Jul, 2011, 23:12
Posts: 42
Location: Romania, Bucharest
Dear Sirs,


Is there a way to set the number of elements in the input price array?

Testing some indicators and reading the error messages I have learned that the default price history loaded when an indicator is calculated is 4000 elements. But for example if I want to calculate the VolumeWeightedAveragePrice for the last 5 days on a 1 minute chart, I need 5x1440=7200 elements of price history.

I know from my previus experience that Metatrader and Metastock can load up to 65.500 elements of price history.


Thank you very much in advance!


 
 Post subject: Re: number of elements in input price array Post rating: 0   New post Posted: Mon 18 Jul, 2011, 11:21 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
You can select bars and ticks from arbitrary historical periods by using IHisotry interface. Consider the following snippet which, for example, can be placed in in IIindicator.onStart() method:
      IConsole console = context.getConsole();
      IHistory history = context.getHistory();
      try {
         // custom historical interval
         SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
         dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
         Date dateFrom = dateFormat.parse("2011-07-11 11:29:00");
         Date dateTo = dateFormat.parse("2011-07-11 11:30:00");

         List<ITick> ticks = history.getTicks(Instrument.EURUSD, dateFrom.getTime(), dateTo.getTime());
         List<IBar> bars = history.getBars(Instrument.EURUSD, Period.TEN_SECS, OfferSide.BID, dateFrom.getTime(), dateTo.getTime());

         for (ITick tick : ticks)
            console.getOut().println("Tick: " + tick);

         for (IBar bar : bars)
            console.getOut().println("Bar: " + bar);

      } catch (ParseException e) {
         console.getErr().println(e);
      } catch (JFException e) {
         console.getErr().println(e);
      }
Mind to keep retrieved List<ITick> and List<IBar> sizes relatively low (e.g. a list of ticks over a week period will likely cause an OutOfMemoryError, more concrete heap size limit is regulated by java settings). So if you need to work with large time intervals, but small bar periods (or ticks), it is advisable to divide your time interval in smaller ones.


 

Jump to:  

cron
  © 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