Programmed Daylight Savings Time Change Code Block

Forums ProRealTime English forum ProOrder support Programmed Daylight Savings Time Change Code Block

Viewing 15 posts - 1 through 15 (of 15 total)
  • #66074

    Hello coders I’m wondering if anyone has written some code to automatically identify when a daylight saving time change is going to happen for example based on the last Sunday of the March?

    I was looking at the documentation and I couldn’t think of anything quick to use to work out the last Sunday of March.

    The initial ideas I have are:

    1. a bunch of IF statements or just enough for a 1 year period.
    2. loop counter to count the number of Sunday for the month of March but this might vary year to year so I have to look into it further

    Any other suggestion or premade solutions would be highly appreciated.

    Thanks for your suggestions and help.

    #66081

    I think I have a start of a solution but I know this isn’t correct yet because I need to account for the days after Sunday in March and days before the last Friday in October:

    I will try to solve it over the weekend if nobody else has.

    #66086

    I use the following code snippet to close positions on friday nights. It also takes care of daylight saving. The attached snippet is for EUR/USD and has to be adapted to the underlying in question depending on where the asset trades.

     

    #66087

    Something like this?

    Last Sunday of March, it’s DST:

     

    #66406

    Nicolas I have worked out the code for the last Friday of the Month (I think) but I’m not sure how to get the days before the last friday of the month = 10?

     

    #66407

    You should parenthesis to separate your 2 conditions:

    (code not tested).

    #66644

    Nicolas I still can’t solve this – I’ve tried many combinations but no solution 🙁

    Well I can solve this but its not pretty I have to use AND + OR statements to trade on the last 6 days to the last Friday but there must be a better or more elegant way.

    Also, if you use Result it the graph doesn’t show a trade on the Sunday but if you use BUY and SELL for some reason it will execute a trade on Sunday in October?

     

    #66888

    I came up with a reasonable solution

    I also remembered it’s possible to use currentdayofweek which should produce the same results and it does for most parts. However when I run a backtest for AUDUSD h1 22K for some reason a comparison of the 2 reports shows there’s difference in results. I compare the list of trades in  a spreadsheet (here as a web page and as spreadsheet) and all the trades are the same they match but the statistics are not the same?

    Then I increase to 100K bars and scanning through the trades visually I find an erroneous trades on:

    • Sunday 27 October 2002 at 20:00
    • Sunday 1 November 2003 at 20:00
    • etc…
    • and the good thing about this error is that it doesn trade at the start of the Sunday when the market opens but I guess its delaying the trade.

    Also, when you look at the candles and the spreadsheet sometimes trades close every hour but other times they do not and they close on the following hour with 2 units closing/exiting.

    Is there an error with the backtest engine?

    #66966

    Then I increase to 100K bars and scanning through the trades visually I find an erroneous trades on:

    • Sunday 27 October 2002 at 20:00
    • Sunday 1 November 2003 at 20:00
    • etc…
    • and the good thing about this error is that it doesn trade at the start of the Sunday when the market opens but I guess its delaying the trade.

    On 2nd inspection with fresh eyes the actual problem is there are extra bars starting from: Sunday 27 October 2002 at 15:00?

    #69257

    Nicolas I think there’s a bug with PRT – I know you’re very busy but last time I submitted my time code related issue to PRT, I received no response.

    This is what happened. PRT Timezone set to UTC 0

    The rest of my instructions a wrapped in the following condition  if tradingHours = OFF then don’t open new positions or close positions.
    So for some reason the system decided to edit the positions by removing the limit orders UTC 0, Thursday, at: 23:00, and then UTC 0, Friday 00:00 reinstate them.
    I hope there’s an error somewhere in my code so that this can be resolved quickly but I’m struggling to see it.
    Thanks for your help.
    #70922

    UPDATE: IG users if you trade FX and want to use TIME conditions please ensure you have the timezone settings set to the default local times zone setting for FX instruments.

    If you don’t, then time settings will not work properly because even if you set the system to some other time zone and code for it eg. +10 it will still treat dayofweek/currentdayofweek as UTC: 0/+1

    It would have been really good if someone at IG or someone from PRT could have provided this information to me/us but sadly no.

    #179599

    Bonjour,

    Avez-vous trouvé une solution sans bug pour ce problème fuseau horaire ?

    Merci d’avance !

    Hello,

    Did you find a bug free solution for this time zone problem?

    Thanks in advance !

    #179610

    Only post in the language of the forum that you are posting in. For example English only in the English speaking forums and French only in the French speaking forums.

    Thank you 🙂

     

    #179634

    I did write a lot of inefficient code to manage the daylight savings changes but it’s a long time ago now, and I’m not actively using PRT anymore.

    #179638

    Thanks for the information !

    Claudio

Viewing 15 posts - 1 through 15 (of 15 total)

Create your free account now and post your request to benefit from the help of the community
Register or Login