Announcement

Collapse
No announcement yet.

create EFS to hold variables

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

  • create EFS to hold variables

    I am using a number of custom indicators that share a group of variables. I need to update these variables about once a month.
    I would like to try and streamline this process. Is it possible to create an EFS specifically to hold the variables from which all the other indicators read?

    That way I would only have to update the indicators once in one place.

    Thanks in advance

  • #2
    Re: create EFS to hold variables

    maninjapan
    While you can do that with an efs - using global values for example - a more practical [and easier] solution is to create a simple function in a Function Library file that just returns an array of all the values [strings, numbers, booleans, etc] that you want to store and then call that function through the addLibrary() function
    That said I think a more appropriate way to do it is to use a text file which you place in the FormulaOutput folder and then read using the EFS File Object.
    If you search the forum you should find various examples of all the above uses
    Alex


    Originally posted by maninjapan
    I am using a number of custom indicators that share a group of variables. I need to update these variables about once a month.
    I would like to try and streamline this process. Is it possible to create an EFS specifically to hold the variables from which all the other indicators read?

    That way I would only have to update the indicators once in one place.

    Thanks in advance

    Comment


    • #3
      I have attempted to work with an efsLib. I think I am quite close, however I am having the following issue with the efsLib posted at the bottom.

      I am using the efsLib only to hold variables to be used across multiple EFS's. It worked momentarily when testing with the first 3 functions, however when adding more functions relating to a second EFS, it started returning a syntax error
      ' failed to call 'ENERGY.BRN': function not defined. It only stopped working after adding extra functions to hold variables.
      Apart from that I didnt change anything.
      The library file is saved in the correct place. and as far as I can see the function is defined....

      Any suggestions?

      I pieced together the library file from examples on the forum, so not even sure I have written it correctly.

      PHP Code:
          var BRENT "BRN 2G-ICE";
          var 
      CL "CL G2";
          var 
      HO "HO G2";
          var 
      XRB "XRB G2",




          var 
      binit false;
          
          
      function 
      BRN() {
          if (
      binit== false){
          return 
      BRENT
          }
      }

      function 
      CRUDE() {
          if (
      binit== false){
          return 
      CL
          }
      }

      function 
      HEAT() {
          if (
      binit== false){
          return 
      HO
          }
      }

      function 
      GASOLINE() {
          if (
      binit== false){
          return 
      XRB
          }

      and here is an excerpt of the EFS calling the library

      PHP Code:

      var ENERGY addLibrary("ENERGY.efsLib");  
      function 
      preMain() {
        

          
      setPriceStudy(false);
          
      setStudyTitle("BRNdiff");
          
      setCursorLabelName("BRN"0);
          
      setCursorLabelName("TCM"1);
          
      setDefaultBarStyle(PS_SOLID0);
          
      setDefaultBarStyle(PS_SOLID1);
          
      setDefaultBarFgColor(Color.red0);
          
      setDefaultBarFgColor(Color.blue1);
          
      setDefaultBarThickness(20);
          
      setDefaultBarThickness(11);
          
      setPlotType(PLOTTYPE_LINE0);
          
      setPlotType(PLOTTYPE_LINE1);


      }


      var 
      bInit false;
      var 
      xClose null
      var 
      brn_sym ENERGY.BRN();
      var 
      yen_sym "6J H2";
      var 
      TCM_sym "TCL K2-TCM";
      var 
      TCM_sym_day "TCL K2-TCM=2";

      function 
      main() {
        
      if (
      getHour(0,sym(brn_sym)) == 15 && getMinute(0,sym(brn_sym)) == 30-getInterval(0,sym(brn_sym))) { // Is your 3.30pm-inv bar
      nCloseDay0=close(0,sym(brn_sym));


      Last edited by maninjapan; 12-20-2011, 05:57 AM.

      Comment


      • #4
        maninjapan
        The reason you are getting an error is that you have a comma instead of a semicolon in the following line of the function library
        var XRB = "XRB G2",
        and you are missing a closing curly bracket in the efs.
        Once you correct these your library and calling script will work.
        That said you do not need a bInit routine in each of those functions of the library. Just call the function one time only from the efs [as you are in effect already doing]
        Furthermore you could condense everything into one function that returns an array of all the symbols which you then call in your script as shown in the basic example enclosed below (note the example was created as a single script just to illustrate the concept and doing it in a function library would be no different other than having to call the library)
        Alex




        Originally posted by maninjapan
        I have attempted to work with an efsLib. I think I am quite close, however I am having the following issue with the efsLib posted at the bottom.

        I am using the efsLib only to hold variables to be used across multiple EFS's. It worked momentarily when testing with the first 3 functions, however when adding more functions relating to a second EFS, it started returning a syntax error
        ' failed to call 'ENERGY.BRN': function not defined. It only stopped working after adding extra functions to hold variables.
        Apart from that I didnt change anything.
        The library file is saved in the correct place. and as far as I can see the function is defined....

        Any suggestions?

        I pieced together the library file from examples on the forum, so not even sure I have written it correctly.

        PHP Code:
            var BRENT "BRN 2G-ICE";
            var 
        CL "CL G2";
            var 
        HO "HO G2";
            var 
        XRB "XRB G2",




            var 
        binit false;
            
            
        function 
        BRN() {
            if (
        binit== false){
            return 
        BRENT
            }
        }

        function 
        CRUDE() {
            if (
        binit== false){
            return 
        CL
            }
        }

        function 
        HEAT() {
            if (
        binit== false){
            return 
        HO
            }
        }

        function 
        GASOLINE() {
            if (
        binit== false){
            return 
        XRB
            }

        and here is an excerpt of the EFS calling the library

        PHP Code:

        var ENERGY addLibrary("ENERGY.efsLib");  
        function 
        preMain() {
          

            
        setPriceStudy(false);
            
        setStudyTitle("BRNdiff");
            
        setCursorLabelName("BRN"0);
            
        setCursorLabelName("TCM"1);
            
        setDefaultBarStyle(PS_SOLID0);
            
        setDefaultBarStyle(PS_SOLID1);
            
        setDefaultBarFgColor(Color.red0);
            
        setDefaultBarFgColor(Color.blue1);
            
        setDefaultBarThickness(20);
            
        setDefaultBarThickness(11);
            
        setPlotType(PLOTTYPE_LINE0);
            
        setPlotType(PLOTTYPE_LINE1);


        }


        var 
        bInit false;
        var 
        xClose null
        var 
        brn_sym ENERGY.BRN();
        var 
        yen_sym "6J H2";
        var 
        TCM_sym "TCL K2-TCM";
        var 
        TCM_sym_day "TCL K2-TCM=2";

        function 
        main() {
          
        if (
        getHour(0,sym(brn_sym)) == 15 && getMinute(0,sym(brn_sym)) == 30-getInterval(0,sym(brn_sym))) { // Is your 3.30pm-inv bar
        nCloseDay0=close(0,sym(brn_sym));


        Comment


        • #5
          that simple....... Thanks Alexis, works perfectly now and have been able to clean it up. I'm not sure how the file object would have worked out, but from what I looked at, this method seemed to be a lot easier to implement for a beginner like myself.


          Thanks Again!!

          Comment


          • #6
            maninjapan
            You are welcome
            Alex


            Originally posted by maninjapan
            that simple....... Thanks Alexis, works perfectly now and have been able to clean it up. I'm not sure how the file object would have worked out, but from what I looked at, this method seemed to be a lot easier to implement for a beginner like myself.


            Thanks Again!!

            Comment

            Working...
            X