Announcement

Collapse
No announcement yet.

efsInternal

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

  • efsInternal

    Hi All,
    I try to make the following script to run but...
    What I want to do is to (include) efsInternal but bring the Internal call and not the main? ANy Ideas?
    This Is the code.
    .............

    /************************************************** *******
    By Alexis C. Montenegro for eSignal © December 2004
    Use and/or modify this code freely. If you redistribute it
    please include this and/or any other comment blocks and a
    description of any changes you make.
    ************************************************** ********/
    var fpArray = new Array();
    function preMain() {

    setPriceStudy(false);
    setStudyTitle("----------");

    setCursorLabelName("percentK", 0);
    setCursorLabelName("percentD", 1);
    setCursorLabelName("Osc",2);
    setDefaultBarFgColor(Color.grey, 0);
    setDefaultBarFgColor(Color.yellow, 1);
    setDefaultBarFgColor(Color.blue,2);
    setPlotType(PLOTTYPE_HISTOGRAM,2);
    setDefaultBarThickness(2,0);
    setDefaultBarThickness(2,1);
    setDefaultBarThickness(2,2);
    askForInput();
    }
    addBand(80, PS_SOLID, 3, Color.grey, "Upper");
    addBand(20, PS_SOLID, 3, Color.black, "Lower");


    var MAVt = null;
    var MAVt1 = null;
    var MAVt_1 = 0;
    var MAVt1_1 = 0;
    var x=0;

    fpArray[x] = new FunctionParameter("Short", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(1);
    setDefault(10);
    }
    fpArray[x] = new FunctionParameter("Long", FunctionParameter.NUMBER);
    with(fpArray[x++]){
    setLowerLimit(1);
    setDefault(21);
    }
    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("Type", FunctionParameter.BOOLEAN);
    with(fpArray[x++]){
    setName("Exponential");
    setDefault(false);
    }
    fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
    with(fpArray[x++]){
    setName("Show Parameters");
    setDefault(false);
    }


    var bInit = false;
    var xOsc = null;

    function main(Short,Long,Source,Symbol,Interval,Type,Params ) {
    var HP = efsInternal("range");
    if(bInit == false){
    if(Symbol == null) Symbol = getSymbol();
    if(Interval == null) Interval = getInterval();
    var vSymbol = Symbol+","+Interval;
    xOsc = osc(Short,Long,eval(Type),eval(Source)(sym(vSymbol )));
    setShowTitleParameters(eval(Params));
    bInit = true;
    }

    return getSeries(xOsc),range();



    function range(nLength, nSmoothing, nSmoothings) {



    if(nLength == null)
    nLength = 8;
    if(nSmoothing == null)
    nSmoothing = 3;
    if(nSmoothings == null)
    nSmoothings = 3;

    var percentK;
    var ll = 0, hh = 0;
    var sum = 0;
    var vHigh = getValue("High", 0, -nLength);
    var vLow = getValue("Low", 0, -nLength);
    var temp = 0;

    if(vHigh == null || vLow == null)
    return;


    for(j = 0; j < nLength; j++) {
    if(j == 0) {
    ll = vLow[j];
    hh = vHigh[j];
    } else {
    hh = Math.max(hh, vHigh[j]);
    ll = Math.min(ll, vLow[j]);
    }
    }
    percentK = ((close() - ll) / (hh - ll)) * 100;
    if (isNaN(percentK) == false) MAVt = MAVt_1 + (percentK - MAVt_1) / nSmoothing;
    if (getBarState() == BARSTATE_NEWBAR) MAVt_1 = MAVt;
    if (isNaN(percentK) == false) MAVt1 = MAVt1_1 + (MAVt - MAVt1_1) / nSmoothings;
    if (getBarState() == BARSTATE_NEWBAR) MAVt1_1 = MAVt1;

    return new Array(MAVt,MAVt1);

    }
    }

  • #2
    elmi
    There are several errors in the script you posted.
    1. The FunctionParameters should be inside the preMain function.
    2. When calling a function that expects some parameters such as is the case with function range(nLength, nSmoothing, nSmoothings) you need to pass those parameters through the efsInternal() call. So your efsInternal() call to function range should be
    PHP Code:
    var HP efsInternal("range",8,3,3
    Note that I have added the parameters used as defaults in that function but you may want to pass different parameters. If you then need to make these parameters user definable you will need to add the appropriate FunctionParameters in preMain and pass those through the efsInternal() call.
    3. Your return statement is set to return one item only. Should be return new Array (item1, item2, etc)
    4. The return statement contains a call to range() which is unnecessary as the function is already being called through efsInternal()
    If you need to return both elements that are returned by that function you will need to use the getSeries() function to retrieve each individual element ie
    PHP Code:
    return new Array(getSeries(xOsc), getSeries(HP,0), getSeries(HP,1
    5. Check all the {} brackets as you have some that are in the incorrect places.
    Before you proceed with any of these changes I would suggest that you thoroughly read this thread which explains in detail (with examples) the efsInternal() and efsExternal() functions. You may also want to read about those functions and the required syntax in the EFS KnowledgeBase
    Alex

    Comment

    Working...
    X