Announcement

Collapse
No announcement yet.

multi-interval NEWBAR sync query (ComputeOnClose())

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • multi-interval NEWBAR sync query (ComputeOnClose())

    Just revisiting some multi-interval efs, I can't work out why the NEWBAR for an auxillary interval does not seem to occur when I thought it did (it seems to be delayed by one chart candle, this is a ComputeOnClose script). Please see description in the efs sample.


    PHP Code:
    // Unexpected time of arrival of NEWBAR for an auxillary interval. [r4, 2008-02-11, using ES]

    // With, say, chart interval = 5mins, and an aux Interval of 30mins, and ComputeOnClose, 

    // As expected for the chart interval, I get the NEWBAR for, say, the candle starting at 07:55 when it closes at the first tick after 08:00.
    // And if I print the candle time (getHour() and getMinute()) I see the proper 07:55 start time.

    // For the aux interval, I expect to see NEWBAR at the the first tick after the 30 min period ends, too, hence I would expect the
    // 30 minute candle starting at 07:30  to also complete at the first tick after 08:00, 
    // ie at the same tick (and call to main()) as the 07:55 5 minute candle ends.


    // BUT I'm seeing the "aux" interval's NEWBAR delayed by one period of the chart interval, 
    // ie it completes just after 08:05 at the same main() call as the 08:00 5 minute candle.
    // And when I access it with getHour() and getMinute() I get the time of 08:00, ie the new 30 minute candle, not the completed one.

    // This occurs both with the "live" candles and the historic candles in the chart, 
    // but is easier to "understand" with the "live" candles as you can also look at the Wall Clock time.
    //
    // Am I wrong or is this a bug?

    // This sample outputs to the Output window only, not the chart

    function preMain() {

        
    setPriceStudy(true);
        
    setStudyTitle("Test NEWBAR timing for 2nd Interval - see Output Window");
        
    debugPrint("Test NEWBAR timing for 2nd Interval, does not work wth TickReplay\n");
        
       
    setComputeOnClose();

    }

    var 
    mbStudyInit false;
    var 
    msIntChart null// chart
    var msIntAux null// auxillary

    var mserSym null// Aux series

    var gnCCO 0// With ComputeOnClose the nCandle argument for the closing candle = 0

    function TwoDigits(n) {// for n is 0 to 60 usually, ie time / date in hh mm ss etc
        
    var n.toString();
        if (
    s.length == 1"0"+s;
        return 
    s// ignore longer
    }
    function 
    WallClockString() {
        var 
    dDate = new Date();  
        return 
    TwoDigits(dDate.getMonth())+"/"+TwoDigits(dDate.getDate())+"-"
    +TwoDigits(dDate.getHours())+":"+TwoDigits(dDate.getMinutes())+":"+TwoDigits(dDate.getSeconds());
    }
        
    function 
    BarTimeOnlyString(nCandle,mserSym) { 
        if (
    mserSym == null) { // how do this properly?
            
    if (getMonth(nCandle) == null) return "No candle?";
            return 
    TwoDigits(getHour(nCandle))+":"+TwoDigits(getMinute(nCandle));
        } else {
            if (
    getMonth(nCandle,mserSym) == null) return "No candle?"
            return 
    TwoDigits(getHour(nCandle ,mserSym))+":"+TwoDigits(getMinute(nCandle ,mserSym));
        }
    }

    function 
    main() {
        
    debugPrint(" \n");
        
    debugPrint("Main() called at WC = " WallClockString() + " \n");
        var 
    nBSChart getBarState();

        if (
    nBSChart == BARSTATE_ALLBARS) {
            
    debugPrint("ALLBARS\n");
            return; 
    // wait for real bars I find better
        
    }

        if(
    mbStudyInit == false){
             if (
    isComputeOnClose()) {
                
    gnCCO 0
                
    debugPrint("ComputeOnClose, nCandle for CandleJustClose = " gnCCO "\n");
            } else {
                
    gnCCO = -1
                
    debugPrint("ComputeOnClose NOT SET - Not intened in this test\n");
            }

            
    msIntChart =  getInterval(); 
            
    msIntAux "30";
            
    //msIntAux = "5";
            
    if (msIntChart != msIntAux) {
                
    debugPrint("Diff Int: " msIntChart ", " msIntAux "\n");
            } else {
                
    // ???
                
    debugPrint("Diff Int NOT SET\n");
            }
            
    mserSym sym(getSymbol().toUpperCase()+","+msIntAux); // same symbol, aux interval, for getting Candle time
            
            
    mbStudyInit true;
        }

        var 
    nIntBS getBarStateInterval(msIntAux); // http://forum.esignalcentral.com/showthread.php?s=&threadid=20800 only one per interval per _main().
        
        
        
    if (nBSChart == BARSTATE_NEWBAR) {
            
            var 
    sText BarTimeOnlyString(gnCCO); //candle time of just ending displayed bar, ie at just after 8:00 this would be the 07:55 candle
            
    debugPrint("NEWBAR (Chart), Start Time of Completed Candle =" sText+"\n");
        }
        if (
    nIntBS == BARSTATE_NEWBAR) {
            
            var 
    sTextBarTimeOnlyString(gnCCO,mserSym); //candle time of just ending aux interval, ie, at juust after 08:00 this would be the 07:30 candle
            
    debugPrint("NEWBAR (aux),   Start Time of Completed Candle =" sText+"\n");
        }

        
       return;

    Last edited by Dave180; 02-11-2008, 04:05 AM.

  • #2
    Here is some sample output, with annotations:

    Code:
     -------- Typical output  
     Note that WC = my local PC in the UK, ie GMT
     The Candle times are Exchange and the symbol is ES (ie Chicago = CET)
     So 14:00 UK = 08:00 Candle time. In the comments below I have omitted the "hour" for clarity
     Chart interval is 5 mins, aux interval is 30 mins
     
     Note that as well as the 5 minute "delay", the candle identified by nCandle = 0 seems to be 
     not the "just completed" one (ComputeOnClose() is set),
     BUT the one that is current, see the candle times reported below and the comments.
     
     
    Main() called at WC = 01/11-13:25:00                     <----- main() called at end of a 5 min period, at xx:25
    NEWBAR (Chart), Start Time of Completed Candle =07:20    <----- 5 min candle started at xx:20 ends as expected
     
    Main() called at WC = 01/11-13:30:00                     <----- Main() called at end of a 30min and 5min period, at xx:30
    NEWBAR (Chart), Start Time of Completed Candle =07:25    <----- 5 min candle started at xx:25 ends, where is the 30min candle from xx:00?
     
    Main() called at WC = 01/11-13:35:00                     <----- main() called at end of next 5 min period, xx:35
    NEWBAR (Chart), Start Time of Completed Candle =07:30    <----- 5 min candle ends as expected
    NEWBAR (aux),   Start Time of Completed Candle =07:30    <----- And here is the 30min candle 
                                                             <      BUT see that the start time is xx:30 (not xx:00)
                                                             <      The implication here is that getMinute(0, auxseries) has returned the "current" 
                                                             <      30min candle (started at xx:30, ie 5 mins ago),
                                                             <      not the completed one that started at xx:00
     
    Main() called at WC = 01/11-13:40:00 
    NEWBAR (Chart), Start Time of Completed Candle =07:35
     
    Main() called at WC = 01/11-13:45:00 
    NEWBAR (Chart), Start Time of Completed Candle =07:40
     
    Main() called at WC = 01/11-13:50:07 
    NEWBAR (Chart), Start Time of Completed Candle =07:45
     
    Main() called at WC = 01/11-13:55:08 
    NEWBAR (Chart), Start Time of Completed Candle =07:50
     
    Main() called at WC = 01/11-14:00:00 
    NEWBAR (Chart), Start Time of Completed Candle =07:55
     
    Main() called at WC = 01/11-14:05:01 
    NEWBAR (Chart), Start Time of Completed Candle =08:00
    NEWBAR (aux),   Start Time of Completed Candle =08:00
     
    Main() called at WC = 01/11-14:10:00 
    NEWBAR (Chart), Start Time of Completed Candle =08:05
     
    Main() called at WC = 01/11-14:15:01 
    NEWBAR (Chart), Start Time of Completed Candle =08:10
     
    Main() called at WC = 01/11-14:20:01 
    NEWBAR (Chart), Start Time of Completed Candle =08:15

    Comment


    • #3
      Following on from the apparent time slip of the auxiliary interval candle, I looked the prices.
      I was curious as to what would happen if I investigated the close() price of the (longer) auxiliary interval each time the chart interval generated a NEWBAR (this is ComputeOnClose()) remember.
      In this output each call to main() also prints the aux interval data, but it is designated “BAR” when it is not a “NEWBAR”, and the close() is printed.

      There are three separate examples, each demonstrating unexpected behaviour.

      1) Here is an output from a tick replay, the intervals were changed to 1 and 5 mins (vs 5 and 30), and as this is “replay” the wall clock times are meaningless.

      Code:
      Main() called at WC = 01/12-21:49:39 
      NEWBAR (Chart), Start Time of Completed Candle =01:41, close() = 1355.25    < --- Correct price as shown on chart for 1 min candle close
         BAR (aux),   Start Time of Current-0 Candle =01:40, close() = 1355.75    < --- The 5 minute candle is showing the close price
                                                                                  < --- BEFORE IT IS KNOWN BUT here we are seeing what the 
                                                                                  < --- close will be in 4 minutes time! Good trick, seems to 
                                                                                  < --- mean that tick replay has problems
      
      Main() called at WC = 01/12-21:49:39 
      NEWBAR (Chart), Start Time of Completed Candle =01:42, close() = 1355.5
         BAR (aux),   Start Time of Current-0 Candle =01:40, close() = 1355.75
      
      Main() called at WC = 01/12-21:49:39 
      NEWBAR (Chart), Start Time of Completed Candle =01:43, close() = 1355.5
         BAR (aux),   Start Time of Current-0 Candle =01:40, close() = 1355.75
      
      Main() called at WC = 01/12-21:49:39 
      NEWBAR (Chart), Start Time of Completed Candle =01:44, close() = 1355.75   < --- The xx:44 1 min candle has closed, so should the 5 min
         BAR (aux),   Start Time of Current-0 Candle =01:40, close() = 1355.75   < See we didn’t get a “NEWBAR” (as now known), but the close() 
                                                                                 < --- price is (still) right, ie same as 1 min bar
      
      Main() called at WC = 01/12-21:49:39 
      NEWBAR (Chart), Start Time of Completed Candle =01:45, close() = 1355.25   < --- 1stst 1 min bar of next 5 min period shows correct close()
      NEWBAR (aux),   Start Time of Completed Candle =01:45, close() = 1354.5    < --- BUT the 5 min bar has only now gone “NEWBAR”, 
                                                                                 < --- however (for nCandle = 0), as before, we get the price 
                                                                                 < --- for the close of the “new” 5 minute candle (again, 
                                                                                 < --- before we know what it will be!)
      So, from tick replay it appears that there is a new problem with the longer interval aux close() printing a figure that essentially is not yet known (ie the close() value before the close occurs).

      2) Here is some output from the “historic” bars (those from before the time the chart was loaded) on a live ES chart, again the wallclock is meaningless, we have a 5 min chart interval and 30 minute auxiliary interval

      Code:
      Main() called at WC = 01/12-22:22:03 
      NEWBAR (Chart), Start Time of Completed Candle =14:35, close() = 1340.75   < --- Correct
         BAR (aux),   Start Time of Current-0 Candle =14:30, close() = 1349.5    < --- Like tick replay, the 30min candle shows the 
                                                                                 < --- close() before it is known!
      
      Main() called at WC = 01/12-22:22:03 
      NEWBAR (Chart), Start Time of Completed Candle =14:40, close() = 1343.25
         BAR (aux),   Start Time of Current-0 Candle =14:30, close() = 1349.5
      
      Main() called at WC = 01/12-22:22:03 
      NEWBAR (Chart), Start Time of Completed Candle =14:45, close() = 1346.75
         BAR (aux),   Start Time of Current-0 Candle =14:30, close() = 1349.5
      
      Main() called at WC = 01/12-22:22:03 
      NEWBAR (Chart), Start Time of Completed Candle =14:50, close() = 1345.75
         BAR (aux),   Start Time of Current-0 Candle =14:30, close() = 1349.5
      
      Main() called at WC = 01/12-22:22:03 
      NEWBAR (Chart), Start Time of Completed Candle =14:55, close() = 1349.5   < --- The last 5 min candle in the 30 min period
         BAR (aux),   Start Time of Current-0 Candle =14:30, close() = 1349.5   < --- No “NEWBAR” for the 30 min candle, but the 
                                                                                < --- close is right 9still!)
      
      Main() called at WC = 01/12-22:22:03 
      NEWBAR (Chart), Start Time of Completed Candle =15:00, close() = 1351
      NEWBAR (aux),   Start Time of Completed Candle =15:00, close() = 1349.75  < --- As before, the NEWBAR turns up late
      Again the “time machine” gives us the close() before the bar closes.

      3) And here we have the normal “as it happens” bar output (ES overnight, so sometimes a few seconds delay between the interval closing and the next tick)


      Code:
      Main() called at WC = 01/13-03:40:03 
      NEWBAR (Chart), Start Time of Completed Candle =21:35, close() = 1347.25  < -- 2nd 5 min bar in a 30min candle closes
         BAR (aux),   Start Time of Current-0 Candle =21:30, close() = 1347     < -- The value from the close() of the 30min candle is different
                                                                                < ---
      Main() called at WC = 01/13-03:45:05 
      NEWBAR (Chart), Start Time of Completed Candle =21:40, close() = 1346		
         BAR (aux),   Start Time of Current-0 Candle =21:30, close() = 1346	  < --- Same close
      
      Main() called at WC = 01/13-03:49:59                                      < --- This PC clock must be a fraction fast
      NEWBAR (Chart), Start Time of Completed Candle =21:45, close() = 1345.75  < --- Different close
         BAR (aux),   Start Time of Current-0 Candle =21:30, close() = 1345.5
      
      Main() called at WC = 01/13-03:55:01 
      NEWBAR (Chart), Start Time of Completed Candle =21:50, close() = 1344.5
         BAR (aux),   Start Time of Current-0 Candle =21:30, close() = 1344.5
      
      Main() called at WC = 01/13-03:59:59 
      NEWBAR (Chart), Start Time of Completed Candle =21:55, close() = 1345.25  < ---Last 5 min candle in 30min interval closes
         BAR (aux),   Start Time of Current-0 Candle =21:30, close() = 1345.25  < ---No close here, as usual, but at least the 
                                                                                < --- price is correct, coincidence or not?
      
      Main() called at WC = 01/13-04:05:02 
      NEWBAR (Chart), Start Time of Completed Candle =22:00, close() = 1347
      NEWBAR (aux),   Start Time of Completed Candle =22:00, close() = 1347     < --- As usual, 30 min interval closes late, and 
                                                                                < --- close() of what one think is the 21:30 candle 
                                                                                < --- is reported as the current value of the 22:00 candle
      So, how can at the close of the 5 min candle starting at :35 min candle (1347.25) the close() of the 30min candle (ie the “last”, = 1347), be different? Here are the ticks from either side of the close of the 5min candle starting at :35 min

      Code:
      T,080213,033950,1347.25,1,
      Q,080213,033950,1347.25,1347.5,10,8,,
      Q,080213,033958,1347.25,1347.5,10,9,,
      T,080213,034000,1347.25,1,
      Any thoughts please?

      Comment


      • #4
        -

        Hello Dave,

        The setComputeOnClose() function does not affect data series that are based on external intervals. It can be used, but it creates the logic problem that you've encountered. We may review the implementation of this function and how multiple time frame logic is affected, but it is a low priority item.

        For the time being, multiple time-frame studies should not use setComputeOnClose(). Use getBarState() and getBarStateInterval() to control execution at BARSTATE_NEWBAR.
        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


        • #5
          Hi Jason,
          Given the tick volume problems that eSignal describe in the article "Market Activity Alert", and of course us developers/users increasingly experience with sluggish and frozen charts due to increasing tick data, especially in any second, tick and volume charts, I would have thought eSignal would be doing all you can to support the use of ComputeOnClose()?

          To say that this is "low priority item" is very disheartening; I hope you will reconsider.

          Meanwhile, perhaps the ComputeOnClose documentation could be updated to make it clear that multiple interval NEWBAR synchronisation problems do exist so as to save other developers trying to "save time" in execution from actually wasting it in development?

          The setComputeOnClose() function does not affect data series that are based on external intervals
          Sorry, I can't fathom what this actually means, presumably I should infer that something does work other than the problem I describe, but I can't work out what it is, please could you enlighten me.

          Can you also say if there are other problems associated with using ComputeOnClose?


          Dave

          Comment


          • #6
            -

            Hello Dave,

            Please see my reply regarding setComputeOnClose() in this thread.
            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