Announcement

Collapse
No announcement yet.

Multiple Interval Function

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

  • Multiple Interval Function

    Good Afternoon;

    The following script is my first attempt to develop a subroutine which is called several times to calculate moving averages on different time periods. When the subroutine is called for one value, it works fine. When I add a second time period it does not perform correctly. I would appreciate suggestions on how to correct the coding to get the subroutine to function correctly.

    Best Regards,

    Alan


    /************************************************** *******
    Function Testing
    ************************************************** ********/

    function preMain() {
    setPriceStudy(false);
    setStudyTitle("Function1");
    setCursorLabelName("MA1", 0);
    setDefaultBarStyle(PS_SOLID, 0);
    setDefaultBarFgColor(Color.blue, 0);
    setDefaultBarThickness(2, 0);
    setPlotType(PLOTTYPE_LINE, 0);

    Symbol1 = "YM U5";
    Interval1 = "20T";
    Interval2 = "1M";

    }

    function main() {

    Sym = Symbol1;
    Int = Interval1;
    MAQ1 = MTM(Sym, Int);

    Sym = Symbol1;
    Int = Interval2;
    MAQ2 = MTM(Sym, Int);

    MAQ3 =MAQ1 + MAQ2;

    return (MAQ1, MAQ2, MAQ3);

    }


    function MTM(Sym, Int) {

    var vSymbol1 = Symbol1+","+Interval1;
    xMA1 = offsetSeries(eval(sma)(3,eval(low)(sym(vSymbol1))) ,0);
    var MA1 = (xMA1.getValue(0));

    return (MA1);

    }
Working...
X