Announcement

Collapse
No announcement yet.

Adding Moving Averages to Formula Study

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

  • Adding Moving Averages to Formula Study

    Hi,

    I am trying to add some moving averages to the B% formula from the Bollinger Study package, but for some reason I am getting an error message on the second use of 'MAStudy' in the following code:

    My Formulas\Percent B Custom.efs, line 41: Error: Failed to call 'MAStudy': parameter # 5 is invalid.

    Strangely enough the first use of 'MAStudy' with almost the same paramter set works perfectly fine:

    var vSMA10_of_vBollinger20_1 = new MAStudy(10, 0, vBollinger20, BollingerStudy.UPPER, MAStudy.SIMPLE);

    Only on the second use I get the error message:
    var vSMA10_of_vBollinger20_2 = new MAStudy(10, 0, vBollinger20, BollingerStudy.LOWER, MAStudy.SIMPLE);

    Here is the complete efs code:
    function preMain() {
    setPriceStudy(false);
    setStudyTitle("MA of B%");
    setCursorLabelName("vB%", 0);
    setCursorLabelName("vGD10", 1);
    setCursorLabelName("vEMA8", 2);
    setDefaultBarFgColor(Color.RGB(0xFE,0x00,0x6D), 0);
    setDefaultBarFgColor(Color.RGB(0x00,0x94,0xFF), 1);
    setDefaultBarFgColor(Color.RGB(0xFE,0x69,0x00), 2);
    setDefaultBarStyle(PS_SOLID, 0);
    setDefaultBarStyle(PS_SOLID, 1);
    setDefaultBarStyle(PS_SOLID, 2);
    setDefaultBarThickness(1,0);
    setDefaultBarThickness(1,1);
    setDefaultBarThickness(1,2);
    setPlotType(PLOTTYPE_LINE,0);
    setPlotType(PLOTTYPE_LINE,1);
    setPlotType(PLOTTYPE_LINE,2);
    }

    var vBollinger20 = new BollingerStudy(20, "Close", 20);
    var vSMA10 = new MAStudy(10, 0, "Close", MAStudy.SIMPLE);
    var vEMA8 = new MAStudy(8, 0, "Close", MAStudy.EXPONENTIAL);
    var vSMA10_of_vBollinger20_1 = new MAStudy(10, 0, vBollinger20, BollingerStudy.UPPER, MAStudy.SIMPLE);
    var vSMA10_of_vBollinger20_2 = new MAStudy(10, 0, vBollinger20, BollingerStudy.LOWER, MAStudy.SIMPLE);
    var vEMA8_of_vBollinger20_1 = new MAStudy(8, 0, vBollinger20, BollingerStudy.UPPER, MAStudy.EXPONENTIAL);
    var vEMA8_of_vBollinger20_2 = new MAStudy(8, 0, vBollinger20, BollingerStudy.LOWER, MAStudy.EXPONENTIAL);
    var vLastAlert = -1;


    function main() {
    var vUpper = vBollinger20.getValue(BollingerStudy.UPPER);
    var vLower = vBollinger20.getValue(BollingerStudy.LOWER);
    var vLast = close();
    var vSMA_Upper = vSMA10_of_vBollinger20_1.getValue(MAStudy.MA);
    var vSMA_Lower = vSMA10_of_vBollinger20_2.getValue(MAStudy.MA);
    var vSMA = vSMA10.getValue(MAStudy.MA);
    var vEMA_Upper = vEMA8_of_vBollinger20_1.getValue(MAStudy.MA);
    var vEMA_Lower = vEMA8_of_vBollinger20_2.getValue(MAStudy.MA);
    var vEMA = vEMA8.getValue(MAStudy.MA);

    if(vUpper == null || vLower == null || vLast == null || vSMA_Upper == null || vSMA_Lower == null || vSMA == null || vEMA_Upper == null || vEMA_Lower == null || vEMA == null)
    return;

    return new Array( (vLast - vLower) / (vUpper - vLower), (vSMA - vSMA_Lower) / (vSMA_Upper - vSMA_Lower), (vEMA - vEMA_Lower) / (vEMA_Upper - vEMA_Lower) );
    }

    This doesn't seem to be overly complicated and I am an absolute beginner with programming efs, so maybe I am overlooking something really simple? I would appreciate any help.

    panta-rhei

  • #2
    I just realized that the code works perfectly well with eSignal 10.6. Is there a bug in eSignal 11.3 that this code does not work there, or has something in the efs syntax changed?

    panta-rhei

    Comment


    • #3
      panta-rhei
      The efs syntax has not changed with regards to this. It looks like it is just a bug in 11.3 with the BASIS and LOWER members of the legacy BollingerStudy() function.
      The workaround [and actually a better way to write the formula IMHO] is to use the efs2 functions rather than the legacy functions [see Bollinger Bands and Moving Averages in the EFS KnowledgeBase
      Enclosed below is your code revised for use with the equivalent efs2 functions
      Alex

      PHP Code:
      function preMain() {
          
      setPriceStudy(false);
          
      setStudyTitle("MA of B%");
          
      setCursorLabelName("vB%"0);
          
      setCursorLabelName("vGD10"1);
          
      setCursorLabelName("vEMA8"2);
          
      setDefaultBarFgColor(Color.RGB(0xFE,0x00,0x6D), 0);
          
      setDefaultBarFgColor(Color.RGB(0x00,0x94,0xFF), 1); 
          
      setDefaultBarFgColor(Color.RGB(0xFE,0x69,0x00), 2);
          
      setDefaultBarStyle(PS_SOLID0);
          
      setDefaultBarStyle(PS_SOLID1);
          
      setDefaultBarStyle(PS_SOLID2);
          
      setDefaultBarThickness(1,0);
          
      setDefaultBarThickness(1,1);
          
      setDefaultBarThickness(1,2);
          
      setPlotType(PLOTTYPE_LINE,0); 
          
      setPlotType(PLOTTYPE_LINE,1);
          
      setPlotType(PLOTTYPE_LINE,2);
      }

      var 
      vBollinger20_U upperBB(20,20);
      var 
      vBollinger20_L lowerBB(20,20);
      var 
      vSMA10 sma(10);
      var 
      vEMA8 ema(8);
      var 
      vSMA10_of_vBollinger20_1 sma(10,vBollinger20_U);
      var 
      vSMA10_of_vBollinger20_2 sma(10,vBollinger20_L);
      var 
      vEMA8_of_vBollinger20_1 ema(8,vBollinger20_U);
      var 
      vEMA8_of_vBollinger20_2 ema(8,vBollinger20_L);
      var 
      vLastAlert = -1;

      function 
      main() {
          var 
      vUpper vBollinger20_U.getValue(0);
          var 
      vLower vBollinger20_L.getValue(0);
          var 
      vLast close(0);
          var 
      vSMA_Upper vSMA10_of_vBollinger20_1.getValue(0);
          var 
      vSMA_Lower vSMA10_of_vBollinger20_2.getValue(0);
          var 
      vSMA vSMA10.getValue(0);
          var 
      vEMA_Upper vEMA8_of_vBollinger20_1.getValue(0);
          var 
      vEMA_Lower vEMA8_of_vBollinger20_2.getValue(0);
          var 
      vEMA vEMA8.getValue(0);

          if(
      vUpper == null || vLower == null || vLast == null || vSMA_Upper == null || vSMA_Lower == null || vSMA == null || vEMA_Upper == null || vEMA_Lower == null || vEMA == null)
          return;

          return new Array( (
      vLast vLower) / (vUpper vLower), (vSMA vSMA_Lower) / (vSMA_Upper vSMA_Lower), (vEMA vEMA_Lower) / (vEMA_Upper vEMA_Lower) );


      Originally posted by panta-rhei
      I just realized that the code works perfectly well with eSignal 10.6. Is there a bug in eSignal 11.3 that this code does not work there, or has something in the efs syntax changed?

      panta-rhei

      Comment


      • #4
        Hi Alexis,

        great stuff, that code works well and looks a lot simpler too

        I didn't know the legacy studies had been updated and it was possible to use these efs2 functions

        Is there a reference somewhere that lists all the updates that were done between efs and efs2?

        At least I can calm myself that it was not my stupidity why the legacy code did not work and I have learned something new.

        Thanks for your help!

        panta-rhei

        Comment


        • #5
          panta-rhei
          FYI most of the efs2 functions [and specifically all the efs2 functions for the built-in studies] were introduced in 2005 with version 7.9 (build# 719).
          You can find the list of the functions introduced at that time - and subsequently - in the EFS Glossary of the EFS KnowledgeBase by referencing the build# column [note that the functions without a build# were introduced through various versions prior to 7.9]
          Also review the Built-in Study Functions folder of the EFS KnowledgeBase which includes all the efs2 built-in studies. Other efs2 functions are included in the Series Functions folder of the EFS KnowledgeBase.
          Lastly you may want to search the forums as there are literally hundreds of threads posted over the years that are related to most [if not all] the efs2 functions
          Alex


          Originally posted by panta-rhei
          Hi Alexis,

          great stuff, that code works well and looks a lot simpler too

          I didn't know the legacy studies had been updated and it was possible to use these efs2 functions

          Is there a reference somewhere that lists all the updates that were done between efs and efs2?

          At least I can calm myself that it was not my stupidity why the legacy code did not work and I have learned something new.

          Thanks for your help!

          panta-rhei

          Comment


          • #6
            Hi Alex,

            ok, I've found your references and will review them.

            Thanks again for those useful hints!

            panta-rhei

            Comment

            Working...
            X