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.

Start time on bars
 Post subject: Start time on bars Post rating: 0   New post Posted: Mon 22 Sep, 2008, 14:26 

User rating: 0
Joined: Sat 06 Sep, 2008, 17:07
Posts: 3
just a quick question on start time on bars. Are the start time always in relation to BST (British Standard Time).

this is the code i used to test:
long timeOfTheCurrentBar = history.getStartTimeOfCurrentBar(Instrument.EURUSD, Period.MONTHLY);
Date datetime = new Date(timeOfTheCurrentBar);

console.getOut().println(datetime.getHours());
console.getOut().println(datetime);

timeOfTheCurrentBar = history.getStartTimeOfCurrentBar(Instrument.EURUSD, Period.ONE_HOUR);
datetime = new Date(timeOfTheCurrentBar);

console.getOut().println(datetime.getHours());
console.getOut().println(datetime);

this was the output:

2008-09-22 13:50:55 Mon Sep 22 13:00:00 BST 2008
2008-09-22 13:50:55 13
2008-09-22 13:50:55 Mon Sep 01 01:00:00 BST 2008
2008-09-22 13:50:55 1

it looks like it is in BSt time but i am sure kust 2 weeks ago when i was working in australia it return time in australian time?


 
 Post subject: Re: start time on bars Post rating: 0   New post Posted: Tue 23 Sep, 2008, 10:38 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
All times, that we return as longs (tick.getTime(), bar.getTime()) are in GMT+0 time. This is Java standard for time represented in long. It can be the same as BST half the year and can be different another half when daylight savings are counted in in BST. When you print new Date(timeInLong).getHours() or new Date(timeInLong).toString() it uses DateFormat in your local timezone. In Australia you will have another time because of different time zone. If you want to print time in GMT, then you can use this code:
DateFormat dateFormat = new SimpleDateFormat("yyyy.MM.dd HH:mm:ss SSS");
dateFormat.setTimeZone(TimeZone.getTimeZone("GMT"));
console.getOut().println(dateFormat.format(new Date(timeInLong)));

or if you want to get hours in GMT:
Calendar cal = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
cal.setTimeInMillis(timeInLong);
int hours = cal.get(Calendar.HOUR_OF_DAY);
console.getOut().println(hours);

TimeZone and Calendar are classes in java.util package and DateFormat is in java.text package


 
 Post subject: Re: start time on bars Post rating: 0   New post Posted: Sun 05 Oct, 2008, 15:14 

User rating: 0
Joined: Sat 06 Sep, 2008, 17:07
Posts: 3
thanxs for all you help, i just have one more question:

long offsetDAILY = Period.MONTHLY.getInterval();

i use the above code in my program, how does the above function determine the correct interval for the right month? eg febuary and december would have different interval values.


 
 Post subject: Re: start time on bars Post rating: 0   New post Posted: Mon 06 Oct, 2008, 09:42 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
It doesn't! You have to use IHistory.getBarStart or IHistory.getNextBarStart or use Calendar to calculate correct start of the bar, you can't just add Period.MONTHLY.getInterval() to get time of the next bar. Period.MONTHLY.getInterval() always returns 30 days.


 

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