Announcement

Collapse
No announcement yet.

hhv() and llv() for price difference

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

  • hhv() and llv() for price difference

    Please HELP!

    By some reason I cannot use hhv() and llv() functions for difference between stock prices.

    I have tried different combinations, but it is always takes set of values from current open price of stock and not the difference between specified stock prices.


    function main() {

    var h_yyy=hhv(30,(close(sym("MSFT,60"))-close(sym("INTC,60"))));
    var l_yyy=llv(30,(close(sym("MSFT,60"))-close(sym("INTC,60"))));

    var vUpper = hhv(30,fc());
    var vLower = llv(30,h_yyy);

    return new Array (fc(),h_yyy,l_yyy, vUpper );
    }

    function fc(){
    var f1 = (close(sym("MSFT,60"))-close(sym("INTC,60")))*6;
    return f1;
    }


    Thank you in advance for your help.

  • #2
    librovich
    Following are some line by line comments on the script you posted.
    PHP Code:
    var h_yyy=hhv(30,(close(sym("MSFT,60"))-close(sym("INTC,60"))));
    var 
    l_yyy=llv(30,(close(sym("MSFT,60"))-close(sym("INTC,60")))); 
    The syntax in these two lines of code is invalid. When you apply some math to a series the result is not a series but a value. So the result of the following expression
    (close(sym("MSFT,60"))-close(sym("INTC,60")))
    which is used as the source for the hhv() function is a value and not a series as required by the function.
    In order to create the series you need to calculate the expression in a separate function or efs and then call that function or efs using the efsInternal() or efsExternal() functions (see the links for the description and syntax). These will create a series which you can then use as the source for the hhv() function. The correct syuntax in this case is
    var h_yyy = hhv(30,efsInternal("fc"));
    var l_yyy = llv(30, efsInternal("fc"));

    This would be simplified in the following way
    var myVar = efsInternal("fc");
    var h_yyy = hhv(30,myVar);
    var l_yyy = llv(30, myVar);


    PHP Code:
    var vUpper hhv(30,fc()); 
    Also in this case the syntax is invalid. As explained in the prior comment the hhv() function requires the source to be a series. To do this you need to call the function fc() using the efsInternal() function which will create the series. The correct syntax in this case is
    var vUpper = hhv(30,efsInternal("fc"));

    PHP Code:
    var vLower llv(30,h_yyy); 
    In this case the syntax would be valid if the variable h_yyy were a series. While you can call a function as you did by usding fc() this will return a value and not a series. In order to accomplish what you want this needs to be written as follows
    var h_yyy = efsInternal("fc");
    var vLower = llv(30, h_yyy);


    In light of all the above comments here is how your script would need to be written in its most basic form
    PHP Code:
    function main() {
      
        var 
    myVar efsInternal("fc");//calls the function and creates the series
        
    var h_yyy=hhv(30,myVar);//now uses the series as source parameter
        
    var l_yyy=llv(30,myVar);//as above

        
    return new Array (myVar,h_yyy,l_yyy);
    }

    function 
    fc(){  
        var 
    f1 = (close(sym("MSFT,60"))-close(sym("INTC,60")))*6;
        return 
    f1

    Hope this helps
    Alex


    Originally posted by librovich
    Please HELP!

    By some reason I cannot use hhv() and llv() functions for difference between stock prices.

    I have tried different combinations, but it is always takes set of values from current open price of stock and not the difference between specified stock prices.


    function main() {

    var h_yyy=hhv(30,(close(sym("MSFT,60"))-close(sym("INTC,60"))));
    var l_yyy=llv(30,(close(sym("MSFT,60"))-close(sym("INTC,60"))));

    var vUpper = hhv(30,fc());
    var vLower = llv(30,h_yyy);

    return new Array (fc(),h_yyy,l_yyy, vUpper );
    }

    function fc(){
    var f1 = (close(sym("MSFT,60"))-close(sym("INTC,60")))*6;
    return f1;
    }


    Thank you in advance for your help.

    Comment


    • #3
      Thank you Alex!!! Now everything works!

      Thank you Alex!!! Now everything works!

      Comment


      • #4
        librovich
        You are most welcome and thank you for letting me know it now works
        Alex

        Comment

        Working...
        X