Announcement

Collapse
No announcement yet.

DST and rawtime

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • DST and rawtime

    One of my outputs from a study is the trade date and time e.g. for entry or exit. I export this value to Excel which automatically converts it to correct format (yy-mm-dd hh:ss). I derive this value in the efs as follows:

    myTime = (rawtime(0) + 3600 - 60) / 86400 + 25569;

    // +3600 to adjust for one hour time change for DST.
    // - 60 TO adjust for one minute
    // /86400 to convert to days
    // +25569 to add 70 years to make the date compatible with Excel

    This worked fine until October 29, 2006. The +3600 adjustment is no longer required when the clocks went back one hour. While I can adjust the code to test if the date falls before or after October 29, 2006 this would be a temporary solution as I would have to rewrite the code again in Spring of 2007.

    Does anyone have a permanent solution for a code that would adjust for one hour automatically for DST? Any help would be appreciated.

    Hamid.

  • #2
    Hi hamidkassam,

    You can modify the hour based on the number of hours from GMT.

    var today = new Date();
    var offset = today.getTimeZoneOffset(); // in minutes


    I believe this value will change when in daylight saving time and when not, allowing you to make the appropriate adjustment. Just integrate this into your efs code.

    Comment


    • #3
      Hi Steven,

      Thank you for the helpful tip.

      Unfortunately, this method of testing on the offset from GMT may be a little difficult to apply in my efs. The purpose of my efs is to backtest some intraday strategies going back over say three months. Therefore I am looking at past period dates and times and capturing the trade times for exporting to Excel for further analysis.

      Your post prompted me to do some more digging and I eventually came up with a more direct way of getting the date/time instead of using rawtime. Here is the script.

      var myDateTime = null;

      function main() {
      if ( getBarState() == BARSTATE_NEWBAR ) {
      myDateTime = getYear(0) + "-" + getMonth(0) + "-" + getDay(0) + " " + getHour(0) + ":" + getMinute(0) ;
      debugPrintln(myDateTime);
      }
      }

      When writing out the DateTime to an ascii file, Excel would recognize the date and time format and assign the correct numerical values.

      Regards,
      Hamid.

      Comment


      • #4
        Steve,

        I tried what you suggested as below:

        PHP Code:
        function main() {
        var 
        numcontract=500.123;
        var 
        today = new Date();
        var 
        offset today.getTimeZoneOffset(); // in minutes

        debugPrintln("offset = "+offset);

        The debugPrintln is not even executed. It has to do with the two lines of code before that.

        Do you know what's wrong?

        Thank you.

        William

        Comment


        • #5
          Hi William,

          I assume you have the debug window open so that you can see the output.

          I did not see anything that would prevent this from working. I am attaching an efs that you should run. If you can see the output from that, there is something odd with your setup.

          If you would like to troubleshoot further, you can un-comment line 3. Now when you load the efs, this will run a function I put in the efs to output the time in addition to line 1

          Please let me know if you have problems with this.
          Attached Files

          Comment


          • #6
            Hi William,

            The problem appears to be due to the Z in getTimeZoneOffset. This should have been getTimezoneOffset. A handy reference for the Date() methods is here...



            They are also in the Knowledgebase as well.

            Comment


            • #7
              Thanks, Steve. It works fine. Now I just have to wait for the next time change and confirm that it really works.

              William

              Comment

              Working...
              X