Announcement

Collapse
No announcement yet.

Strange EFS Behavior

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

  • Strange EFS Behavior

    I have an EFS that would only go through its logic if (var nState!=BARSTATE_ALLBARS) ... in another words, it should not do any processing when it is being loaded but only when a new tick comes in. I set computeonclose to false in preMain. But, it goes through the logic anyway when it gets loaded. Really confused. Please help. Thanks.

  • #2
    Hello z11,

    For a complete explanation of Bar State, please review the following thread, getBarState(). Let me know if you have any more questions.
    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
      Hi Jason, I read your thread and that is exactly how I understood it ...but somehow my problem remains as stated in my original post. Any ideas?

      Comment


      • #4
        Hi Jason, more info on my problem...I loaded the same EFS in 4 different charts and only one of them shows that problem...and I repeated the process a number of times and it appears this problem happens randomly to different charts at different reload or remove/load operations. Please give me some idea as to why this is happening ...Thanks.

        Comment


        • #5
          Hello z11,

          In your first message you say your using if (var nState!=BARSTATE_ALLBARS). This will only prevent the code from executing at ALLBARS, which only occurs once at the oldest bar in the chart when the formula first initializes. If you post a code example that you're having trouble with, I'd be happy to take a look.

          Also, the setComputeOnClose() function does not have any parameters. Passing a boolean parameter to the function has no effect. If setComputeOnClose(false) is in preMain, it has the same effect as setComputeOnClose().
          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
            Hi Jason. the skeleton of my code is:
            main () {
            var nState = getBarState();
            if (nState!=BARSTATE_ALLBARS) {

            ...do things...

            }
            }

            My objective is when the EFS loads it should not do anything. Only when new ticks coming it will then start to "do things"..
            Thanks.

            Comment


            • #7
              Hello z11,

              Your code snippet only prevents the EFS from executing at ALLBARS. While the formula is loading it processes once for each bar. The bar state at those instances is BARSTATE_NEWBAR, which is why your code gets executed during the loading process. Here's a better way to handle your situation.

              var nIndex = getCurrentBarIndex();
              if (nIndex < 0) return;

              Add this to the top of main. This will do what you're trying to accomplish.
              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


              • #8
                Hi Jason,

                I tried your suggestion by doing :
                van nIndex=...
                if (nIndex <0) return;
                else {
                ...do things...
                }

                And now the EFS does not do anything!

                Confused....

                Comment


                • #9
                  Hello z11,

                  Do you have setComputeOnClose() in preMain? If so, then change the 0 to -1.

                  if (nIndex < -1) 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


                  • #10
                    Thanks ...that worked! for my education ...would you explain why that made the difference with computeonclose set to false in preMain? Thanks again.

                    Comment


                    • #11
                      Hello z11,

                      Sure. As I mentioned previously, setComputeOnClose() does not have any parameters. Passing false to the function has no effect. If the function exists in preMain(), your formula will only be executing on the close. If you want to turn your formula back to tick-by-tick processing you have to comment out the function or remove it from preMain().
                      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


                      • #12
                        Thank you Jason.
                        Just to be sure, if I DO NOT have the computeonclose in preMain but leave the condition of (nIndex <-1) in main() alone, that would not hurt anything would it?

                        Comment


                        • #13
                          Hello z11,

                          No, it won't hurt anything. But it will allow the formula to process once on bar -1 during the load.
                          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