|
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.
Issue with customising trading hours - after 1400 GMT |
imtsfx
|
Post subject: Issue with customising trading hours - after 1400 GMT |
Post rating: 0
|
Posted: Mon 27 Aug, 2012, 15:27
|
|
User rating: 0
Joined: Mon 20 Aug, 2012, 07:37 Posts: 8 Location: AustraliaAustralia
|
Hi, I'm new to Jforex. Trying to run EA between 0700 and 1600 GMT, and then close all open positions at the end of the day, public void onBar(Instrument instrument, Period period, IBar askbar, IBar bidbar) throws JFException { if (isValidTime(7, 0, 16, 0, Calendar.MONDAY, Calendar.TUESDAY, Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY) == false) return; if (instrument != Instrument.EURUSD || period != Period.FIVE_MINS) return; I've done some testing to close all positions BEFORE 1400GMT and they were all successful. The following code is just one example to close all positions at 1400 GMT, if (isValidTime(13, 55, 14, 0, Calendar.MONDAY, Calendar.TUESDAY, Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY) == true){ for (IOrder orderInMarket : engine.getOrders()) orderInMarket.close(); } Attachment: However, if I change it to any time AFTER 1400 GMT, none of the open positions got closed out at the time expected, for instance 1405 GMT, if (isValidTime(14, 0, 14, 5, Calendar.MONDAY, Calendar.TUESDAY, Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY) == true){ for (IOrder orderInMarket : engine.getOrders()) orderInMarket.close(); } Attachment: I use calendar to customise trading hours. Can someone please advise what I did was wrong? Thanks! //use of calendar 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.setTimeInMillis(lastTickTime); calendar.setTimeZone(TimeZone.getTimeZone("GMT")); calendar.set(Calendar.HOUR_OF_DAY, fromHour); calendar.set(Calendar.MINUTE, fromMin); calendar.set(Calendar.SECOND, 0); long from = calendar.getTimeInMillis(); calendar.setTimeInMillis(lastTickTime); calendar.setTimeZone(TimeZone.getTimeZone("GMT")); 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; }
|
|
|
|
 |
imtsfx
|
Post subject: Re: Issue with customising trading hours - after 1400 GMT |
Post rating: 0
|
Posted: Tue 28 Aug, 2012, 01:34
|
|
User rating: 0
Joined: Mon 20 Aug, 2012, 07:37 Posts: 8 Location: AustraliaAustralia
|
I changed the subject as the issue is actually with isValidTime method by using calendar option. I don't think it has anything to do with order closing function. I just did more tests with two strategies. This is the one with customising trading hours working, Attachment: again, in Strategy "SMAStrategy_test_before1400gmt", I used the following code to close all orders in market after 13:59 GMT, boolean isValid = isValidTime(13, 59, 16, 0, Calendar.MONDAY, Calendar.TUESDAY, Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY); if (isValid == true){ for (IOrder orderInMarket : engine.getOrders()) orderInMarket.close(); } and you may notice all filled/open orders got closed at 13:59. Here is the screenshot after the testing, Attachment: But in strategy "SMAStrategy_test_after1400gmt", the "customising trading hours" didn't work for some reason, Attachment: Please see the screenshot as below. None of the filled/open orders got closed around 14:01, Attachment: The only difference between these two strategies is the codes as following, SMAStrategy_test_before1400gmt boolean isValid = isValidTime(13, 59, 16, 0, Calendar.MONDAY, Calendar.TUESDAY, Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY); SMAStrategy_test_after1400gmt boolean isValid = isValidTime(14, 1, 16, 0, Calendar.MONDAY, Calendar.TUESDAY, Calendar.WEDNESDAY, Calendar.THURSDAY, Calendar.FRIDAY); Can someone kindly advise what I missed in the tests above please? Thanks!
|
|
|
|
 |
imtsfx
|
Post subject: Re: Issue with customising trading hours - after 1400 GMT |
Post rating: 0
|
Posted: Wed 29 Aug, 2012, 06:56
|
|
User rating: 0
Joined: Mon 20 Aug, 2012, 07:37 Posts: 8 Location: AustraliaAustralia
|
Issue resolved after I put "calendar.setTimeZone(TimeZone.getTimeZone("GMT"));" in front of "calendar.setTimeInMillis(lastTickTime);". Can someone at Dukascopy please review the codes posted on the Wiki site? https://www.dukascopy.com/wiki/#Customize_trading_hourslong lastTickTime = history.getLastTick(instrument).getTime(); Calendar calendar = Calendar.getInstance(); calendar.setTimeZone(TimeZone.getTimeZone("GMT")); calendar.setTimeInMillis(lastTickTime); // calendar.setTimeZone(TimeZone.getTimeZone("GMT")); 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.setTimeZone(TimeZone.getTimeZone("GMT")); calendar.set(Calendar.HOUR_OF_DAY, toHour); calendar.set(Calendar.MINUTE, toMin); calendar.set(Calendar.SECOND, 0); long to = calendar.getTimeInMillis();
|
|
|
|
 |
API Support
|
Post subject: Re: Issue with customising trading hours - after 1400 GMT |
Post rating: 0
|
Posted: Wed 29 Aug, 2012, 12:49
|
|
User rating: ∞
Joined: Fri 31 Aug, 2007, 09:17 Posts: 6139
|
The article has been updated.
|
|
|
|
 |
imtsfx
|
Post subject: Re: Issue with customising trading hours - after 1400 GMT |
Post rating: 0
|
Posted: Thu 30 Aug, 2012, 00:47
|
|
User rating: 0
Joined: Mon 20 Aug, 2012, 07:37 Posts: 8 Location: AustraliaAustralia
|
|
|
|
 |
|
Pages: [
1
]
|
|
|
|
|