Announcement

Collapse
No announcement yet.

Syntax error

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

  • Syntax error

    Trying to put a ma on LRS. Gives me a syntax error on line 68. Also, how do enter input variables for the ma ?

    Alexis C. Montenegro © June 2006
    Use and/or modify this code freely. If you redistribute it
    please include this and/or any other comment block and a
    description of any changes made.
    ************************************************** ********/

    // NOTE:
    // This efs requires amFunctions.efsLib in the FunctionLibrary folder.
    // If you do not have this file you can download it at the link below.
    // http://share.esignal.com/groupconten...ies&groupid=10

    var fpArray = new Array();

    function preMain(){

    setPriceStudy(false);
    setStudyTitle("Linear Regression Slope with MA");
    setCursorLabelName("LRS");
    setDefaultBarFgColor(Color.blue);
    setDefaultBarThickness(1);
    askForInput();

    var x=0;
    fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(1);
    setDefault(10);
    }
    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("Symbol", FunctionParameter.STRING);
    with(fpArray[x++]){
    setDefault();
    }
    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);
    }
    }



    function main() {
    var xLRS = efsInternal("calc");
    var movAvg = sma(5,getSeries(xLRS));
    return new Array (xLRS,movAvg);
    }

    var amLib = addLibrary("amFunctions.efsLib");
    var bInit = false;
    var xLRS = null;

    Function calc(Length,Source,Symbol,Interval,Params){

    if(bInit==false){
    if(Symbol == null) Symbol = getSymbol();
    if(Interval == null) Interval = getInterval();
    var vSymbol = Symbol+","+Interval;
    xLRS = amLib.amLinRegSlope(Length,eval(Source)(vSymbol));
    addBand(0,PS_SOLID,1,Color.black,"0");
    setShowTitleParameters(eval(Params));
    bInit=true;
    }

    return getSeries(xLRS);
    }Function calc

  • #2
    GM
    Because in the original LRS script which you are referencing xLRS is already a series you can pass it directly to one of the moving average functions without necessarily having to calculate it in a separate function.
    FWIW that is why I created the functions provided in the function libraries so that they would be available as a series just like the functions provided by eSignal
    Using the original script (the one you posted has too many errors to try and fix it) declare a new global variable (ie outside of preMain and main) calling it for example xMAofLRS and set it initially to null
    PHP Code:
    ...
    var 
    xMAofLRS null;//global variable

    function main(Length,...,...) 
    Then inside the existing bInit section add the sma() function using xLRS as the source as in the following code sample. At this stage the variable xLRS is a series so it can be used directly without the need to call it with the getSeries() function.
    PHP Code:
    if(bInit==false){
            if(
    Symbol == nullSymbol getSymbol();
            if(
    Interval == nullInterval getInterval();
            var 
    vSymbol Symbol+","+Interval;
            
    xLRS amLib.amLinRegSlope(Length,eval(Source)(vSymbol));
            
    xMAofLRS sma(5xLRS);//added sma function
            
    addBand(0,PS_SOLID,1,Color.black,"0");
            
    setShowTitleParameters(eval(Params));
            
    bInit=true;
        } 
    Once you have done that modify the return statement changing it to the following
    PHP Code:
    return new Array(getSeries(xLRS), getSeries(xMAofLRS)); 
    At this point you will need to add to preMain all the required statements to name the Cursor label, color the plot, etc.
    If you want to see some other completed examples of how to add a moving average to an existing series then look at the various MAofxxxx.efs that are available here and compare those to the original studies which are in your EFS2 Custom folder in Formulas.(for example compare MAofCCI.efs with customCCI.efs from wihich it is derived)
    All those scripts will also provide an example of input variables for the moving average functions. For information and syntax of the FunctionParameter object used to create those user defined input variables see this article in the EFS KnowledgeBase
    Alex

    Comment

    Working...
    X