Announcement

Collapse
No announcement yet.

Passing Parameters to Builtin Studies

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Passing Parameters to Builtin Studies

    The examples I have seen so far create builtin study objects outside of main(). This seems reasonable since creating an object on every tick (or bar with setComputeOnClose) would likely impose a heavy processor load.

    However, the only method I have seen to pass user-configurable parameters to efs code, such as specifying the length of a moving average, is through arguments to main(). But if a study object is created before main(), it appears you cannot set its parameters that way.

    Is there another way of passing parameters to a formula, or is there a method to alter a study object's parameters after it's created? Or is there any other way to code using builtin studies that allows the user to affect its paramters?

  • #2
    Hello Book,

    You can pass input parameters to a built-in study and allow the object to only be created once by checking for a bar state of BARSTATE_ALLBARS. Download PassInputsToStudy.efs to see an example using MAStudy.
    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
      Good idea. The following seems to work. Note you need to declare the variable globally, outside of main, but you can create the object inside BARSTATE_ALLBARS:

      function premain() { ... }
      var study;
      function main(MAlen) {
      if (MAlength == null) MAlen = 10;
      if(getBarState() == BARSTATE_ALLBARS) {
      study = new MAStudy(MAlen, 0, "Close", MAStudy.SIMPLE);
      }
      ...
      }

      [I wish they would let us tabify code.]

      Thanks,
      Book

      Comment


      • #4
        Hi Book,

        I agree. It would be nice if we could use tab when writing replies to posts. It's a problem with HTML syntax. In a web page, tab is used to move from object to object. Anyway, to get around this, I write the code in Notepad or the EFS editor in eSignal and then just copy it into the text box when posting replies. You can also surround the code with [php ] [/php ] and it will colorize it. Note: you'll have to take out the space before the end brackets for it to work. Try it out on your next post.

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

        function 
        main() {
            
        // code;

        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
          FYI - I'd recommend it be done this way. Checking to see if the study is null rather than ALLBARS

          PHP Code:
          function premain() { ... }

          var 
          study null;

          function 
          main(MAlen) {
              if (
          MAlength == nullMAlen 10;

              if(
          study == null)
                  
          study = new MAStudy(MAlen0"Close"MAStudy.SIMPLE);

              ...

          Matt Gundersen

          Comment

          Working...
          X