Announcement

Collapse
No announcement yet.

Quick and Simple rawtime question

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

  • Quick and Simple rawtime question

    Just a simple silly question

    why does

    PHP Code:
    debugPrintln(getValue("rawtime")); 
    Return Yesterday at 23:01:00

    Even when the parket is open?

    Best Regards,

    Tim

  • #2
    Hello Tim,

    That function returns the rawtime, or number of seconds since 1/1/1970, for the bar that your formula is processing. It does not return a value in the format of hh:mm:ss. Without seeing your code it is difficult to say what the problem is. If you are converting the rawtime number into the format you've posted, perhaps there is a problem with that code. Post the formula you're working with and I'll take a look.
    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


    • #3
      Hi Jason,

      Thank you very much.

      It is actually returning 1157497260 Which converts to:

      Tue, 5 Sep 2006 23:01:00 UTC

      Below are portions of what I am using (the entire thing is over 500 lines so I will spare all of it = The Background paint IS working correctly
      Many Thanks Again,

      Tim

      PHP Code:
      f((value2 == 1) && (value1 != 0)) value2 0;
      if ((
      value2 == ) && (value1 == 0) && (v2p == 0) && (lgpo == 0)) {
          
      setBarBgColor(Color.RGB(0,255,0))
          
      lgpo   1;
          
      //Long Position entry
          
      lgstp  ll3p;
          
      Strategy.doLong("Enter 03 Long",Strategy.CLOSE,Strategy.THISBAR,1)
          
      enthhl hhp;
          
      entlll LL;
          
      trigl  = (high() + (avgrg 7));
          
      eatrl  avgrg;
          
      lentp  close();
          
      lgms   ll3p;
          
      eday   1;
          
      entdl  day(0);
      }

      if((
      value2 == -1) && (value1 != 0)) value2 0;
      if ((
      value2 == -1) && (value1 == 0) && (v2p == 0)) {
          
      stpo   1;
          
      // Short Position Entry
          
      setBarBgColor(Color.RGB(255,0,0))
          
      ststp  hh3p;
          
      Strategy.doShort("Enter 03 Short",Strategy.CLOSE,Strategy.THISBAR,1);
          
      enthhs HH;
          
      entlls LL;
          
      trigs  dlow + (avgrg 7);
          
      eatrs  avgrg;
          
      sentp  tdcl;
          
      stms   hh3p;
          
      eday   1;
          
      entds  day(0);
      }
      if (
      stpo || lgpodebugPrintln("InPos") ;

      if (
      tr && lgpo) {
          if (
      low() < hlc3()) {
              
      //debugPrintln("7-Bar Vol Long")
              
      bar7l close();    
              if (
      Strategy.isLong() == trueStrategy.doSell("7 Vol Long Exit"Strategy.STOPStrategy.THISBAR1bar7l);
              
      //End long pos 7 bar vol
              
      if (lgpft == nulllgpft 0;
              
      lgpft  = (tdcl lentp) / eatrl;
              
      lgpftt lgpftt lgpft;
              
      rntot  rntot lgpft;
              
      //debugPrintln("P-L this Trade: " + lgpft + "\n" + "P-L Long Total: " + lgpftt + "\n" + "Running Total: " + rntot);
              //debugPrintln("Long:");
              
      value2 0;
              
      trigl  0;
              
      enthhl 0;
              
      tr     0;
              
      entlll 0;
              
      lx     0;
              
      lgpo   0;
          }
      }
      if (
      Strategy.isLong() == true) {
          
      setBarBgColor(Color.RGB(0,0,255));
          
      lgpo 1
          
      }
      if (
      Strategy.isShort() == true) {
          
      setBarBgColor(Color.RGB(128,82,0))
          
      stpo 1;
          }
      debugPrintln(getValue("rawtime"0)); 

      Comment


      • #4
        Addition to Previous post
        this code reurns yesterday too 1157497260

        PHP Code:
        function preMain(){
        setPriceStudy(false);
        setStudyTitle("Time");
        setCursorLabelName("Realtime",0);
        }

        function 
        main() {
        debugPrintln(getValue("rawtime"0));

        Comment


        • #5
          Hello Tim,

          Based on the code you've posted, it's not clear how you are converting the rawtime figure to the time of 23:01:00.

          Below is a code example that converts the rawtime of each bar to local time. Make note that the return result is off by 1 minute, so you'll need to subtract 60 seconds from the rawtime number before the conversion. The code below puts the time string in the cursor window so you can compare it to the time stamp of each bar.

          PHP Code:
          /* Seconds
          day  86400
          hour  3600
          min     60
          sec      1
          */

          function main() {
              if (
          getCurrentBarIndex() == 0) return;
              var 
          nRawTime getValue("rawtime");
              
              var 
          sTime nRawTime - (Math.floor(nRawTime 86400) * 86400) - 60;
              var 
          nHrs Math.floor(sTime 3600) ;
              var 
          nMns Math.floor((sTime - (nHrs 3600)) / 60);
              var 
          nScs sTime - (nHrs*3600) - (nMns*60);
              
              
          nHrs += 1;
              if (
          nHrs 10nHrs "0" nHrs;
              if (
          nMns 10nMns "0" nMns;
              if (
          nScs 10nScs "0" nScs;
              
          sTime nHrs ":" nMns ":" nScs;
              
              
          debugPrintln(getCurrentBarIndex() + "  sTime: " sTime);
              return 
          sTime;

          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


          • #6
            Good Morning,

            Using your below code I still get no return value of a timestamp on my 0 bar (the current bar being built on the chart). The most current formula output reads. -1 sTime: 24:00:00

            As well as today it is returning 1157583660 From My simple code Which is September 6th at 23:01:00 AM UTC if my calculations are correct.

            Is there a setting that I could have wrong? No other EFS was running at the same time. The Symbol I am using is CL #F, but the time seems to act the same way with other markets as well.

            Appreciate all the help, Thank you,

            Tim
            Attached Files

            Comment


            • #7
              Tim
              With regards to the script not returning a value on bar index 0 I believe that is due to the line
              if (getCurrentBarIndex() == 0) return;
              Comment it out and you should get a value also on the current bar.
              The value of 24:00:00 that is being returned by Jason's script is due to the fact that you are running the efs on a daily chart and the time stamp of the daily bar is 00:00 (which equates to 24:00) You can also see this in the Cursor Window at the label Time which is just below Date.
              The reason why you get 23:01:00 with your script is because rawtime does not take into account Daylight Saving Time. As to the extra minute that is due to what Jason explained in his last reply to you.
              Alex

              Comment


              • #8
                Alex,

                Thank you for the reply, I do see the timestamp, and DST is OK with me, Is there however A way for rawtime to give me the current time of the current bar in a daily interval chart? I Run the below code and the price on the chart updates fine, however the time it returns to the formula output window is 1157583660, any way (other than using my PC clock, I sort of need this to come from the feed) that I can get rawtime to be current on a daily chart?

                Best Regards,

                Tim


                PHP Code:
                function preMain(){
                setPriceStudy(false);
                setStudyTitle("Time");
                setCursorLabelName("Realtime",0);
                }

                function 
                main() {
                debugPrintln(getValue("rawtime"0));

                Comment


                • #9
                  Tim
                  To do that you would need to use the rawtime() function which allows you to base it on a different interval. Enclosed below is an example of how you could do this.
                  You may want to also review Jason's reply in this thread as it provides a much more capable script.
                  Alex

                  PHP Code:
                  function preMain(){
                  setPriceStudy(false);
                  setStudyTitle("Time");
                  setCursorLabelName("Realtime",0);
                  }
                   
                  var 
                  xTime null;
                   
                  function 
                  main() {
                   
                      if(
                  xTime==nullxTime rawtime(inv("1s"));
                      
                  //replace 1s with other interval depending on the desired granularity of the time stamp
                      
                      
                  debugPrintln("Bar time is: "+getValue("rawtime")+" Most recent time is: "+xTime.getValue(0));

                  Comment


                  • #10
                    Many Thanks Alex



                    Tim

                    Comment


                    • #11
                      Tim
                      You are most welcome.
                      In addition to what I suggested in my prior message here is another way you can retrieve the time of the last update. In this case rather than using rawtime and then having to derive the hh:mm:ss from that I use the hour(), min() and second() functions based on the 1s interval (see the corresponding links for the complete syntax).
                      Alex

                      PHP Code:
                      function preMain(){
                      setPriceStudy(false);
                      setStudyTitle("Time");
                      setCursorLabelName("Realtime",0);
                      }
                       
                      var 
                      xHour null;
                      var 
                      xMin  null;
                      var 
                      xSec  null;
                       
                      function 
                      main() {
                       
                          if(
                      xHour==nullxHour hour(inv("1s"));
                          if(
                      xMin==nullxMin minute(inv("1s"));
                          if(
                      xSec==nullxSec second(inv("1s"));
                          
                      //replace 1s with other interval depending on the desired granularity of the time stamp
                          
                          
                      if(xHour.getValue(0)==null||xMin.getValue(0)==null||xSec.getValue(0)==null) return;//null check
                          
                          
                      debugPrintln(padTime(xHour.getValue(0))+":"+padTime(xMin.getValue(0))+":"+padTime(xSec.getValue(0)));
                       
                      }
                       
                      function 
                      padTime(input){
                          if(
                      input<10
                              var 
                      ret "0"+input;
                          else 
                              var 
                      ret input;
                          return 
                      ret;

                      Comment

                      Working...
                      X