Announcement

Collapse
No announcement yet.

Nothing displayed for my .efs formula

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

  • Nothing displayed for my .efs formula

    Hi,

    I am very new to programming. The only experience I had was using the formula wizard in the older version of esignal.

    The formula wizard is not suitable for the script that I need so I decided to manually code an efs for the first time.

    Everything seems to be ok & there are no syntax errors reported.

    The problem is when I insert it into the chart, nothing is displayed at all. I do not know where I went wrong.

    Any guidance would be greatly appreciated.

    The script is as follows...

    ---------------------------------------------------

    function preMain() {

    setPriceStudy(false);
    setStudyTitle("ProxyTest");
    setCursorLabelName("ProxyTest",0);
    setDefaultBarFgColor(Color.RGB(0x00,0x94,0xFF), 0);
    setPlotType(PLOTTYPE_LINE,0);
    setDefaultBarThickness(2,0);
    }

    function main() {


    var nMA_OpenClose = sma (8, open - close)

    var nMA_HighLow = sma (8, high - low)


    var nProxy = (((nMA_OpenClose / nMA_HighLow) *50) +50)


    return nProxy;

    }

    ---------------------------------------------------

    Thanks,

    kbw

  • #2
    Re: Nothing displayed for my .efs formula

    kbw
    The reason the script is not working is that neither open – close nor high – low are a series hence you cannot use them as the source of the sma() function you are assigning to the variables nMA_OpenClose and nMA_HighLow
    To create a series [of each] you need to calculate your equations of the open – close and high – low [which by the way should be open(0) – close(0) and high(0) – low(0)] in a separate function or external efs which you then call using the efsInternal() or efsExternal() functions. These series created by the efsInternal() or efsExternal() functions can then be used as the source for the built-in studies. For the description of the efsInternal() and efsExternal() functions and the required syntax see the links above which will take you to the corresponding articles in the EFS KnowledgeBase.
    You can find additional examples in this thread on the efsInternal() and efsExternal() functions [which BTW includes a specific example of how to calculate a moving average of the High-Low] and in this thread that shows how you can create studies on studies using these functions
    FWIW you could also write this study without the need of separate functions to create the series [hence even using the Formula Wizard] because the average of (a – b) is the same as the (average of a – average of b) therefore you could just create the four averages and then use them in your equation that computes the variable nProxy
    Alex


    Originally posted by kbw
    Hi,

    I am very new to programming. The only experience I had was using the formula wizard in the older version of esignal.

    The formula wizard is not suitable for the script that I need so I decided to manually code an efs for the first time.

    Everything seems to be ok & there are no syntax errors reported.

    The problem is when I insert it into the chart, nothing is displayed at all. I do not know where I went wrong.

    Any guidance would be greatly appreciated.

    The script is as follows...

    ---------------------------------------------------

    function preMain() {

    setPriceStudy(false);
    setStudyTitle("ProxyTest");
    setCursorLabelName("ProxyTest",0);
    setDefaultBarFgColor(Color.RGB(0x00,0x94,0xFF), 0);
    setPlotType(PLOTTYPE_LINE,0);
    setDefaultBarThickness(2,0);
    }

    function main() {


    var nMA_OpenClose = sma (8, open - close)

    var nMA_HighLow = sma (8, high - low)


    var nProxy = (((nMA_OpenClose / nMA_HighLow) *50) +50)


    return nProxy;

    }

    ---------------------------------------------------

    Thanks,

    kbw

    Comment


    • #3
      Hi Alexis,

      Thanks for pointing me in the right direction.

      I removed the "efsInternal", i.e. efsInternal(Indexation()) because the formula did not display anything & it reported an error.

      I managed to get it to display data on the chart but I now have other problems.

      It did not create a moving average of an index that I had hoped for. It should have fluctuated between 0 & 100 but instead, it seems to be displaying similar data to the price of the market itself. I tried adding limits to the preMain() so that it limits data to 0-100 but then the formula does not work at all so I removed that code.

      My new script looks like this...


      ----------------------------------------------------------------------------------------------------------------


      function preMain() {

      setPriceStudy(false);
      setStudyTitle("ProxyTest");
      setCursorLabelName("ProxyTest",0);
      setDefaultBarFgColor(Color.RGB(0x00,0x94,0xFF), 0);
      setPlotType(PLOTTYPE_LINE,0);
      setDefaultBarThickness(2,0);
      }

      function main() {


      var nProxy = sma (13, Indexation())


      return nProxy;

      }


      function CloseOpen() {

      var nCloseOpen = (close(0) - open(0));

      return nCloseOpen;

      }


      function HighLow() {

      var nHighLow = (high(0) - low(0));

      return nHighLow;

      }


      function Ratio() {

      var nRatio = (CloseOpen() / HighLow())

      return nRatio;

      }


      function Indexation() {

      var nIndexation = (Ratio() *50 +50)

      return nIndexation;

      }

      ----------------------------------------------------------------------------------------------------------------

      I would also like to be able to change the period for the sma without opening the script editor. If there is a quick line of code I need to add, it would be great to know what it is please.


      Thanks,

      Kern

      Comment


      • #4
        kbw
        As I explained to you in my previous post if you want to use a custom variable as the source of one of the built-in study functions this needs to be a series and to create a series you need to calculate your custom variable in a separate function or efs and call it using either the efsInternal() or efsExternal() calls
        The call to the Indexation function does not return a series hence the sma() function will not return the results you are expecting
        The reason it returned an error when you called it using efsInternal(Indexation()) is because the syntax you used was incorrect. I would suggest you review the examples in the linked articles and threads I provided in my previous post
        Having said that I think you are making this unnecessarily complicated. As I indicated in my previous reply you can calculate your equation very simply [given that average(a-b) is the same as average(a)-average(b)] by calculating the moving averages of the individual Open, High, Low, Close values and using those in your equation
        In its simplest form your formula can be condensed to the following



        With regards to being able to change the parameters you can do that using the FunctionParameter Object. See the linked article for the description and syntax. For more examples of its use see any of the studies in the Formulas->Built-in Studies Formulas->Custom Formulas folder [or Formulas->EFS2 Custom folder in 10.6]
        Alex


        Originally posted by kbw
        Hi Alexis,

        Thanks for pointing me in the right direction.

        I removed the "efsInternal", i.e. efsInternal(Indexation()) because the formula did not display anything & it reported an error.

        I managed to get it to display data on the chart but I now have other problems.

        It did not create a moving average of an index that I had hoped for. It should have fluctuated between 0 & 100 but instead, it seems to be displaying similar data to the price of the market itself. I tried adding limits to the preMain() so that it limits data to 0-100 but then the formula does not work at all so I removed that code.

        My new script looks like this...


        ----------------------------------------------------------------------------------------------------------------


        function preMain() {

        setPriceStudy(false);
        setStudyTitle("ProxyTest");
        setCursorLabelName("ProxyTest",0);
        setDefaultBarFgColor(Color.RGB(0x00,0x94,0xFF), 0);
        setPlotType(PLOTTYPE_LINE,0);
        setDefaultBarThickness(2,0);
        }

        function main() {


        var nProxy = sma (13, Indexation())


        return nProxy;

        }


        function CloseOpen() {

        var nCloseOpen = (close(0) - open(0));

        return nCloseOpen;

        }


        function HighLow() {

        var nHighLow = (high(0) - low(0));

        return nHighLow;

        }


        function Ratio() {

        var nRatio = (CloseOpen() / HighLow())

        return nRatio;

        }


        function Indexation() {

        var nIndexation = (Ratio() *50 +50)

        return nIndexation;

        }

        ----------------------------------------------------------------------------------------------------------------

        I would also like to be able to change the period for the sma without opening the script editor. If there is a quick line of code I need to add, it would be great to know what it is please.


        Thanks,

        Kern

        Comment


        • #5
          Alexis,

          You are correct as it appears that I did make it unnecessarily complicated after looking at the simple one line code that you illustrated in the diagram.

          Things should be more straight forward for me from now on so thanks for all your help.


          Kind regards,

          Kern

          Comment

          Working...
          X