Announcement

Collapse
No announcement yet.

Time in bar

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

  • Time in bar

    I'm trying to perform an action in a chart based on if a time-of-day falls inside the start and end times for the creating of that bar.

    In the main() function, when receiving historic bars, is there anyway of discovering when that bar ended (the time) before the BARSTATE_NEWBAR event is received?
    Standing on the shoulders of giants.

  • #2
    Hello Wildfiction,

    Yep, this is now possible with EFS2 and the inv() function. However, you will only be able to get the exact time stamp going back 10 days. The reason is because to get this time stamp we have to look at a 1T interval. We only have 10 days of historical tick data. What you do is build the time stamp using hour(), minute() and second() (see Series Functions) where you pass the 1T interval to the sym/inv parameter. The EFS2 engine is handling all the time synchronization routines for us so we don't need to worry about finding the relative bar index of the appropriate tick for the lower time frame interval. By default, when accessing a lower time-frame series on a higher time-frame chart, requesting the bar index of 0 for the lower time-frame series returns the last data point of that series that occurred within the bar interval of the higher time-frame chart where the formula is processing. Here's the code.

    PHP Code:
    var bInit  false;
    var 
    xClose null;

    function 
    main() {
        if (
    bInit == false) {
            
    xClose close(inv("1T"));
            
    bInit  true;   
        }
        
        var 
    vTickTime tickTime("1T");
        var 
    nClose    xClose.getValue(0);
        if (
    vTickTime != null && nClose != null) {
            
    debugPrintln("bar " getCurrentBarIndex() + " close: " 
                (
    xClose.getValue(0)).toFixed(2) + " at " vTickTime);
        }
        
        return;
    }


    function 
    tickTime(n) {
       var 
    nHour hour(0inv(n));
       var 
    nMinute minute(0inv(n));
       var 
    nSecond second(0inv(n));
       var 
    temp "" + ((nHour 12) ? nHour 12 nHour);
       if (
    nHour == 0temp "12";
       
    temp += ((nMinute 10) ? ":0" ":") + nMinute;
       
    temp += ((nSecond 10) ? ":0" ":") + nSecond;
       
    temp += (nHour >= 12) ? " P.M." " A.M.";
       return 
    temp;


    Run this on something like a 60-min IDC chart on your end and compare to a time and sales window. You will see in the formula output window that it identifies the last trade and it's exact time stamp for each 60-minute bar. To get the full 10 days, be sure to set up your time template to load 10 days of history for a T interval.



    You could use a 1-minute interval to get a time stamp going back 120 days, but the time stamp would represent the start time of the last 1-minute bar within the higher time-frame bar.

    Hope this helps.
    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
      Many thanks Jason - that helped a lot.
      Standing on the shoulders of giants.

      Comment


      • #4
        You're most welcome.
        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