Daylight Saving Coding… AGAIN!
Forums › ProRealTime English forum › ProBuilder support › Daylight Saving Coding… AGAIN!
- This topic has 6 replies, 3 voices, and was last updated 8 months ago by robertogozzi.
-
-
03/26/2024 at 12:24 PM #230465
Hi All
I know this topic has been covered numerous times over the years:
- PRT Strategy adjust Local TradeTime when Daylight Savings time changes +/- 1hr? : Forum ProBuilder support – ProRealTime (prorealcode.com)
- Daylight savings time messing up charts : Forum ProRealTime platform support – ProRealTime (prorealcode.com)
- Programmed Daylight Savings Time Change Code Block : Forum ProOrder support – ProRealTime (prorealcode.com)
- Daylight savings : Forum ProRealTime platform support – ProRealTime (prorealcode.com)
- Daylight savings code : Forum ProOrder support – ProRealTime (prorealcode.com)
- Daylight Saving Time at Open Range Breakout? : Forum ProOrder support – ProRealTime (prorealcode.com)
- Daylight savings anomaly inconsistency : Forum ProOrder support – ProRealTime (prorealcode.com)
Yet, I am still struggling.
This is the info I have:
- My charts are set to (UTZ+00:00)Z
- Market: Wall Street Cash (£1)
- During DST on a Friday, the market closes at 21hoo (UTZ)
- During Non-DST on a Friday, markets close at 22h00 (UTZ)
As far as I can see, my indicator says:
- No trades are to be opened from 19h00 on Fridays, and no trades are to be placed on Sundays during DST.
- No trades are to be opened from 20h00 on Fridays, and no trades are to be placed on Sundays during Non-DST.
TradingDay (with/without DST)1234567891011121314151617181920// Determine the day of the week for the second Sunday in MarchMarchSecondSunday = (Month = 3) AND (DayOfWeek = 0) AND (Date >= 8) AND (Date <= 14)// Determine the day of the week for the first Sunday in NovemberNovemberFirstSunday = (Month = 11) AND (DayOfWeek = 0) AND (Date >= 1) AND (Date <= 7)// Check if current date is within DST periodIF Date > MarchSecondSunday AND Date < NovemberFirstSunday THENDSTOn = 1ELSEDSTOn = 0ENDIF// Define trading hours based on DST status:IF (DayOfWeek = 5 AND Time >= 200000) OR (DSTOn AND Time >= 190000) OR (DayOfWeek = 0) THENTradingDay = 0ELSETradingDay = 1ENDIFReturn TradingDayYet, when I apply my indicator, it still shows:
- Trading is allowed at 19h20 on Fridays and 23h40 on Sundays during DST.
- Trading is allowed at 19h20 on Fridays and 23h40 on Sundays during Non-DST.
- (Screenshots attached)
A few questions, please:
- Is my indicator coded correctly?
- Does changing my chart time zone to: “Use different time zones for different markets (United States Indices – US)” make coding for DST unnecessary? (This has been mentioned by members in the forum)
- When completing a backtest, is a DST taken into account?
Regards
Brad
03/26/2024 at 2:19 PM #230490Try this one:
12345678910111213141516171819202122232425262728293031323334IF BarIndex = 0 THENIF OpenMonth < 3 OR OpenMonth > 10 THENDSTon = 0ELSEDSTon = 1ENDIFSundays = 0ENDIF// Determine the day of the week for the second Sunday in March when DST turns ONIF (OpenMonth = 3) AND (DSTon = 0) THENIF OpenDayOfWeek >= 0 AND (OpenDayOfWeek[1] > OpenDayOfWeek) THENSundays = Sundays + 1IF Sundays = 2 THENDSTOn = 1Sundays = 0ENDIFENDIFENDIF// Determine the day of the week for the first Sunday in November when DST turns OFFIF (OpenMonth = 11) AND (DSTon = 1) THENIF OpenDayOfWeek >= 0 AND (OpenDayOfWeek[1] > OpenDayOfWeek) THENDSTOn = 0ENDIFENDIF// Define trading hours based on DST status:IF (OpenDayOfWeek = 5 AND ((OpenTime >= 200000 AND Not DSTon) OR (DSTOn AND OpenTime >= 190000))) OR (OpenDayOfWeek = 0) THENTradingDay = 0ELSETradingDay = 1ENDIFReturn TradingDay1 user thanked author for this post.
03/26/2024 at 3:44 PM #230504Hi Brad,
Does changing my chart time zone to: “Use different time zones for different markets (United States Indices – US)” make coding for DST unnecessary? (This has been mentioned by members in the forum)
Nope.
When completing a backtest, is a DST taken into account?
If all the DLS periods are recognized in your code, Yes. Thus, backtest from of e.g. Jan 2019, and including the current one, 11 periods should be recognized and you must of course have those periods correct. You should also cover for the future, like the next period in autumn 2024 and spring 2025, assumed your Live System will be running until then.
There is no automation for this, apart from your own. 🙂1 user thanked author for this post.
03/26/2024 at 3:50 PM #23050503/26/2024 at 3:53 PM #23050603/26/2024 at 3:57 PM #230507Try this one:
Roberto, your code does virtually nothing, because it is not (or will not be) about Daylight Savings as such, sec;
You would not care a hoot whether your Italian stocks etc. open one hour earlier or later in relation to sun dawn when summer time has arrived next week (don’t even try to reason about the earlier or later if you want to survive this day 😉 ). What is important is the relation to the world markets. Thus, the past two weeks and the current week, the US markets open and close 1 hour earlier than Europe’s, because THEIR DLS already started two weeks ago; ours is just to come.
In principle the same thing will happen in autumn (the US will be early) but whether the period takes 3 weeks again, is to be seen (I did not look it up yet).All we can say is that for Europe the rules are quite decent (your code contains that) and that for the US they seem to do what they like, or I don’t know the rules (why this idea ? because it is different often, like 1 week of difference, 2 weeks of difference, or 3 weeks of difference like currently). But hey, if you travel 10 States, you must change your watch 10 times. 🙂
03/27/2024 at 2:03 PM #230578if you travel 10 States, you must change your watch 10 times
If you use different instruments of 10 different countries you will have to change the dates above 10 times.
I just coded what had been asked.
-
AuthorPosts