Announcement

Collapse
No announcement yet.

Bar Replay inconsistent: barstate changes and bars not seen with ComputeOnClose()

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

  • Bar Replay inconsistent: barstate changes and bars not seen with ComputeOnClose()

    I've been trying to use Bar (not tick) replay to debug EFS scripts (intraday, 15min charts).
    But I find yet more complications:

    1) With ComputeOnClose() set I don't get any "current" bars. That is, I see historic bars (last one is -1), but then when I click "Play" or "Step forward", I see the new bars on the charts, but main() is not called. Why??

    2) With ComputeOnClose() not set I do get "current" bars. BUT the getBarState() changes from historic to current bars.
    That is, I see historic bars (last one is 0) with state == NEWBAR, but then when I click "Play" or "Step forward", I see state == CURRENTBAR. Why??


    All these inconsistencies are time-wasting obstacles to just getting on with writing code.

    See code to test this follows

    PHP Code:
    function preMain() {

        
    //setComputeOnClose();
        
    debugPrint("preMain"" isComputeOnClose() = "+ (isComputeOnClose() == true"true":"false"));
    }
    // for n is 0 to 60 usually, ie time / date in hh mm ss etc
    function TwoOrMoreDigits(n) {var n.toString(); if (s.length == 1"0"+s; return s;}

    // naf, for bar index
    function ThreeOrMoreDigits(n) {var TwoOrMoreDigits(n); if (s.length == 2"0"+s; return s;}
    function 
    WallClockString() {
        var 
    dDate = new Date();  // we only need this when we get to current bars ? Ideally use one from start of _main(){}
        
    return TwoOrMoreDigits(dDate.getMonth())+"/"+TwoOrMoreDigits(dDate.getDate())+"-"
    +TwoOrMoreDigits(dDate.getHours())+":"+TwoOrMoreDigits(dDate.getMinutes())+":"+TwoOrMoreDigits(dDate.getSeconds());
    }
    function 
    sBarState(n) {
        if (
    == BARSTATE_NEWBAR)     return "NEWBAR ";
        if (
    == BARSTATE_CURRENTBAR) return "TICK   ";
        if (
    == BARSTATE_ALLBARS)    return "ALLBARS";
        return 
    "?????";
    }
    function 
    main()  {

    var 
    iBar getCurrentBarIndex();
    var 
    sIndex iBar == 0"   0":"-"+ThreeOrMoreDigits(-iBar);
    debugPrint(" Bar: "+sIndex +" State: "+sBarState(getBarState())
            + 
    ", isComputeOnClose() = "+ (isComputeOnClose() == true"true":"false")
            + 
    ", isReplayMode() = "+ (isReplayMode() == true"true":"false")
            + 
    ", WallClock() = " WallClockString()
            +
    "\n");
            
            return 
    null;

    Last edited by Dave180; 06-16-2007, 05:30 AM.

  • #2
    -

    Hello Dave,

    When using setComputeOnClose(), the formula is forced to process only at BARSTATE_NEWBAR, which is the signal that the prior bar has closed. At this instance the formula processes bar -1 and displays results. Bar index 0 will not have any data displayed until the formula sees BARSTATE_NEWBAR for the next bar when it arrives. As far as I can tell main() is being called for each bar with or without setComputeOnClose(). Here's the code I tested with. You should see an "x" above each bar and a corresponding debugPrintln in the output window. If setComputeOnClose() is active you will not see the print or the "x" for the current bar 0.

    PHP Code:
    function preMain() {
        
    setPriceStudy(true);
        
    setStudyTitle("Test");
        
    setShowCursorLabel(false);
        
    setComputeOnClose();
    }


    function 
    main()  {    
        
        if (
    getBarState() == BARSTATE_NEWBAR) {
            
    debugPrintln("bar " hour(0) +":"minute(0) +":"second(0));
            
    drawText("x"AboveBar2Color.blueText.CENTER);
        }
        
        return;


    Regarding the BARSTATE_CURRENTBAR occurrences during Bar Replay mode, I am seeing this behaviour. This can occur if the symbol you are using in bar replay mode is currently in session. The real time trades that are taking place are still triggering an execution of the formula. I see this as a bug and will report this to development. In the mean time, the work around is to add a condition to exit main() when isReplayMode() is true and getBarState() is equal to _CURRENTBAR at the top of main().

    PHP Code:
    function main()  {    
        if (
    isReplayMode() && getBarState() == BARSTATE_CURRENTBAR) return;
     ... 
    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
      Jason, hi

      Sorry, my use of "current" was not in terms of the bar closing and 0 vs -1, but the difference between those drawn to fill the chart when the replay is loaded (I called "historic") and those added when the replay buttons are pressed to move a new ("current") bar onto the chart, I simply don't get the main() calls, at all, as explained, it's not a closed bar / one bar deficit!

      This is the unexplained second oddity I have with Bar replay. I wonder if I have a problem with my installation.
      The other issue is that the chart does not properly repaint, only the most current four bars get repainted, the rest of the chart stays static (so the fourth bar disappears when a new bar is added). If the bar happens to exceed the high or low of the chart and it gets rescaled then the redrawn chart does show the bars correctly.

      When you describe the bug of getting "CURRENTBAR" during replay with live markets, what I mean is that I get CURRENTBAR every time I click to move forward (and no NEWBARs), but for the bars that got loaded to "fill" the chart I got "NEWBAR". So although you seem to have found a bug, it's not the problem that I encountered. Did you run your (or better my) script without ComputeOnClose() and see any NEWBARs when you clicked the play / step buttons?

      I am assuming that with a bar replay there can only be NEWBARs as there is no tick data, so ComputeOnClose should be irrelevent?


      Enjoy the weekend.

      Dave

      Comment


      • #4
        -

        Hello Dave,

        I'm not able to reproduce the scenario where main() does not get called. I've tested both code examples here and main() is being executed in replay mode as well as forwarding one bar at a time. It's possible that it is a installation problem. If you are running multiple instances of eSignal, try your code again while only running one instance of the application.

        The issue with the chart not repainting while in replay mode was a known issue that should be fixed in the next version. It was related to the time template settings where the # Days/Bars option is set to Bars. Check your time template and change it to load a # of Days or dynamic mode.

        Regarding the CURRENTBAR states, I'm only seeing these occur because of real time trades that are occurring. Clicking on the forward button is not generating a BARSTATE_CURRENTBAR as far as I can see. I tested this with both code examples with and without setComputeOnClose(). Again, this may be related to the same problem you're experiencing with main() not being called. Check this one again while running only one instance of eSignal as well.

        And yes, using setComputeOnClose() in bar replay mode is irrelevant. However, it can help avoid the extra executions of main() due to the CURRENTBAR bug that was discovered as it forces the formula to ignore the CURRENTBAR state.
        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
          Jason, brief reply for now...

          Thanks for investigating, much appreciated.

          Yes I do run multiple copies sometimes, I'll check again.

          I described the repaint problem to your phone tech support and they didn't know anything about it, hence my attempt to link it to other problems, maybe you could circulate the information to them.

          More to follow when I've done more checking.

          Dave

          Comment

          Working...
          X