|
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.
Set trading hours |
jalodge
|
Post subject: Set trading hours |
Post rating: 0
|
Posted: Thu 23 Apr, 2015, 09:21
|
|
User rating: 0
Joined: Tue 02 Aug, 2011, 11:35 Posts: 32 Location: United Arab Emirates, Dubai
|
Can anyone help. I want to set trading hours in Strategy from say 9am through to 5am the next day
I'm using
private boolean isValidTime(int fromHour, int fromMin, int toHour, int toMin, Integer... days) throws JFException { long lastTickTime = history.getLastTick(instrument).getTime(); Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("GMT")); //you want to work with the date of the last tick - in a case you are back-testing calendar.setTimeInMillis(lastTickTime); calendar.set(Calendar.HOUR_OF_DAY, fromHour); calendar.set(Calendar.MINUTE, fromMin); calendar.set(Calendar.SECOND, 0); long from = calendar.getTimeInMillis();
calendar.setTimeZone(TimeZone.getTimeZone("GMT")); calendar.setTimeInMillis(lastTickTime); calendar.set(Calendar.HOUR_OF_DAY, toHour); calendar.set(Calendar.MINUTE, toMin); calendar.set(Calendar.SECOND, 0); long to = calendar.getTimeInMillis(); boolean isDayOk = (Arrays.asList(days)).contains(calendar.get(Calendar.DAY_OF_WEEK)); boolean timeOk = lastTickTime > from && lastTickTime < to ; print(String.format("calendar: %s - %s last tick: %s, isDayOk=%s, timeOk=%s", gmtSdf.format(from), gmtSdf.format(to), gmtSdf.format(lastTickTime), isDayOk, timeOk));
return isDayOk && timeOk;
and
barTime = bidBar.getTime(); boolean isValid = isValidTime(9, 0, 23, 0, Calendar.TUESDAY,Calendar.MONDAY, Calendar.THURSDAY); print ( gmtSdf.format(barTime) + " Is valid time? " + isValid);
If you change 23 to 6 it doesn't take any trades??
|
|
|
|
 |
nicejack
|
Post subject: Re: Set trading hours |
Post rating: 0
|
Posted: Thu 23 Apr, 2015, 20:54
|
|
User rating: 2
Joined: Wed 03 Sep, 2014, 09:11 Posts: 32 Location: GermanyGermany
|
Hi jalodge, you cant´t trade from 9 to 6 ! use this: boolean isValid = isValidTime(6, 0, 9, 0, Calendar.TUESDAY,Calendar.MONDAY, Calendar.THURSDAY);
|
|
|
|
 |
jalodge
|
Post subject: Re: Set trading hours |
Post rating: 0
|
Posted: Fri 24 Apr, 2015, 03:59
|
|
User rating: 0
Joined: Tue 02 Aug, 2011, 11:35 Posts: 32 Location: United Arab Emirates, Dubai
|
Thanks NiceJack...
but thats will just allow trading after 6 and before 9..
I need after 6 and before 9 not valid
|
|
|
|
 |
API Support
|
Post subject: Re: Set trading hours |
Post rating: 0
|
Posted: Fri 24 Apr, 2015, 11:30
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
This can be done with the same function by dividing the day into two periods: boolean isValid = isValidTime(0, 0, 5, 0, Calendar.TUESDAY, Calendar.MONDAY, Calendar.THURSDAY); // night "session" isValid = isValid || isValidTime(9, 0, 24, 0, Calendar.TUESDAY, Calendar.MONDAY, Calendar.THURSDAY); // day "session"
|
|
|
|
 |
jalodge
|
Post subject: Re: Set trading hours |
Post rating: 0
|
Posted: Fri 24 Apr, 2015, 12:39
|
|
User rating: 0
Joined: Tue 02 Aug, 2011, 11:35 Posts: 32 Location: United Arab Emirates, Dubai
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|