Announcement

Collapse
No announcement yet.

Formatting Time

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

  • Formatting Time

    I'm trying to format a time stamp but I'm having some trouble. Using the code below each time I want vDTime works fine but it seems really inefficient to repeat it every time. Unfortunately, if I separate it out (i.e., put it at the top of my script instead of within each statement requiring it), I get the time but it isn't formatted. Any suggestions? I don't mind the work of repeating this but I don't want to muck things up either. Thanks.

    // Setup Time Stamp
    if(getHour() < 10);
    vHour = "0" + getHour();
    if(getHour() >= 10);
    vHour = getHour();
    if(getMinute() < 10);
    vMinute = "0" + getMinute();
    if(getMinute() >= 10);
    vMinute = getMinute();

    vDTime = vHour + ":" + vMinute;

  • #2
    Time Stamp

    Let me try....


    var vTime = new Date();
    var vHour;
    var vMinute;

    // Setup Time Stamp
    if(vTime.getHour() < 10) {
    vHour = "0" + vTime.getHour();
    } else {
    vHour = vTime.getHour();
    }

    if(vTime.getMinute() < 10) {
    vMinute = "0" + vTime.getMinute();
    } else {
    vMinute = vTime.getMinute();
    }

    vDTime = vHour + ":" + vMinute;


    This should work...

    Brad
    Brad Matheny
    eSignal Solution Provider since 2000

    Comment


    • #3
      Thanks. Using vTime.getHour instead of just getHour (and the same for minutes) caused the whole study to fail (which I didn't expect since this is just for a time stamp) but switching to an if...else approach did the trick.


      // Setup Time Stamp
      if(getHour() < 10) {
      vHour = "0" + getHour();
      } else {
      vHour = getHour();
      }
      if(getMinute() < 10) {
      vMinute = "0" + getMinute();
      } else {
      vMinute = getMinute();
      }

      vDTime = vHour + ":" + vMinute;

      Comment


      • #4
        My guess is you didn't define vTime if the study failed, but your way is better anyway, as it uses the rawtime interface vs. creating a date object. Creating a date object is rather a resource hog in efs.
        Garth

        Comment


        • #5
          "My guess is you didn't define vTime if the study failed, but your way is better anyway, as it uses the rawtime interface vs. creating a date object. Creating a date object is rather a resource hog in efs."

          Actually, I defined vTime as:

          var vTime = getValue("Time");

          I used vTime in two ways. First, to define when the system can trade:

          // Trading Time
          if ( ((vTime.getHours() > vStartHour) && (vTime.getHours() < vEndHour)) ||
          ((vTime.getHours() == vStartHour) && (vTime.getMinutes() >= vStartMin)) ||
          ((vTime.getHours() == vEndHour) && (vTime.getMinutes() <= vEndMin)) ) {

          And second, to identify the day's opening price:

          // Identify the Open
          if(vTime != null) {
          var vFirstIndex =getFirstBarIndexOfDay(vTime);
          if(vFirstIndex != null) {
          vTodaysOpen = getValueAbsolute("open", vFirstIndex);
          }
          }

          Are you suggesting that I stop using vTime? As far as using it to define when the system can trade, that seems easy enough but what about when I use it to get the day's opening price?

          Thanks.

          Comment


          • #6
            If you are using FirstBarIndexOfDay() or a few other functions that use the return of getValue("rawtime"), then you are stuck using that method to deal with time issues. Which means you will be having to create a date object and the penalties associated with that.

            Last I heard eSignal had plans to support rawtime with these, but I don't think they have been implemented yet. They did recently implemet the getHour(), etc which uses rawtime...so progress is being made.
            Garth

            Comment

            Working...
            X