As from monday we’ve got 2 weeks when the American and European daylight savings are out of synch, and I’d like to have a piece of code to allow for the hour difference in opening time.
I’m sure the following is wrong, but you get the general idea. I find the documentation very unclear about how to specify dates.
Once DLS = (month =3 and day>=14 and day <=28)
If DLS then
Tradetime = time >=133000 and time <200000
elsif not DLS then
Tradetime = time >=143000 and time <210000
endif
You need to remove ONCE from line 1, because it must be evaluated everyday, not just the first time in autotrading.
Thanks Roberto, I wasn’t so completely wrong then!
But I just remembered there’s another week in November that needs correcting. UK DLS ends 31 Oct and the American on Nov 7, so can I use:
DLS = (month =3 and day>=14 and day <=28) or (month=11 and day>=1 and day <=7)
If DLS then
Tradetime = time >=133000 and time <200000
elsif not DLS then
Tradetime = time >=143000 and time <210000
endif
I refined and expanded the code to cover the period 2010 to 2024 and it seems to work in terms of altering the opening times of trades during those weeks – this is for an algo that only operates in the DOW’s first hour so for me the change is crucial.
//adjustment for American Daylight Savings time
DLS =(Date >= 20100314 and date <=20100328) or (Date >= 20101031 and date <=20101107) or (Date >= 20110313 and date <=20110327) or (Date >= 20111030 and date <=20111106) or (Date >= 20120311 and date <=20120325) or (Date >= 20121028 and date <=20121104) or (Date >= 20130310 and date <=20130331) or (Date >= 20131027 and date <=20131103) or (Date >= 20140309 and date <=20140330) or (Date >= 20141026 and date <=20141102) or (Date >= 20150308 and date <=20150329) or (Date >= 20151025 and date <=20151101) or (Date >= 20160313 and date <=20160327) or (Date >= 20161030 and date <=20161106) or (Date >= 20170312 and date <=20170326) or (Date >= 20171030 and date <=20171105) or (Date >= 20180311 and date <=20180325) or (Date >= 20181028 and date <=20181104) or (Date >= 20190310 and date <=20190331) or (Date >= 20191027 and date <=20191103) or (Date >= 20200308 and date <=20200329) or (Date >= 20201025 and date <=20201101) or (Date >= 20210314 and date <=20210328) or (Date >= 20211031 and date <=20211107) or (Date >= 20220313 and date <=20220327) or (Date >= 20221030 and date <=20221106) or (Date >= 20230312 and date <=20230326) or (Date >= 20231029 and date <=20231105) or (Date >= 20240310 and date <=20240331) or (Date >= 20241027 and date <=20241103)
If DLS then
Tradetime = time >=133000 and time <200000
elsif not DLS then
Tradetime = time >=143000 and time <210000
endif
But unfortunately it also seems to alter the results for trades taken outside of those periods. If you look at the attached image, you can see that the dates, times, and number of bars is identical, but the profit is completely different. The figures on the right are adjusted for American Daylight Savings (although those dates fall outside of the adjusted period), the figures on the left have no adjustment at all.
???
Never mind, I found the problem – nothing to do with that code, which seems ok. 😁
I found the problem
Hi, curious has anyone found a solution to change the trade-times for daylight savings without having to individually put in each years daylight savings dates as above?
Ive tried the suggestions here: https://www.prorealcode.com/topic/programmed-daylight-savings-time-change-code-block/
but they didn’t work, was still opening times during daylight savings the same as out.
there’s a strong chance the Americans will do away with the clock change altogether so it might not be a problem.
Maybe the problem persists even more;
Right now there’s a chance that all fall together (in spring as well as in autumn). When this goes through then there’s definitely a change twice a year.
🙂
sh*t, you’re right of course … hadn’t thought that through.
If only PRT could come up with a solution that “communicates” over these issues. They are of vast importance (says me, says you) but at least for backtesting they can’t be solved really. Yeah, with code like you proposed. But now integrate with the Aussies (like I tried with Kev Monaghan the past days – just not doable).
The time constraints are a sheer pain throughout. Maybe I understand Futures by now. Just maybe. But only the $ (financial) assets. … unsolvable ?
integrate with the Aussies
so it might not be a problem.
Definitely a problem remains for us Aussies. Sydney changed a +2 hours compared to London time last month. As our DLS finished (- 1 hour) and your BST started (+1hr), which has really messed around all my strategies performances, my strategies placing orders 2 hours outside of the actual London trade times for example.
I’m also not sure if you change your platforms time to the instruments “local time” and then launch the strategy if that would mean that adjusts automatically to local time (eg. +/- 1hr related to BST), or not, cant find anything in the PRT manuals on this?
I tried to work out it out: https://www.prorealcode.com/topic/prt-strategy-adjust-local-tradetime-when-daylight-savings-time-changes-1hr/ – no answer on that topic yet.
But as you can see on that topic the performance even with the code seems worse, which means i must still not have it sorted or my logic is all wrong.
It’s an extra burden for Aussie traders because of the UK + US + AU time changes.
I can solve it but how many traders here really need this solved?
I do, or any other Aussies, which i assume is a lot considering IG is our biggest broker in Australia (well so they claim).
Hi guys, I’m a bit late to this but I *think* you’re all overthinking this.. I used to have the exact same issues.. to fix it I went to – Platform Settings >> Time Zones and Trading Hours. Then click ‘Use different time zones for different markets as specified below:’.. then you find the relevant market (I tend to test on the Dow, so; Indices – US) then you click both ‘Use the local market time zone’ and ‘Use trading hours of this market’.
Once that’s done you just code in local times, so if you’re trading the US open use 093000.. no need to adjust for any DSL or differences in time zones whatsoever! Hope that helps!