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.

Set trading hours
 Post subject: Set trading hours Post rating: 0   Post Posted: Thu 23 Apr, 2015, 09:21 
User avatar

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??


 
 Post subject: Re: Set trading hours Post rating: 0   Post Posted: Thu 23 Apr, 2015, 20:54 
User avatar

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);


 
 Post subject: Re: Set trading hours Post rating: 0   Post Posted: Fri 24 Apr, 2015, 03:59 
User avatar

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


 
 Post subject: Re: Set trading hours Post rating: 0   Post Posted: Fri 24 Apr, 2015, 11:30 
User avatar

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"


 
 Post subject: Re: Set trading hours Post rating: 0   Post Posted: Fri 24 Apr, 2015, 12:39 
User avatar

User rating: 0
Joined: Tue 02 Aug, 2011, 11:35
Posts: 32
Location: United Arab Emirates, Dubai
Great Thanks


 

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