Announcement

Collapse
No announcement yet.

FunctionParameter Class problem

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

  • FunctionParameter Class problem

    Good afternoon,
    I have the following issue when I try to plot a simple difference of moving average.
    In the preMain section I convert 3 parameters into numbers using the FunctionParameter Class.
    Then I pass those paramethers to 2 ema and 1 coeficient.
    But somehow the paramethers for the ema are not detected as NUMBERS. Could you help me to solve this issue?

    This is the code:

    function preMain() {
    setStudyTitle(Diferencia);
    setCursorLabelName(Diferencia);
    setStudyMax(120);
    setStudyMin(-120);
    addBand(0, PS_DOT, 1.5, Color.white,0);
    setDefaultBarThickness(2,0);
    var fp1 = new FunctionParameter("amp", FunctionParameter.NUMBER);
    fp1.setDefault(1);
    var fp2 = new FunctionParameter("medSup", FunctionParameter.NUMBER);
    fp2.setDefault(60);
    var fp3 = new FunctionParameter("medInf", FunctionParameter.NUMBER);
    fp3.setDefault(30);
    }

    function main(amp,medInf,medSup) {
    var shortAverage = ema(medInf);
    var longAverage = ema(medSup);
    var diferencia = amp*(shortAverage-longAverage);
    return diferencia;
    }

    This is the error message:

    My Formulas\Diferencia.efs, line 37: Error: Failed to call 'ema': parameter # 1 is invalid.
    My Formulas\Diferencia.efs, line 23: ReferenceError: Diferencia is not defined

    Apparently ema() function does not recognice medInf as a NUMBER but I do not know why, I have declare them in the pre main section like specified in the doc. Extrange issue

    Thanks for your help

  • #2
    Ojos86
    You have errors in the arguments of the setStudyTitle() and setCursorlabelName() statements which should be strings ie "Diferencia" and not Diferencia
    Once you resolve that the script will work fine
    FWIW you can accomplish the same result by using the macd() function with the lengths set to 30, 60, 1 respectively or use the Price Oscillator function I posted here and set the parameters to 30, 60, 1
    Alex


    Originally posted by Ojos86 View Post
    Good afternoon,
    I have the following issue when I try to plot a simple difference of moving average.
    In the preMain section I convert 3 parameters into numbers using the FunctionParameter Class.
    Then I pass those paramethers to 2 ema and 1 coeficient.
    But somehow the paramethers for the ema are not detected as NUMBERS. Could you help me to solve this issue?

    This is the code:

    function preMain() {
    setStudyTitle(Diferencia);
    setCursorLabelName(Diferencia);
    setStudyMax(120);
    setStudyMin(-120);
    addBand(0, PS_DOT, 1.5, Color.white,0);
    setDefaultBarThickness(2,0);
    var fp1 = new FunctionParameter("amp", FunctionParameter.NUMBER);
    fp1.setDefault(1);
    var fp2 = new FunctionParameter("medSup", FunctionParameter.NUMBER);
    fp2.setDefault(60);
    var fp3 = new FunctionParameter("medInf", FunctionParameter.NUMBER);
    fp3.setDefault(30);
    }

    function main(amp,medInf,medSup) {
    var shortAverage = ema(medInf);
    var longAverage = ema(medSup);
    var diferencia = amp*(shortAverage-longAverage);
    return diferencia;
    }

    This is the error message:

    My Formulas\Diferencia.efs, line 37: Error: Failed to call 'ema': parameter # 1 is invalid.
    My Formulas\Diferencia.efs, line 23: ReferenceError: Diferencia is not defined

    Apparently ema() function does not recognice medInf as a NUMBER but I do not know why, I have declare them in the pre main section like specified in the doc. Extrange issue

    Thanks for your help

    Comment


    • #3
      Thank you :-), everything works OK now

      Comment


      • #4
        Ojos86
        You are welcome
        Alex


        Originally posted by Ojos86 View Post
        Thank you :-), everything works OK now

        Comment

        Working...
        X