Announcement

Collapse
No announcement yet.

How can I get the previous trading day of

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

  • How can I get the previous trading day of

    any trading day? For example, if in my EFS I need to know the date of the previous trading day of 07/21/2003, which should be 07/18/2003. How can I do it using those functions in eSginal? I tried a program looks like this:

    var newDateObject = new Date(2003, 7, 21, 10, 50, 0);
    var time = newDateObject.getTime()
    var vPriorDay = getPreviousTradingDay(time);
    debugPrintln(time);
    debugPrintln(getValue("time"));
    debugPrintln(vPriorDay.getDay());


    However I got error message: Invalid Date Argument in getPreviousTradingDay()

    It seems the local time object and the object returned by getValue("time") are of different types. Any idea about how to solve my problem?


    Clearpicks

  • #2
    I just keep track of it manually..

    For example...

    I check the current day value...

    var LastDay = 0;
    var PreviousTradingDay = 0;

    var vHour;
    var vMin;
    var vSec;
    var vDay;
    var vMonth;

    function main() {

    var vTime = new Date();
    //---------------------------------------------------
    // Get Time Variables
    vTime = getValue("Time", 0);
    vHour = vTime.getHours();
    vMin = vTime.getMinutes();
    vSec = vTime.getSeconds();
    vDay = vTime.getDate();
    vMonth = vTime.getMonth() +1;

    if (vDay != LastDay) { // day has changed
    PreviousTradingDay = LastDay;
    LastDay = vDay;
    }

    }
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Re: I just keep track of it manually..

      Brad,

      Thanks for the response. But it seems the code you posted doesn't answer my question.


      Clearpick


      Originally posted by Doji3333
      For example...

      I check the current day value...

      var LastDay = 0;
      var PreviousTradingDay = 0;

      var vHour;
      var vMin;
      var vSec;
      var vDay;
      var vMonth;

      function main() {

      var vTime = new Date();
      //---------------------------------------------------
      // Get Time Variables
      vTime = getValue("Time", 0);
      vHour = vTime.getHours();
      vMin = vTime.getMinutes();
      vSec = vTime.getSeconds();
      vDay = vTime.getDate();
      vMonth = vTime.getMonth() +1;

      if (vDay != LastDay) { // day has changed
      PreviousTradingDay = LastDay;
      LastDay = vDay;
      }

      }

      Comment


      • #4
        My code solution...

        In my code, the PreviousTradingDay should be the previous day of trading (the DAY of the previous trading day).

        Just as you explained you wanted. If you want something different, please let me know.

        The only thing is, you need to have at least 2~3 days of data loaded in the chart for my code to work. It kinda keeps a running log of the data (days).

        Brad
        Brad Matheny
        eSignal Solution Provider since 2000

        Comment


        • #5
          Re: My code solution...

          Brad,

          What I want is to find the previous trading day of any day. For example, although there are 100 bars loaded in the daily chart, I need to find out the previous trading day of 01/01/1990. Because 01/01/1990 data is not loaded into the chart, while vTime = getValue("Time", 0) only gets the time of the current bar on which the main() is being executed, therefore I think your code is not what I want. Thanks for your help anyway.


          Clearpicks


          Originally posted by Doji3333
          In my code, the PreviousTradingDay should be the previous day of trading (the DAY of the previous trading day).

          Just as you explained you wanted. If you want something different, please let me know.

          The only thing is, you need to have at least 2~3 days of data loaded in the chart for my code to work. It kinda keeps a running log of the data (days).

          Brad

          Comment


          • #6
            Hello Clearpicks,

            Try the code snippet below. In your original code example, you were trying to pass the value of newDateObject.getTime(), which isn't a date object itself. getPreviousTradingDay(Date) requires a date object. Let me know if this works for you.

            PHP Code:
            var vFlag false;

            function 
            main() {
                if (
            getCurrentBarIndex() == && vFlag == false) {
                    var 
            newDateObject = new Date(200371810500);
                    
            //var time = newDateObject.getTime()
                    
            var vPriorDay getPreviousTradingDay(newDateObject);
                    
            debugPrintln("Date:  " newDateObject);
                    
            debugPrintln("prior day:  " vPriorDay);
                    
            // .getDay() returns 0 for Sunday, 1 for Monday etc.
                    //debugPrintln("Date:  " + newDateObject.getDay());
                    //debugPrintln("prior day:  " + vPriorDay.getDay());
                    
            vFlag true;
                }
                
                return;

            Jason K.
            Project Manager
            eSignal - an Interactive Data company

            EFS KnowledgeBase
            JavaScript for EFS Video Series
            EFS Beginner Tutorial Series
            EFS Glossary
            Custom EFS Development Policy

            New User Orientation

            Comment


            • #7
              It seems that it only works on daily charts. When the template is intraday charts, the returned prior day object is null.


              Clearpicks

              Comment


              • #8
                Hello Clearpicks,

                These functions work much the same way close(-x) works. If the bar that we're requesting data from is not loaded into your chart, the result returns null. If you use a custom time template to ensure that the proper amount of bars are loaded to your chart the routine will return a valid date when you pass 8/18/2003 to getPreviousTradingDay().

                Jason K.
                Project Manager
                eSignal - an Interactive Data company

                EFS KnowledgeBase
                JavaScript for EFS Video Series
                EFS Beginner Tutorial Series
                EFS Glossary
                Custom EFS Development Policy

                New User Orientation

                Comment

                Working...
                X