Announcement

Collapse
No announcement yet.

Last Bar Computations

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

  • Last Bar Computations

    If I'm using setComputeOnClose(true), how do I force a final calculation for bar(0) after the last tick has arrived for the day -- regardless of the time interval selected?

    I was processing every tick, but that's a bit too much data to handle due to the frequency of the ticks.

    Thanks.

  • #2
    Hello AssetHound,

    With the use of setComputeOnClose() a formula will only execute once each time a bar closes. To force an execution of main() or another user-defined function within your formula can only be done manually. You could draw a button on the chart that executes the function when clicked. Concatenate to the text parameter of the drawTextRelative() function the following highlighted string.

    drawTextRelative( barIndex, yValue, text + "@URL=EFS:yourFunctionName", fgColor, bgColor, Flags, fontName, fontSize [, tagID] [, cx] [, cy] )
    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
      Hmmm. I was afraid you would say that. I'll give this a try later today, but it seems I would still have the problem with the bar(0) data since that last bar isn't "closed". Wouldn't this be the same as reloadEFS()? If so, I could just wait until the market closed and then reload which I could do in the program. Thanks.

      ---------

      Originally posted by JasonK
      Hello AssetHound,

      With the use of setComputeOnClose() a formula will only execute once each time a bar closes. To force an execution of main() or another user-defined function within your formula can only be done manually. You could draw a button on the chart that executes the function when clicked. Concatenate to the text parameter of the drawTextRelative() function the following highlighted string.

      drawTextRelative( barIndex, yValue, text + "@URL=EFS:yourFunctionName", fgColor, bgColor, Flags, fontName, fontSize [, tagID] [, cx] [, cy] )

      Comment


      • #4
        Hello AssetHound,

        There isn't a method to detect when the last bar closes in EFS while using setComputeOnClose(), which is why this last calculation update has to be done manually. When you see visually that the interval is over you can click the button and the calculation in your user-defined function can use the data from bar 0 even with setComputeOnClose(). Try the following example.

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

        var 
        bInit false;

        function 
        main() {
            if (
        getCurrentBarIndex() == -&& bInit == false) {
                
        drawTextRelative2020"test@URL=EFS:calc"Color.blueColor.grey
                    
        Text.BUTTON|Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT
                    
        null12"test" );
                
        bInit true;
            }
            return;
        }

        function 
        calc() {
            
        debugPrintln(getCurrentBarIndex() + "  " close(0));
            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


        • #5
          This was a great help. I was trying your suggestion, and just about had this done -- but this will save me a little time. Thanks.
          ---------

          Originally posted by JasonK
          Hello AssetHound,

          There isn't a method to detect when the last bar closes in EFS while using setComputeOnClose(), which is why this last calculation update has to be done manually. When you see visually that the interval is over you can click the button and the calculation in your user-defined function can use the data from bar 0 even with setComputeOnClose(). Try the following example.

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

          var 
          bInit false;

          function 
          main() {
              if (
          getCurrentBarIndex() == -&& bInit == false) {
                  
          drawTextRelative2020"test@URL=EFS:calc"Color.blueColor.grey
                      
          Text.BUTTON|Text.RELATIVETOBOTTOM|Text.RELATIVETOLEFT
                      
          null12"test" );
                  
          bInit true;
              }
              return;
          }

          function 
          calc() {
              
          debugPrintln(getCurrentBarIndex() + "  " close(0));
              return;

          Comment


          • #6
            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


            • #7
              Just to verify if you will, when using setComputeOnClose(), and it is decision time in the efs, would close(0) or close(-1) hold the value of the bar that just closed?

              I hope that makes sense.

              Thanks

              Comment


              • #8
                The Toad
                When using setComputeOnClose() it would be close(0)
                Alex

                Comment


                • #9
                  Well, now I'm confused. if setComputeOnClose() is being used, the current bar is still being formed and that bar is the (0) bar. The bar that just closed -- i.e., no more trades -- is bar (-1), I thought, since the bar (0) is still in process.

                  If you are not using setComputeOnClose(), that essentially means you are processing each trade and main will reevaluate the current bar (0) with each new trade.

                  --------------

                  Originally posted by Alexis C. Montenegro
                  The Toad
                  When using setComputeOnClose() it would be close(0)
                  Alex

                  Comment


                  • #10
                    AssetHound
                    I believe Jason provided an explanation of how it works in this post.
                    Anyhow this can be easily verified by running the enclosed script in real time (or playback) on an intraday chart. You should see that close(0) and open(0) refer to the last processed bar (ie at bar index -1)
                    Alex

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

                    function 
                    main(){
                        if(
                    close(0)>open(0)) setBarBgColor(Color.yellow);
                        return 
                    close(0);

                    Comment

                    Working...
                    X