Announcement

Collapse
No announcement yet.

I'm tyring to use variable for the sym()

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

  • I'm tyring to use variable for the sym()

    I'm trying to use a variable to put in for another symbol and time frame in a stochD study. The following works if I hard code it:

    vStoch10 = stochD(6, 3, 3, sym("IBM, 10"));

    but if I try to use a variable

    var sym_time = ""\sym(\"IBM,10\")\""

    which puts in the sym_time variable

    sym("IBM,10")

    so the following doesn't work

    vStoch10 = stochD(6, 3, 3, sym_time);

    with no error message. I've tried just to put in the "IBM,10"

    vStoch10 = stochD(6, 3, 3, sym(sym_time))

    again without any error message, it just gives bad data. Am I doing something wrong?

    Thanks,
    Mark

  • #2
    Mark
    Here is a basic example of how to make the symbol and interval a variable for use with the sym() function
    PHP Code:
    var xStochD null;
     
    function 
    main(){
     
        var 
    Sym_Int "IBM,10";
        
        if(
    xStochD==nullxStochD stochD(6,3,3,sym(Sym_Int));
        
        return 
    xStochD.getValue(0);

    If you then want to make the symbol and/or interval user defined variables that you can modify through Edit Studies then see the example enclosed below. You may also want to look at the formulas included in the EFS2 Custom folder as they will provide you with examples of how to do it using the FunctionParameter Object
    Alex

    PHP Code:
    var xStochD null;
     
    function 
    main(SymbolInterval){
     
        if(
    Symbol==nullSymbol getSymbol();//if no symbol is input use chart symbol
        
    else Symbol Symbol;//else use input symbol
        
    if(Interval==nullInterval getInterval();//same for interval
        
    else Interval Interval;
        var 
    Sym_Int Symbol+","+Interval;//combine symbol and interval as a string
        
        
    if(xStochD==nullxStochD stochD(6,3,3,sym(Sym_Int));
        
        return 
    xStochD.getValue(0);

    Comment

    Working...
    X