Announcement

Collapse
No announcement yet.

rawtime != time of bar

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

  • rawtime != time of bar

    Hi,

    I'm using 1 minute bar on JPY A0-FX, and at the end of bar time 15:05 I use rawtime() to return a value, which is supposed to be 15:06 after the conversion. However, I found that if there is no data bar until the bar time is 15:08, the rawtime() returns a time that is equivalent to 15:06, which is clearly wrong as the bar has been skipped and has become 15:08 by now instead of 15:06 from the converted rawtime() stamp.

    Is there a way to correctly get the rawtime even though some bars are skipped?

    Thanks,
    William

  • #2
    Re: rawtime != time of bar

    Hi William,

    The time basis for any bar is the first tick of the new bar, i.e. the beginning of a bar. There is no bar-Time that cooresponds to the end of a bar. There are several ways that you can estimate this, but it will be a kludge (estimate) regardless of whether you do this with historical bars or in real time. The kludge can be resource intensive or simple.

    My recommendation is that you try and work around not having the data in a simple fashion, e.g. subtract a second from the next bar time.

    Originally posted by wwong112
    Hi,

    I'm using 1 minute bar on JPY A0-FX, and at the end of bar time 15:05 I use rawtime() to return a value, which is supposed to be 15:06 after the conversion. However, I found that if there is no data bar until the bar time is 15:08, the rawtime() returns a time that is equivalent to 15:06, which is clearly wrong as the bar has been skipped and has become 15:08 by now instead of 15:06 from the converted rawtime() stamp.

    Is there a way to correctly get the rawtime even though some bars are skipped?

    Thanks,
    William

    Comment


    • #3
      Hi Steve,

      I do recognize that the rawtime() gives the beginning of a bar. Therefore, in my example, after the bar of which the time began at 15:05, I expect the rawtime() to return 15:06. However, because the bar starting at 16:06 and 15:07 were skipped due to lack of trade, instead the rawtime() returns 16:06 even though the next bar begins at 15:08.

      I hope I made myself clear.

      William

      Comment


      • #4
        Hi William,

        What you are saying doesn't make sense to me. First, how do you know that the next bar started at 15:08, and when this occured, did you query rawtime at that point?

        At this point, I recommend you post your code (or a working example which demonstrates the issue), and any data you recorded. It appears there is either an issue with your execution logic, or one with platform functionality.

        Comment


        • #5
          Steve,

          I have been looking (staring) at the chart and see that at the end of every bar, a new bar is generated, the rawtime() would return the beginning of the next and new bar. As I continued to monitor the bar movement with my own eyes, I noticed that after the bar 15:05, couple of bars (15:16 and 1507) were missing due to no trade activity. The next bar that came was 15:08, and the rawtime() returned 15:16 instead of 15:08.

          It would be very hard for anyone to duplicate this because you would need missing bars as I had experienced today which was due to a holiday. As for the code, there's just the rawtime function. that's it.

          You code try the following code on JPY A0-FY on 1 min interval at bars 14:20 and 14:23, there are couple of bar real missing bars at 14:21 and 14:22 on Feb 19th, 2007.

          I am not sure if this phenomenon only appears in live data stream, and not on historical data.

          PHP Code:
          function main()
          {
          debugPrintln(rawtime());

          Comment


          • #6
            William,

            How did you confirm the bar had ended other than the verifying the time of day? Did you use a test for a new bar? When I asked you to post your code, I wanted to see how you were coming to the conclusion that a new bar had arrived. Based on what you have posted, you are confirming only that a new tick has arrived, and not confirming that anything else is occuring.

            I recommend that you output additional information such as bar minute, seconds, hour, actual time - new Date().getTime(), and barstate in addition to providing how you calculate the time equivalence calculation using rawtime() to hours and minutes.

            Then, since you are outputting this via debugPrintln, simply go to the C:\Program Files\eSignal folder and open the formulaoutput.log file and copy the appropriate output. This plus a sufficient efs will document the condition will be good information to help eSignal troubleshoot the condition.

            Comment


            • #7
              Here's a snippet of my code. I'm using rawtime() because it is unique and passing it to a function via a DLL call.

              I am expecting that rawtime gives me the time at the end of each bar because of the setComputeOnClose(). However,
              as I'm charting with 1 min interval on JPY A0-FX, I can see that regularly a bar somewhat starts at the beginning of each minute and ends at the end of each minute. I use "somewhat" because I visually determine that the bar actually starts at the first trade of each minute. So, there's a trade 30 seconds into the minute, the bar would start at 30 into the minute instead of at the beginning of the minute.

              In short, I simply want to get the unique time, in the same format as rawtime, at the end of every minute (as I'm chart in 1 min interval). The way that I am doing it gives me the time at first tick of each bar. This can be a problem for me if the first tick of next bar happens in 3 minutes even if I'm plotting in 1 minute interval.

              William


              PHP Code:
              function preMain() {
                  
              setPriceStudy(true);        
                  
              setComputeOnClose();
              }

              function 
              main( ) 
              {    
                 
              debugPrintln("end of bar is at "+rawtime());   
                 
              debugPrintln(hour(0)+":"+minute(0)+":"+second(0));
                 
                 
              //call DLL function and use time as an input
                 //{call("outputrt",rawtime()));}

              Comment


              • #8
                William
                rawtime() returns the bar time which in eSignal corresponds to the beginning of an interval. The value returned by this function is constant throughout the interval so you cannot use it to determine the closing time of a bar.
                To do what you want you need to use the Date Object to retrieve the system time at every tick. Then at each instance of BARSTATE_NEWBAR and prior to retrieving the time of the most recent tick you assign the last retrieved time to another variable which will represent the closing time of the prior bar (see the sample code sample enclosed below where PriorBarCloseTime represents the closing time of the prior bar expressed in the same format as rawtime()).
                Alex

                PHP Code:
                var CurrentTime 0
                var PriorBarCloseTime 0;

                function 
                main(){

                    var 
                SystemTime = new Date();
                    var 
                BarTime rawtime(0);
                    
                    if(
                getBarState() == BARSTATE_NEWBAR){
                        
                PriorBarCloseTime CurrentTime;
                    }

                    
                CurrentTime parseInt(SystemTime.getTime()/1000)-(SystemTime.getTimezoneOffset()*60);
                    
                    
                debugPrintln(BarTime+"  "+PriorBarCloseTime)

                Comment


                • #9
                  Let me see if I understand you correctly.

                  Assuming I'm in 1 min interval and ComputeOnClose is set. The rawtime gives me the time when the first tick of the new bar occurs. If that tick happens to be 10 minutes and 12 seconds from the end of last bar, rawtime would give me the time that is approximately 10 minutes and 12 sec from the time the last bar ended. Is that correct?

                  W.

                  Comment


                  • #10
                    William
                    That is not correct. The rawtime() function returns the bar time (expressed in seconds from January 1st 1970) ie the time to which that bar corresponds based on its interval and not the time at which the bar is created.
                    For example on a 1 minute chart the bars times will be 9:30, 9:31, 9:32, etc regardless of when each of those bars was created.
                    As I indicated in my prior reply if you want to determine the actual closing (or opening) time of a bar you need to use the Date Object to retrieve the system (ie your computer's) time. Note that this can only occurr in real time. Also in order to do this the formula must not be set to compute on close.
                    Alex

                    Comment


                    • #11
                      Thanks, Alex.

                      If I want to find out how fast a segment of my code is, is the following correct? Because I tried it and both time stamp give me the same millisecond which cannot be right.

                      William

                      PHP Code:
                      //inside function Main()


                      var SystemTime = new Date();
                      debugPrintln(SystemTime.getMilliseconds());

                      {...
                      segment of code here...}

                      debugPrintln(SystemTime.getMilliseconds()); 

                      Comment


                      • #12
                        William
                        The getMilliseconds() method does not actually retrieve the time but it only extrapolates the milliseconds from the time retrieved on each iteration of the script by the Date Object which is why the two timestamps are the same.
                        Alex

                        Comment


                        • #13
                          Thank you.

                          William

                          Comment


                          • #14
                            William
                            You are most welcome
                            Alex

                            Comment

                            Working...
                            X