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 get day of the week / hour from bar/tick getTime()
 Post subject: how to get day of the week / hour from bar/tick getTime() Post rating: 0   New post Posted: Thu 26 Dec, 2013, 17:47 
User avatar

User rating: 0
Joined: Sun 04 Aug, 2013, 10:16
Posts: 48
Location: FranceFrance
still newbie in java, apologize

weekend gaps are totally spoiling my long term tests so I need to do something about it (like closing positions on friday if there are, reopening the same on the monday), rather than test week by week

from
bar.getTime()
what would be the most elegant way to obtain the day of the week( string ?) & the gmt hour (int ?)

I've been hitting a wall there as I didn't find anything about date/time conversion in the wiki nor the API javadoc

the only way I can think about is really ugly (bartime - current week bar time / number of ms per day... not even being sure about when a week bar starts). There are more straightforward ways aren't there ?

thanks for your help or for pointing to the doc that'd cover this


 
 Post subject: Re: how to get day of the week / hour from bar/tick getTime() Post rating: 0   New post Posted: Thu 26 Dec, 2013, 18:26 
User avatar

User rating: 0
Joined: Sun 04 Aug, 2013, 10:16
Posts: 48
Location: FranceFrance
              Date date = new Date (askBar.getTime());
              console.getOut().println(date.getDay());
              console.getOut().println(date.getHours());


return integer for day of the week.

However :

Quote:
getDay

@Deprecated
public int getDay()

Deprecated. As of JDK version 1.1, replaced by Calendar.get(Calendar.DAY_OF_WEEK).

https://docs.oracle.com/javase/7/docs/ap ... tDay%28%29

getDay is working on my machine though (ubuntu java 6);
haven't found how to use Calendar

looking forward for explanations on what should be the best way to do it


 
 Post subject: Re: how to get day of the week / hour from bar/tick getTime() Post rating: 1   New post Posted: Fri 27 Dec, 2013, 21:16 
User avatar

User rating: 96
Joined: Mon 09 Sep, 2013, 07:09
Posts: 287
Location: Ukraine, SHostka
Try this approach:
https://www.dukascopy.com/wiki/#History_bars/Filter_usage

About Calendar usage:
Calendar calendar = GregorianCalendar.getInstance(TimeZone.getTimeZone("GMT"));
calendar.setTimeInMillis(askBar.getTime());
int dayOfWeek = calendar.get(Calendar.DAY_OF_WEEK);


 
 Post subject: Re: how to get day of the week / hour from bar/tick getTime() Post rating: 0   New post Posted: Sat 28 Dec, 2013, 21:59 
User avatar

User rating: 164
Joined: Mon 08 Oct, 2012, 10:35
Posts: 676
Location: NetherlandsNetherlands
Maybe it is a bit over complicated, but you can use the SimpleDateFormat class to convert the time (long) to string, and then get the hour (int) from the string.
See https://www.dukascopy.com/wiki/#Format_Date_Time.


 
 Post subject: Re: how to get day of the week / hour from bar/tick getTime() Post rating: 1   New post Posted: Thu 02 Jan, 2014, 10:00 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
mikakun wrote:
what would be the most elegant way to obtain the day of the week( string ?) & the gmt hour (int ?)
See:
https://www.dukascopy.com/wiki/#Customize_trading_hours


 
 Post subject: Re: how to get day of the week / hour from bar/tick getTime() Post rating: 0   New post Posted: Sat 04 Jan, 2014, 12:27 
User avatar

User rating: 0
Joined: Sun 04 Aug, 2013, 10:16
Posts: 48
Location: FranceFrance
thank you all for this & sorry I didn't look well enough in the wiki since it was there...

nb : link to simpledateformat class in oracle site is broken


 
 Post subject: Re: how to get day of the week / hour from bar/tick getTime() Post rating: 0   New post Posted: Mon 06 Jan, 2014, 08:17 
User avatar

User rating:
Joined: Fri 31 Aug, 2007, 09:17
Posts: 6139
The links have been updated.


 

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