Daylight savings anomaly inconsistency

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #168348 quote
    PhilstradingPhilstrading
    Participant
    Senior

    hi

    So Ive included the code and an ITF file for runing checks.

    Here the switching is not consistently on sundays. I appear to have data – timezone is europe/London utc +01:00

    I included the graphing, but I’m not altogether sure why I’m getting days other than a sunday for the Switch

    Any assistance would be appreciated.. there is some additional code tried behind comments

    I’ve tried on FX and Dax – time change code not too important as that canbe anything, but it should be switching on Sundays in line with the daylights saivngs but is inconsistently sundays…

    DEFPARAM CumulateOrders = False
    DEFPARAM PreLoadBars    = 2000
    //-------------------------------------------------------------------------------------
    //March settings
    //-------------------------------------------------------------------------------------
    If normaltime=1 then
    startT = 040000   //Starting TIME
    endT   = 123000   //Ending TIME
    td1         = 1 AND OpenDayOfWeek = 1 AND OpenTime >= startT AND OpenTime <= endT //Monday
    td2         = 1 AND OpenDayOfWeek = 2 AND OpenTime >= startT AND OpenTime <= endT  //Tuesday
    td3         = 1 AND OpenDayOfWeek = 3 AND OpenTime >= startT AND OpenTime <= endT  //Wednesday
    td4         = 1 AND OpenDayOfWeek = 4 AND OpenTime >= startT AND OpenTime <= endT  //Thursday
    td5         = 1 AND OpenDayOfWeek = 5 AND OpenTime >= startT AND OpenTime <= 040000 //Friday
    tdCond      =  td1 OR td2 OR td3 OR td4 OR td5
    tdclose = 1 AND OpenDayOfWeek = 5 AND OpenTime >= 200000 //Friday close off 9pm
    endif
    if changedtime=1 then
    startT = 040000   //Starting TIME
    endT   = 123000   //Ending TIME
    td1         = 1 AND OpenDayOfWeek = 1 AND OpenTime >= startT AND OpenTime <= endT //Monday
    td2         = 1 AND OpenDayOfWeek = 2 AND OpenTime >= startT AND OpenTime <= endT  //Tuesday
    td3         = 1 AND OpenDayOfWeek = 3 AND OpenTime >= startT AND OpenTime <= endT  //Wednesday
    td4         = 1 AND OpenDayOfWeek = 4 AND OpenTime >= startT AND OpenTime <= endT  //Thursday
    td5         = 1 AND OpenDayOfWeek = 5 AND OpenTime >= startT AND OpenTime <= 040000 //Friday
    tdCond      =  td1 OR td2 OR td3 OR td4 OR td5
    tdclose = 1 AND OpenDayOfWeek = 5 AND OpenTime >= 200000 //Friday close off 9pm
    endif
    timeframe (daily)
    If openmonth=3 then
    daycount=daycount+1
    endif
    if OpenMonth=3 and OpenDayOfWeek=0 then
    sunday=Sunday+1
    endif
    If OpenMonth=3 and sunday=2 then//clocks go forward in America to pen = 1-30pm GMT
    changedtime=1
    normaltime=0
    endif
    If OpenMonth=3 and sunday>=4 and  31-daycount<7 then//or OpenMonth=3 and sunday=5 and 31-daycount=0   then
    normaltime=1
    changedtime=0
    daycount=0
    sunday=0
    endif
    //-------------------------------------------------------------------------------------
    //-------------------------------------------------------------------------------------
    //Oct Nov Settings
    //-------------------------------------------------------------------------------------
    If openmonth=10 then
    daycount=daycount+1
    endif
    if OpenMonth=10 and opendayofweek=0 then
    sunday=Sunday+1
    endif
    If OpenMonth=10 and sunday>=4 and 31-daycount<7  then//or OpenMonth=10 and sunday=5 and 31-daycount=0 then
    changedtime=1//1-30pm again as 1-30pm will be 2-30pm US
    normaltime=0
    daycount=0
    sunday=0
    endif
    If openmonth=11 and opendayofweek=0 then
    normaltime=1
    changedtime=0
    sunday=0
    daycount=0
    endif
     
    graph changedtime coloured (255,0,0)
    graph normaltime coloured (0,0,255)
    //graph daycount
    timeframe (4 hours, updateonclose)
    Myamount=1
    If not onmarket then
    buy myamount perpoint at market
    endif
    If not tdcond and onmarket then
    sell at market
    endif
    Daylight-savings-beta.itf
    #168498 quote
    PhilstradingPhilstrading
    Participant
    Senior

    No takers then

    Fixed anyways.

    I’ll put it up for good measure, though I’m still confused why I need days <=4 when March 2019 has 5 Sundays starting on 3rd.. so yet to see if it causes an isue by looking back.. Any comment on that be useful -still to backtest some years to check for consistency and cant really tell why its a week early if I put <4 when it falls on Sunday 3rd March in 2019, so  a long wait for testing live so looking back best bet..  any resolve on why day<4 doesnt work when Sunday falls on 3rd be appreciated..Probably to do with how day is counted on sundays….Line 50 on my code for “weekcount” – foreseen issue possibly if Sunday lands on 4th and its a 4 week month so still looking to tweak it but its woking, just the resolve on <=4 when it lands on 3rd… getting there

    //In the UK the clocks go forward 1 hour at 1am on the last Sunday in March, and back 1 hour at 2am on the last Sunday in October.
    
    //Daylight Saving Time (DST) in the USA starts on the 2nd Sunday in March (go forward an hour) and ends on the 1st Sunday in November.(turn clocks back)
    
    //2nd Sunday (US) changes again last Sunday in March (UK)
    //Last Sunday in Ocober UK changes 1st Sunday in November (US)
    DEFPARAM CumulateOrders = False
    DEFPARAM PreLoadBars    = 5000
    timeframe (15 minutes, updateonclose)
    //-------------------------------------------------------------------------------------
    //March settings
    //-------------------------------------------------------------------------------------
    live=0
    If live=0 then
    if normaltime=1 then
    startT = 040000   //Starting TIME
    endT   = 123000   //Ending TIME
    td1         = 1 AND OpenDayOfWeek = 1 AND OpenTime >= startT AND OpenTime <= endT //Monday
    td2         = 1 AND OpenDayOfWeek = 2 AND OpenTime >= startT AND OpenTime <= endT  //Tuesday
    td3         = 1 AND OpenDayOfWeek = 3 AND OpenTime >= startT AND OpenTime <= endT  //Wednesday
    td4         = 1 AND OpenDayOfWeek = 4 AND OpenTime >= startT AND OpenTime <= endT  //Thursday
    td5         = 1 AND OpenDayOfWeek = 5 AND OpenTime >= startT AND OpenTime <= 040000 //Friday
    tdCond      =  td1 OR td2 OR td3 OR td4 OR td5
    tdclose = 1 AND OpenDayOfWeek = 5 AND OpenTime >= 200000 //Friday close off 9pm
    elsif changedtime=1 then
    startT = 040000   //Starting TIME
    endT   = 123000   //Ending TIME
    td1         = 1 AND OpenDayOfWeek = 1 AND OpenTime >= startT AND OpenTime <= endT //Monday
    td2         = 1 AND OpenDayOfWeek = 2 AND OpenTime >= startT AND OpenTime <= endT  //Tuesday
    td3         = 1 AND OpenDayOfWeek = 3 AND OpenTime >= startT AND OpenTime <= endT  //Wednesday
    td4         = 1 AND OpenDayOfWeek = 4 AND OpenTime >= startT AND OpenTime <= endT  //Thursday
    td5         = 1 AND OpenDayOfWeek = 5 AND OpenTime >= startT AND OpenTime <= 040000 //Friday
    tdCond      =  td1 OR td2 OR td3 OR td4 OR td5
    tdclose = 1 AND OpenDayOfWeek = 5 AND OpenTime >= 200000 //Friday close off 9pm
    endif
    endif
    timeframe (daily)
    
    if not openmonth=3 or not openmonth=10 then
    sunday=0
    weekcount=0
    endif
    if openmonth=3 and OpenDayOfWeek=0 then
    sunday=Sunday+1
    endif
    If openmonth=3 and sunday=2 then//clocks go forward in America to pen = 1-30pm GMT
    changedtime=1
    normaltime=0
    endif
    If openmonth=3 and day<=4 and opendayofweek=0 then
    weekcount=5
    elsif openmonth=3 and weekcount<>5 then
    weekcount=4
    endif
    If openmonth=3 and weekcount=5 and sunday=5  then
    normaltime=1
    changedtime=0
    sunday=0
    weekcount=0
    elsif openmonth=3 and weekcount=4 and sunday=4   then
    normaltime=1
    changedtime=0
    sunday=0
    weekcount=0
    endif
    
    //-------------------------------------------------------------------------------------
    //-------------------------------------------------------------------------------------
    //Oct Nov Settings
    //-------------------------------------------------------------------------------------
    if OpenMonth=10 and opendayofweek=0 then
    sunday =Sunday+1
    endif
    If openmonth=10 and day<=4 and opendayofweek=0 then
    weekcount=5
    endif
    if OpenMonth=10 and weekcount<>5 then
    weekcount=4
    endif
    If OpenMonth=10 and weekcount=5 and sunday=5 then
    changedtime=1//1-30pm again as 1-30pm will be 2-30pm US
    normaltime=0
    sunday=0
    weekcount=0
    endif
    if OpenMonth=10 and weekcount=4 and sunday=4 then
    changedtime=1//1-30pm again as 1-30pm will be 2-30pm US
    normaltime=0
    sunday=0
    weekcount=0
    endif
    If openmonth=11 and opendayofweek=0 then
    normaltime=1
    changedtime=0
    sunday=0
    weekcount=0
    endif
     
    graph changedtime coloured (255,0,0)
    graph normaltime coloured (0,0,255)
    graph day
    timeframe (15 minutes, updateonclose)
    Myamount=1
    If not onmarket then
    buy myamount perpoint at market
    endif
    If not tdclose and onmarket then
    sell at market
    endif
    #168556 quote
    nonethelessnonetheless
    Participant
    Master

    this is the way I account for the time change. Yours is better in that it’s open ended, whereas mine uses the actual dates 2010-2024, but I’d be curious to know if it gives you a different result.

    I only use it for american indices to adjust their opening and closing times on GMT but you can change the Tradetime numbers to whatever…

    //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
    #171746 quote
    PhilstradingPhilstrading
    Participant
    Senior

    I’ll take a look at that, however I found when graphing the results were anomalous, and often differed, so I’ve yet to see how it operates and its a long winded way to write it but I wrote the below code.. The code appeared to graph correctly when backtested across the years..

    I will take a look at your code and graph it to see as its a lot shorter of course..  too ended up inputed specific years….

     

    DEFPARAM CumulateOrders = False // Cumulating positions deactivated
    Defparam preloadbars=1300
    If normaltime=1 then
    StartT=143000
    EndT=144000
    EndTend=144100
    td1         = 1 AND OpenDayOfWeek = 1 AND OpenTime >= startT AND OpenTime <= endT //Monday
    td2         = 1 AND OpenDayOfWeek = 2 AND OpenTime >= startT AND OpenTime <= endT  //Tuesday
    td3         = 1 AND OpenDayOfWeek = 3 AND OpenTime >= startT AND OpenTime <= endT  //Wednesday
    td4         = 1 AND OpenDayOfWeek = 4 AND OpenTime >= startT AND OpenTime <= endT  //Thursday
    td5         = 1 AND OpenDayOfWeek = 5 AND OpenTime >= startT AND OpenTime <= EndT //Friday
    tdcond= td1 or td2 or td3 or td4 or td5
    td6         = 1 AND OpenDayOfWeek = 1 AND OpenTime >= EndTend //Monday
    td7         = 1 AND OpenDayOfWeek = 2 AND OpenTime >= EndTend //Tuesday
    td8         = 1 AND OpenDayOfWeek = 3 AND OpenTime >= EndTend //Wednesday
    td9         = 1 AND OpenDayOfWeek = 4 AND OpenTime >= EndTend //Thursday
    td10        = 1 AND OpenDayOfWeek = 5 AND OpenTime >= EndTend //Friday
    tdclose2= td6 or td7 or td8 or td9 or td10
    //---------------------------------------------------------
    tdclose = 1 AND OpenDayOfWeek = 5 AND OpenTime >= 210000 //Friday close off 9pm
    endif
    if changedtime=1 then
    StartT=133000
    EndT=134000
    EndTend=134100
    td1         = 1 AND OpenDayOfWeek = 1 AND OpenTime >= startT AND OpenTime <= endT //Monday
    td2         = 1 AND OpenDayOfWeek = 2 AND OpenTime >= startT AND OpenTime <= endT  //Tuesday
    td3         = 1 AND OpenDayOfWeek = 3 AND OpenTime >= startT AND OpenTime <= endT  //Wednesday
    td4         = 1 AND OpenDayOfWeek = 4 AND OpenTime >= startT AND OpenTime <= endT  //Thursday
    td5         = 1 AND OpenDayOfWeek = 5 AND OpenTime >= startT AND OpenTime <= EndT //Friday
    tdcond= td1 or td2 or td3 or td4 or td5
    td6         = 1 AND OpenDayOfWeek = 1 AND OpenTime >= EndTend //Monday
    td7         = 1 AND OpenDayOfWeek = 2 AND OpenTime >= EndTend //Tuesday
    td8         = 1 AND OpenDayOfWeek = 3 AND OpenTime >= EndTend //Wednesday
    td9         = 1 AND OpenDayOfWeek = 4 AND OpenTime >= EndTend //Thursday
    td10        = 1 AND OpenDayOfWeek = 5 AND OpenTime >= EndTend //Friday
    tdclose2= td6 or td7 or td8 or td9 or td10
    //---------------------------------------------------------
    tdclose = 1 AND OpenDayOfWeek = 5 AND OpenTime >= 200000 //Friday close off 9pm
    endif
    timeframe (daily)
    once normaltime=1//depending on when started. Reverse for daylight saving opposing
    once changedtime=0
    IF year=2013 or year=2019 or year=2024 or year=2030 or year=2041 then
    march5week=1
    else
    march5week=0
    endif
    IF year=2021 or year=2027 or year=2032 or year=2038 or year=2049 then
    oct5week=1
    else
    oct5week=0
    endif
    if not openmonth=3 or not openmonth=10 then
    sunday=0
    weekcount=0
    endif
    //-------------------------------------------------------------------------------------
    //March settings
    //-------------------------------------------------------------------------------------
    if openmonth=3 and OpenDayOfWeek=0 then
    sunday=Sunday+1
    endif
    If openmonth=3 and sunday=2 then//clocks go forward in America to pen = 1-30pm GMT
    changedtime=1
    normaltime=0
    endif
    If march5week=0 and openmonth=3 and day<=3 and opendayofweek=0  then
    weekcount=5
    endif
    if march5week=1 and openmonth=3 and day<=4 and opendayofweek=0  then
    weekcount=5
    endif
    if march5week=0 and openmonth=3 and weekcount=0 then
    weekcount=4
    endif
    If openmonth=3 and weekcount=5 and sunday=5  then
    normaltime=1
    changedtime=0
    sunday=0
    weekcount=0
    elsif openmonth=3 and weekcount=4 and sunday=4   then
    normaltime=1
    changedtime=0
    sunday=0
    weekcount=0
    endif
    //-------------------------------------------------------------------------------------
    //-------------------------------------------------------------------------------------
    //Oct Nov Settings
    //-------------------------------------------------------------------------------------
    if OpenMonth=10 and opendayofweek=0 then
    sunday =Sunday+1
    endif
    If oct5week=0 and openmonth=10 and day<=3 and opendayofweek=0 then
    weekcount=5
    endif
    if oct5week=1 and openmonth=10 and day<=4 and opendayofweek=0 then
    weekcount=5
    endif
    if oct5week=0 and OpenMonth=10 and weekcount=0 then
    weekcount=4
    endif
    If OpenMonth=10 and weekcount=5 and sunday=5 then
    changedtime=1//1-30pm again as 1-30pm will be 2-30pm US
    normaltime=0
    sunday=0
    weekcount=0
    elsif OpenMonth=10 and weekcount=4 and sunday=4 then
    changedtime=1//1-30pm again as 1-30pm will be 2-30pm US
    normaltime=0
    sunday=0
    weekcount=0
    endif
    If openmonth=11 and opendayofweek=0 then
    normaltime=1
    changedtime=0
    sunday=0
    weekcount=0
    endif
    #171747 quote
    PhilstradingPhilstrading
    Participant
    Senior

    Without recoding it that way then it didnt graph correctly…

    #171748 quote
    PhilstradingPhilstrading
    Participant
    Senior

    Sorry thats some of the program timecode there

Viewing 6 posts - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.
ProRealAI ProRealAI New

Stuck on this ProBuilder code?

Describe what this topic is trying to build, in plain English, and ProRealAI writes the ProRealTime™ indicator, screener or system for you.

Available in 7 languages
Try ProRealAI

Daylight savings anomaly inconsistency


ProOrder: Automated Strategies & Backtesting

New Reply
Author
Summary

This topic contains 5 replies,
has 2 voices, and was last updated by PhilstradingPhilstrading
5 years, 3 months ago.

Topic Details
Forum: ProOrder: Automated Strategies & Backtesting
Language: English
Started: 04/29/2021
Status: Active
Attachments: 1 files
ProRealCode ProRealCode
Loading...