Announcement

Collapse
No announcement yet.

Stumped as to when EFS runs

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

  • Stumped as to when EFS runs

    I am stumped as to how to understand when my EFS runs . I am trying to build a trading system that runs live at the end of every bar but does not generate signals while the EFS is loading . What I have done is this :

    - I set the preferences for all EFS to run at the close of a bar .

    - In my code I check for signals when getBarState == BARSTATE_CURRENTBAR

    I then expect my signal code to run at the end of every bar . Well nothing happens . I remove the BarState check and things run but I get the unwanted side effect of getting stale signals firing .
    I changed the check to BARSTATE_NEWBAR and things start to work but I thought NEWBAR was only used at the beginning of a bar and not at the end of the bar where I want my code to run .

    Have I mis-understood the use of getBarState .... .

    I want to remove the preference to have all EFS run at close of bar as I have a tick counter that displays on my chart . What is the most robust method to have a single EFS only run at bar close without this preference checked ?

    On a side note I recall at one time seeing a tick counter for the bar in the Cursor window . I coul duse that if it is available but I don't recall how to set it up .

    Thanks for your help and reading my ramblings

  • #2
    Hi,

    Check out this very recent thread, and see if it helps:

    getCurrentBarIndex

    Garth
    Garth

    Comment


    • #3
      Oh...btw...checking for BARSTATE_CURRENTBAR will only tell you that you don't have a NEWBAR and that you aren't having ALLBARS being loaded (ie: first load, or a reload of the script).

      So for almost every tick, you will get a barstate of BARSTATECURRENTBAR
      Garth

      Comment


      • #4
        Billmini,
        Without knowing the details, I think you could use BARSTATE_NEWBAR, but simply do all your calculations on bars up to and including the prior bar. You would use the fact that the prior bar has an index value of -1.

        Bob

        Comment


        • #5
          Garth , that furthers my understanding and gives me another tool but I am still unable to get my code executue when I want it :

          Here is a test EFS I have .
          var price = 0;
          var state = 0;

          function preMain()
          {
          //setComputeOnClose(true);
          setPriceStudy(true);
          setStudyTitle("Test - Trade");
          setCursorLabelName("Test - Trade");
          }

          function main() {

          price = close(-1);
          state = getBarState();

          if ((state==BARSTATE_NEWBAR) && (getCurrentBarIndex ==0))
          {debugPrintln("BARSTATE_NEWBAR" + price);} // BARSTATE_NEWBAR
          return;
          }

          I have unchecked the properties that ask EFS to run at close of bar . I have loaded this single EFS on a 25 Tick chart and watch as nothing comes out of the Formula Output Window . Still a bit stumped why I can't see this simple piece of code work at least once per new bar.

          Comment


          • #6
            Change getCurrentBarIndex to getCurrentBarIndex().
            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
              Jason beat me to it...but in addition if you have it so that all EFS only calculate at close of bar you don't need:

              state==BARSTATE_NEWBAR

              However, if you plan on changing that global setting to allow tick by tick execution, then the NEWBAR check is needed.


              Garth
              Garth

              Comment


              • #8
                Thanks for your timely help folks . My program is now over that hurdle .

                Regards Bill

                Comment

                Working...
                X