Announcement

Collapse
No announcement yet.

setComputeOnClose vs. NEWBAR

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

  • setComputeOnClose vs. NEWBAR

    Hi Jason, I hope you get this message.

    Can you please clarify a few (related) questions for me, because I am getting somewhat confused on this subject:

    Is there ANY difference between ComputeOnclose and "NEWBAR" condition?

    Does "NEWBAR" condition happen before or on the first tick of the new bar?

    I assume it is on the first tick and in this case, please clarify if:

    a/ close(0) will return the close of previous bar, or of the first tick of the new bar?
    b/ What will return close(-1)?
    c/ does this apply to any study?

    Thank you.
    Mihai
    Mihai Buta

  • #2
    Hello Mihai,

    Yes, there is a difference. setComputeOnClose() only allows the execution of the EFS when a bar closes. So one execution of the EFS per bar. The close event is triggered by the first tick of the new bar. At that point the EFS calculates and updates the return data on bar -1.

    BARSTATE_NEWBAR occurs on the first tick of the new bar.

    With setComputeOnClose();

    a) close(0) returns the close of bar -1. Try this code snippet below to see it in action.

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

        
    setCursorLabelName("close");
        
    setDefaultBarThickness(2);
    }

    function 
    main() {
        var 
    close(0);
        
        return 
    c;

    b) close(-1) returns the close from bar -2. Everything is offset by 1 bar when you use setComputeOnClose. Change the close(0) in the above code example to close(-1) and you'll see this.
    c) Yes.
    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
      Mihai,

      To answer your questions in the case of using BARSTATE_NEWBAR. These answers also assume you are not using setComputeOnClose in conjunction with NEWBAR.

      a) close(0) returns the close from bar 0. On the first tick of the new bar, the open, high, low and close are all the same price. So at the instance of BARSTATE_NEWBAR, close(0) is equal to open(0).
      b) close(-1) will return the close from bar -1.
      c) Yes.

      Now, just to clarify, using a conditional statement checking for BARSTATE_NEWBAR while using setComputeOnClose() isn't necessary since you will only have one execution of the EFS per bar. When using setComputeOnClose(), getBarState() returns BARSTATE_NEWBAR on every execution. There's no adverse affect to your study if you do use it in this case. It's just extra code. Try the code below. You'll see is operates in the same fashion as the previous example.

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

          
      setCursorLabelName("close");
          
      setDefaultBarThickness(2);
      }

      function 
      main() {
          if (
      getBarState() == BARSTATE_NEWBAR) {
              var 
      close(0);
              
              return 
      c;        
          }

      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


      • #4
        Hi Jason,

        I got the notification of your replies today (Monday, 1:50pm), thank you.

        I suspected there was something, because I was getting "glitches" for some indicators in real time, but they were correctly re-calculated if I reloaded the efs.

        Just to make sure I understand correctly: I need to re-write all the sections that execute on "NEWBAR" to use (-1) instead of (0). And I need to refer to (-2) if I want the values of one bar before last (excepting the one that it is being formed by NEWBAR).
        Note: I do NOT want to use ComputeOnClose, but I want some parts of the code to execute only once per bar.

        Thank you.
        Mihai
        Last edited by mbuta; 10-04-2004, 03:30 PM.
        Mihai Buta

        Comment


        • #5
          Hello Mihai,

          It sounds like you are on the right track with the -1 bar referencing at NEWBAR. It's difficult to say for sure what your specific solution would be without seeing your code. After you make the changes you'll know for sure. The problem your having is fairly common. The core issue is that some variables need to change on a tick-by-tick basis where others do not. If you continue to have problems, try to put together a stripped down code example that illustrates the problem and I'll help you find a more specific solution.
          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


          • #6
            Thank you for help and for your ofer Jason.
            I will try myself first.

            The problem manifests for "static" variables (that, like flip-flops are set/reset based on a set of conditions). Sometimes, on NEWBAR a state is set (prematurelly) and this is what I need to correct.

            I hate the prospect of having to go through the entire code again, though.

            Thanks,
            Mihai
            Mihai Buta

            Comment


            • #7
              Hi Jason.

              I need just one more clarification please:

              When "CurrentBarIndex" is not zero (historic data is processed during an efs load/re-load and there is only one tick/execution per bar anyway), on "NEWBAR" condition, are the close/open/studies (any GetValue) correct for this bar or still not?

              I think you understand why it is important: if on "NEWBAR" values are correct for this bar, we also need to include "CurrentBarIndex==0" as condition.

              In other words:

              If ("NEWBAR") {
              if ("CurrentBarIndex"==0) ref to (-1)
              else ref to (0)
              }

              Thanks,
              Mihai
              Mihai Buta

              Comment


              • #8
                Hello Mihai,

                You're understanding is correct. When processing the historical bars, the EFS gets executed only once and getBarState() returns NEWBAR for each bar. The historical bars are completed bars, so the getValue("Close") or close(0) returns the actual close for that bar.

                Your code snippet is one set of logic that would work when processing in real time to simulate a compute on close routine. I do something a little different, but it works in very much the same way.

                I set up two global variables called nClose and nClose1, for example. At NEWBAR, I set nClose1 to the value of nClose before I make the new call for nClose, which sets it equal the open of the new bar when processing in real time. This way, the logic stays consistent when processing the historical bars as well and you don't have to be concerned with the current bar index that is being processed. Let me know if this helps.

                PHP Code:
                function preMain() {
                    
                setPriceStudy(true);
                    
                setStudyTitle("Simulated Compute on Close");
                    
                setCursorLabelName("Bar -1 Close");
                }

                var 
                nClose null;
                var 
                nClose1 null;

                function 
                main() {
                    var 
                nState getBarState();
                    
                    if (
                nState == BARSTATE_NEWBAR) {
                        
                nClose1 nClose;
                        
                /* 
                            Perform simulated compute on 
                            close routines using nClose1 here.
                        */
                    
                }
                    
                    
                /* 
                        Store the last trade of the bar on a 
                        tick by tick basis for the next NEWBAR.
                    */
                    
                nClose close(0);
                    
                    return 
                nClose1;

                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


                • #9
                  Thank you Jason.

                  Your way is nice and cleaner than mine, but I have a little problem: I have about fourty studies runing, in three time frames (to avoid false signals on 2min chart when 5 and/or 15min do not confirm), plus their normalization (so I can do
                  If( (ADX+Stoch+MARSI+MACD+Osc)/5>.75) {Do that}
                  for example), so you can see the mess I get into if I store every tick.

                  Thank you for clarification.
                  Regards,
                  Mihai
                  Mihai Buta

                  Comment

                  Working...
                  X