Announcement

Collapse
No announcement yet.

Problem with variation on "rafter.efs"

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

  • Problem with variation on "rafter.efs"

    I'm trying to set price (Open, High, Low or Close) as a user input so the user can apply William Rafter's moving trend to those values rather than just the close (as in the original formula by TSSupport).

    I've substituted "Nval" for close in the original formula, but it doesn't seem to work. If I try to change the value to, say, high in the edit studies dialog, the study just disappears from the chart. If I clear the nval field in the edit studies dialog, the study reappears. The code I'm using is below. I've a horrible feeling I'm just doing something dumb.....




    function preMain()
    {
    setStudyTitle("MLR");
    setCursorLabelName("MLR", 0);
    setDefaultBarFgColor(Color.green, 1);
    setPriceStudy(true);

    }

    function main(n, nval) {

    if(nval== null) {nval= close;}

    if(n == null)
    n = 20;

    var sum = 0;
    var i = 0;
    var mt = 0;

    for(i = n; i > 0; i--)
    sum += (i - (n + 1) / 3) * nval(i - n);
    wt = 6 / (n * (n + 1)) * sum
    return wt;
    }

  • #2
    Re: Reply to post 'Problem with variation on "rafter.efs"'

    All you should have to do is substitute open, high, or low for close in the
    efs.
    ----- Original Message -----
    From: <[email protected]>
    To: <[email protected]>
    Sent: Sunday, January 26, 2003 5:59 AM
    Subject: Reply to post 'Problem with variation on "rafter.efs"'


    > Hello rhbishop,
    >
    > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    >

    Comment


    • #3
      Hi rh

      Thanks for the reply - sorry I didn't make myself clear. I realise I could do that, but I wanted to set it up so I didn't have to edit the efs file each time I wanted to change the value. Ideally I want to be able to switch it in the "edit formulas" dialog.

      Comment


      • #4
        Here you go Andy. This works. Evidently when you pass strings the editor doesn't recognize them as reserved global constants.
        When you edit the study and type in low for example you should make sure its lower case.

        function preMain()
        {
        setStudyTitle("MLR");
        setCursorLabelName("MLR", 0);
        setDefaultBarFgColor(Color.green, 1);
        setPriceStudy(true);

        }

        function main(n,nval) {

        if(nval== null) {nval= close;}
        if(nval=="open") {nval=open;}
        if(nval=="high") {nval=high;}
        if(nval=="low") {nval=low;}
        if(n == null)
        n = 20;

        var sum = 0;
        var i = 0;
        var mt = 0;

        for(i = n; i > 0; i--)
        sum += (i - (n + 1) / 3) * nval(i - n);
        wt = 6 / (n * (n + 1)) * sum
        return wt;
        }

        Comment


        • #5
          Brilliant! Many thanks rh.

          Comment

          Working...
          X