Announcement

Collapse
No announcement yet.

formula locking up

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

  • formula locking up

    I sem to be having a problem with my series variables. This script is causing the program to freeze up.

    PHP Code:
    var fpArray = new Array();
    function 
    preMain() {

        
    setPriceStudy(false);
        
    setStudyTitle("MACD of 2ROC");
        
        
    setCursorLabelName("diff"0);
        
    setDefaultBarFgColor(Color.black0);
        
    setPlotType(PLOTTYPE_LINE,0);
        
    setDefaultBarThickness(2,0);  

        
    setCursorLabelName("dAvg"1);
        
    setDefaultBarFgColor(Color.magenta1);
        
    setPlotType(PLOTTYPE_LINE,1);
        
    setDefaultBarThickness(1,1);
        
        
    setCursorLabelName("MA-s"2);
        
    setDefaultBarFgColor(Color.blue2);
        
    setPlotType(PLOTTYPE_LINE,2);
        
    setDefaultBarThickness(1,2);
        
        
    setCursorLabelName("MA-f"3);
        
    setDefaultBarFgColor(Color.red3);
        
    setPlotType(PLOTTYPE_LINE,3);
        
    setDefaultBarThickness(1,3);
        

        var 
    x=0;
        
    fpArray[x] = new FunctionParameter("sLen"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("Slow ROC Length");
            
    setLowerLimit(1);        
            
    setDefault(28);
        }
        
    fpArray[x] = new FunctionParameter("fLen"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("Fast ROC Length");
            
    setLowerLimit(1);        
            
    setDefault(14);
        }
        
    fpArray[x] = new FunctionParameter("maLen"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("MA Length");
            
    setLowerLimit(1);        
            
    setDefault(8);
        }

        
    fpArray[x] = new FunctionParameter("Source"FunctionParameter.STRING);
        
    with(fpArray[x++]){
            
    addOption("open"); 
            
    addOption("high");
            
    addOption("low");
            
    addOption("close");
            
    addOption("hl2");
            
    addOption("hlc3");
            
    addOption("ohlc4"); 
            
    setDefault("close"); 
        }
        
    fpArray[x] = new FunctionParameter("Interval"FunctionParameter.STRING);
        
    with(fpArray[x++]){
            
    setDefault();
        }
        
    fpArray[x] = new FunctionParameter("Params"FunctionParameter.BOOLEAN);
        
    with(fpArray[x++]){
            
    setName("Show Parameters");
            
    setDefault(false);
        }
    }

    var 
    bInit false;
    var 
    sROCfROCxMAsxMAfxDiff;

    function 
    main(sLen,fLen,maLen,Source,Interval,Params) {

        if(
    bInit == false){
            var 
    Symbol getSymbol();
            if(
    Interval == nullInterval getInterval();
            var 
    vSymbol Symbol+","+Interval;
            
    sROC roc(sLen,eval(Source)(sym(vSymbol)));
            
    fROC roc(fLen,eval(Source)(sym(vSymbol)));        
            
    xMAs sma(maLen,sROC);
            
    xMAf sma(maLen,fROC);
            
    addBand(0,PS_SOLID,1,Color.grey,"Centerline");   
            
    setShowTitleParameters(eval(Params));      
            
    bInit true;
        }
        var 
    xMAs.getValue(0);
        var 
    xMAf.getValue(0);
        
    xDiff efsInternal(CalcDiffs); 
        
    dAvg ema(10,xDiff);
        

        return new Array (
    getSeries(xDiff), getSeries(dAvg), getSeries(xMAs), getSeries(xMAf) );
    }

    function 
    CalcDiff(s1f1){
        
    d1 = (s1 f1);
    return(
    d1);


  • #2
    Hi pj909,

    Try this. I really don't know why but I assume that creating the series outside of bInit keeps recreating the series object and thus slows down the system tremendously.

    This efs works fine on my end with the revisions I made.

    PHP Code:
    //http://forum.esignal.com/showthread.php?threadid=34031
    var fpArray = new Array();
    function 
    preMain() {

        
    setPriceStudy(false);
        
    setStudyTitle("MACD of 2ROC");
        
        
    setCursorLabelName("diff"0);
        
    setDefaultBarFgColor(Color.black0);
        
    setPlotType(PLOTTYPE_LINE,0);
        
    setDefaultBarThickness(2,0);  

        
    setCursorLabelName("dAvg"1);
        
    setDefaultBarFgColor(Color.magenta1);
        
    setPlotType(PLOTTYPE_LINE,1);
        
    setDefaultBarThickness(1,1);
        
        
    setCursorLabelName("MA-s"2);
        
    setDefaultBarFgColor(Color.blue2);
        
    setPlotType(PLOTTYPE_LINE,2);
        
    setDefaultBarThickness(1,2);
        
        
    setCursorLabelName("MA-f"3);
        
    setDefaultBarFgColor(Color.red3);
        
    setPlotType(PLOTTYPE_LINE,3);
        
    setDefaultBarThickness(1,3);
        

        var 
    x=0;
        
    fpArray[x] = new FunctionParameter("sLen"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("Slow ROC Length");
            
    setLowerLimit(1);        
            
    setDefault(28);
        }
        
    fpArray[x] = new FunctionParameter("fLen"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("Fast ROC Length");
            
    setLowerLimit(1);        
            
    setDefault(14);
        }
        
    fpArray[x] = new FunctionParameter("maLen"FunctionParameter.NUMBER);
        
    with(fpArray[x++]){
            
    setName("MA Length");
            
    setLowerLimit(1);        
            
    setDefault(8);
        }

        
    fpArray[x] = new FunctionParameter("Source"FunctionParameter.STRING);
        
    with(fpArray[x++]){
            
    addOption("open"); 
            
    addOption("high");
            
    addOption("low");
            
    addOption("close");
            
    addOption("hl2");
            
    addOption("hlc3");
            
    addOption("ohlc4"); 
            
    setDefault("close"); 
        }
        
    fpArray[x] = new FunctionParameter("Interval"FunctionParameter.STRING);
        
    with(fpArray[x++]){
            
    setDefault();
        }
        
    fpArray[x] = new FunctionParameter("Params"FunctionParameter.BOOLEAN);
        
    with(fpArray[x++]){
            
    setName("Show Parameters");
            
    setDefault(false);
        }
    }

    var 
    bInit false;
    var 
    xMAsxMAfxDiffdAvg;//added dAvg

    function main(sLen,fLen,maLen,Source,Interval,Params) {

        if(
    bInit == false){
            var 
    Symbol getSymbol(),sROCfROC;
            if(
    Interval == nullInterval getInterval();
            var 
    vSymbol Symbol+","+Interval;
            
    sROC getSeries(roc(sLen,eval(Source)(sym(vSymbol))));
            
    fROC getSeries(roc(fLen,eval(Source)(sym(vSymbol))));        
            
    xMAs getSeries(sma(maLen,sROC));
            
    xMAf getSeries(sma(maLen,fROC));
            
    xDiff getSeries(efsInternal("CalcDiff"xMAsxMAf ));//CalcDiff must be enclosed in parens 
            
    dAvg getSeries(ema(10,xDiff));
            
    addBand(0,PS_SOLID,1,Color.grey,"Centerline");   
            
    setShowTitleParameters(eval(Params));      
            
    bInit true;
        }

        return new Array (
    xDiffdAvgxMAsxMAf );
    }

    function 
    CalcDiff(s1f1){
        
    d1 = (s1 f1);
        return(
    d1);

    Wayne
    Last edited by waynecd; 07-28-2010, 11:36 PM.

    Comment

    Working...
    X