Announcement

Collapse
No announcement yet.

Problems with calling ZeroLag Tema studies

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

  • Problems with calling ZeroLag Tema studies

    As far as I can see any of Sylvain Vervoort’s studies that include zerolag tema, e.g. Zerolag Tema, HA Zerolag Tema and Zerolag HA Tema Difference can be called using efsExternal() but only in the interval of the calling chart. For example, from a 1000V Volume chart the first code snippet shown below works but the second generates the error message ”ZeroLag_TEMA.efs, line 62: Parameter Number 2 of Function ema is invalid.” Below is also the code for ZeroLag_TEMA.efs. Line 62 is in sub-function calcTema and reads xAvg1 = ema(nLength,xSource); My question is how can the returned values of these studies be called in intervals other than that of the calling chart. Thanks for any help.

    Mike

    Snippet #1):

    function preMain() {
    setPriceStudy(false);
    setStudyTitle("title1");
    addBand(0, PS_SOLID, 2, Color.RGB(0,0,0), "TagName");
    }
    var bInit1 = null;
    var test1 = null;
    var Study1 = null;

    function main(){
    if(bInit1 == false){
    Study1 = efsExternal("ZeroLag_TEMA.efs");
    Test1 = getSeries(Study1, 0);
    bInit1 = true
    }

    return test1;
    }
    *********************

    Snippet #2):

    function preMain() {
    setPriceStudy(false);
    setStudyTitle("title2");
    addBand(0, PS_SOLID, 2, Color.RGB(0,0,0), "TagName");
    }
    var bInit2 = null;
    var test2 = null;
    var Study2 = null;

    function main(){

    if(bInit2 == false){
    Study2 = efsExternal("ZeroLag_TEMA.efs", inv(“2000V”));
    Test2 = getSeries(Study2, 0);
    bInit2 = true
    }

    return test2;
    }
    *********************

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("Zero Lag TEMA ");
    setCursorLabelName("ZTEMA", 0);
    setDefaultBarFgColor(Color.red, 0);
    setDefaultBarThickness(2, 0);

    var fp1 = new FunctionParameter("nPeriods", FunctionParameter.NUMBER);
    fp1.setName("Periods");
    fp1.setLowerLimit(1);
    fp1.setDefault(55);
    var fp2 = new FunctionParameter("sSource", FunctionParameter.STRING);
    fp2.setName("Price Source");
    fp2.addOption("Close");
    fp2.addOption("HL/2");
    fp2.addOption("HLC/3");
    fp2.addOption("OHLC/4");
    fp2.setDefault("HLC/3");
    }

    var bInit = false;
    var xTema1 = null;
    var xTema2 = null;
    var xSource = null;

    function main(nPeriods, sSource) {

    if (bInit == false) {
    if (sSource == "Close") {
    xSource = close();
    } else if (sSource == "HL/2") {
    xSource = hl2();
    } else if (sSource == "HLC/3") {
    xSource = hlc3();
    } else if (sSource == "OHLC/4") {
    xSource = ohlc4();
    }
    xTema1 = efsInternal("calcTEMA", nPeriods, xSource);
    xTema2 = efsInternal("calcTEMA", nPeriods, xTema1);
    bInit = true;
    }

    var nZEma = null;
    var nTema1 = xTema1.getValue(0);
    var nTema2 = xTema2.getValue(0);
    if (nTema1 == null || nTema2 == null) return;

    nZTEma = nTema1 + (nTema1 - nTema2);

    return nZTEma;
    }


    var xAvg1 = null;
    var xAvg2 = null;
    var xAvg3 = null;
    var bInit2 = false;

    function calcTEMA(nLength,xSource){

    if(bInit2 == false){
    xAvg1 = ema(nLength,xSource);
    xAvg2 = ema(nLength,xAvg1);
    xAvg3 = ema(nLength,xAvg2);
    bInit2 = true;
    }

    var nAvg1 = xAvg1.getValue(0);
    var nAvg2 = xAvg2.getValue(0);
    var nAvg3 = xAvg3.getValue(0);
    if (nAvg1 == null || nAvg2 == null || nAvg3 == null) return;

    var nTEMA = (3*nAvg1)-(3*nAvg2)+nAvg3;

    return nTEMA;
    }

  • #2
    Re: Problems with calling ZeroLag Tema studies

    Mike
    The first problem which is in both calling scripts is caused by the mixed use of upper and lower cases in the naming of some variables. For example in the first example you declare a variable as test1 but then initialize it as Test1. JavaScript is case sensitive.
    Also in both scripts you declare the variables bInit? assigning null to them but then evaluate if they are false which they are not hence the other variables never get initialized
    As to why calling the ZeroLag_TEMA does not work in your second example in which you pass an interval the reason is explained in the Notes in this article of the EFS KnowledgeBase on the efsExternal() function ie
    "If function parameters are being passed, all parameters must be passed that the formula is expecting"
    In your efsExternal() call add the necessary parameters that the called formula is expecting and it will work
    Alex


    Originally posted by mikejhelms
    As far as I can see any of Sylvain Vervoort’s studies that include zerolag tema, e.g. Zerolag Tema, HA Zerolag Tema and Zerolag HA Tema Difference can be called using efsExternal() but only in the interval of the calling chart. For example, from a 1000V Volume chart the first code snippet shown below works but the second generates the error message ”ZeroLag_TEMA.efs, line 62: Parameter Number 2 of Function ema is invalid.” Below is also the code for ZeroLag_TEMA.efs. Line 62 is in sub-function calcTema and reads xAvg1 = ema(nLength,xSource); My question is how can the returned values of these studies be called in intervals other than that of the calling chart. Thanks for any help.

    Mike

    Snippet #1):

    function preMain() {
    setPriceStudy(false);
    setStudyTitle("title1");
    addBand(0, PS_SOLID, 2, Color.RGB(0,0,0), "TagName");
    }
    var bInit1 = null;
    var test1 = null;
    var Study1 = null;

    function main(){
    if(bInit1 == false){
    Study1 = efsExternal("ZeroLag_TEMA.efs");
    Test1 = getSeries(Study1, 0);
    bInit1 = true
    }

    return test1;
    }
    *********************

    Snippet #2):

    function preMain() {
    setPriceStudy(false);
    setStudyTitle("title2");
    addBand(0, PS_SOLID, 2, Color.RGB(0,0,0), "TagName");
    }
    var bInit2 = null;
    var test2 = null;
    var Study2 = null;

    function main(){

    if(bInit2 == false){
    Study2 = efsExternal("ZeroLag_TEMA.efs", inv(“2000V”));
    Test2 = getSeries(Study2, 0);
    bInit2 = true
    }

    return test2;
    }
    *********************

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("Zero Lag TEMA ");
    setCursorLabelName("ZTEMA", 0);
    setDefaultBarFgColor(Color.red, 0);
    setDefaultBarThickness(2, 0);

    var fp1 = new FunctionParameter("nPeriods", FunctionParameter.NUMBER);
    fp1.setName("Periods");
    fp1.setLowerLimit(1);
    fp1.setDefault(55);
    var fp2 = new FunctionParameter("sSource", FunctionParameter.STRING);
    fp2.setName("Price Source");
    fp2.addOption("Close");
    fp2.addOption("HL/2");
    fp2.addOption("HLC/3");
    fp2.addOption("OHLC/4");
    fp2.setDefault("HLC/3");
    }

    var bInit = false;
    var xTema1 = null;
    var xTema2 = null;
    var xSource = null;

    function main(nPeriods, sSource) {

    if (bInit == false) {
    if (sSource == "Close") {
    xSource = close();
    } else if (sSource == "HL/2") {
    xSource = hl2();
    } else if (sSource == "HLC/3") {
    xSource = hlc3();
    } else if (sSource == "OHLC/4") {
    xSource = ohlc4();
    }
    xTema1 = efsInternal("calcTEMA", nPeriods, xSource);
    xTema2 = efsInternal("calcTEMA", nPeriods, xTema1);
    bInit = true;
    }

    var nZEma = null;
    var nTema1 = xTema1.getValue(0);
    var nTema2 = xTema2.getValue(0);
    if (nTema1 == null || nTema2 == null) return;

    nZTEma = nTema1 + (nTema1 - nTema2);

    return nZTEma;
    }


    var xAvg1 = null;
    var xAvg2 = null;
    var xAvg3 = null;
    var bInit2 = false;

    function calcTEMA(nLength,xSource){

    if(bInit2 == false){
    xAvg1 = ema(nLength,xSource);
    xAvg2 = ema(nLength,xAvg1);
    xAvg3 = ema(nLength,xAvg2);
    bInit2 = true;
    }

    var nAvg1 = xAvg1.getValue(0);
    var nAvg2 = xAvg2.getValue(0);
    var nAvg3 = xAvg3.getValue(0);
    if (nAvg1 == null || nAvg2 == null || nAvg3 == null) return;

    var nTEMA = (3*nAvg1)-(3*nAvg2)+nAvg3;

    return nTEMA;
    }

    Comment


    • #3
      Thanks

      Wow, I must have been tired when I wrote that post. The actual program doesn’t have the case sensitive variable problems or the missed defined null you pointed out but you’re right that including all the parameters was the answer. I find that a little strange though because in the past if I did not include parameters in an efsExternal() calling statement then the default parameters in the called studies were used. But hey, it works so no complaints here. Once again I am amazed at the quality and quantity of your work on this board. Thanks.

      Mike

      Comment


      • #4
        Re: Thanks

        Mike
        Thank you for the kind words and you are most welcome.

        I find that a little strange though because in the past if I did not include parameters in an efsExternal() calling statement then the default parameters in the called studies were used.
        That still holds true and in fact your first example [ie the one without any parameters at all] would work in as much as the called efs would use its internal parameters.
        It is only when you pass one parameter and the called efs also requires more that you will get the error because it no longer uses its internal parameters but relies on those being passed in the efsExternal() call.
        As an aside this is also true for efsInternal()
        Alex


        Originally posted by mikejhelms
        Wow, I must have been tired when I wrote that post. The actual program doesn’t have the case sensitive variable problems or the missed defined null you pointed out but you’re right that including all the parameters was the answer. I find that a little strange though because in the past if I did not include parameters in an efsExternal() calling statement then the default parameters in the called studies were used. But hey, it works so no complaints here. Once again I am amazed at the quality and quantity of your work on this board. Thanks.

        Mike

        Comment

        Working...
        X