Announcement

Collapse
No announcement yet.

fix efs script...

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

  • fix efs script...

    can some help to fix below efs?




    function preMain() {
    setPriceStudy(false);
    setStudyTitle("Zero Lag EMA ");
    setCursorLabelName("sEMA", 0);
    setDefaultBarFgColor(Color.red, 0);
    setDefaultBarThickness(1, 0);
    setCursorLabelName("fEMA", 1);
    setDefaultBarFgColor(Color.green, 1);
    setDefaultBarThickness(1, 1);


    var fp1 = new FunctionParameter("sPeriods", FunctionParameter.NUMBER);
    fp1.setName("Periods");
    fp1.setLowerLimit(1);
    fp1.setDefault(7);

    var fp2 = new FunctionParameter("fPeriods", FunctionParameter.NUMBER);
    fp2.setName("Periods");
    fp2.setLowerLimit(1);
    fp2.setDefault(21);
    }

    // Global Variables
    var bVersion = null; // Version flag
    var bInit = false; // Initialization flag

    var xEma1 = null;
    var xEma2 = null;

    var fEMA1 = null;
    var fEMA2 = null;

    function main(sPeriods, fPeriods) {
    var nState = getBarState();
    var nIndex = getCurrentBarIndex();



    if (bInit == false) {
    xEma1 = ema(sPeriods);
    xEma2 = ema(sPeriods, xEma1);

    fEma1 = ema(fPeriods);
    fEma2 = ema(fPeriods, fEma1);
    bInit = true;
    }

    var nZEma = null;
    var nEma1 = xEma1.getValue(0);
    var nEma2 = xEma2.getValue(0);
    if (nEma1 == null || nEma2 == null) return;

    nZEma = nEma1 + (nEma1 - nEma2);


    var fZEma = null;
    var fEma1 = fEma1.getValue(0);
    var fEma2 = fEma2.getValue(0);
    if (fEma1 == null || fEma2 == null) return;

    fZEma = fEma1 + (fEma1 - fEma2);


    return (nZEma, fZEma);
    }

  • #2
    Re: fix efs script...

    vincentjianq
    The error is in the following two lines of code
    var fEma1 = fEma1.getValue(0);
    var fEma2 = fEma2.getValue(0);

    where you are declaring local variables that have the same name of the series. Rename the variables eg
    var nEma1 = fEma1.getValue(0);
    var nEma2 = ...

    and then replace each instance of fEma1 and fEma2 following those two lines of code with nEma1 etc
    Once you do that the formula should work
    Alex


    Originally posted by vincentjiang
    can some help to fix below efs?


    function preMain() {
    setPriceStudy(false);
    setStudyTitle("Zero Lag EMA ");
    setCursorLabelName("sEMA", 0);
    setDefaultBarFgColor(Color.red, 0);
    setDefaultBarThickness(1, 0);
    setCursorLabelName("fEMA", 1);
    setDefaultBarFgColor(Color.green, 1);
    setDefaultBarThickness(1, 1);


    var fp1 = new FunctionParameter("sPeriods", FunctionParameter.NUMBER);
    fp1.setName("Periods");
    fp1.setLowerLimit(1);
    fp1.setDefault(7);

    var fp2 = new FunctionParameter("fPeriods", FunctionParameter.NUMBER);
    fp2.setName("Periods");
    fp2.setLowerLimit(1);
    fp2.setDefault(21);
    }

    // Global Variables
    var bVersion = null; // Version flag
    var bInit = false; // Initialization flag

    var xEma1 = null;
    var xEma2 = null;

    var fEMA1 = null;
    var fEMA2 = null;

    function main(sPeriods, fPeriods) {
    var nState = getBarState();
    var nIndex = getCurrentBarIndex();



    if (bInit == false) {
    xEma1 = ema(sPeriods);
    xEma2 = ema(sPeriods, xEma1);

    fEma1 = ema(fPeriods);
    fEma2 = ema(fPeriods, fEma1);
    bInit = true;
    }

    var nZEma = null;
    var nEma1 = xEma1.getValue(0);
    var nEma2 = xEma2.getValue(0);
    if (nEma1 == null || nEma2 == null) return;

    nZEma = nEma1 + (nEma1 - nEma2);


    var fZEma = null;
    var fEma1 = fEma1.getValue(0);
    var fEma2 = fEma2.getValue(0);
    if (fEma1 == null || fEma2 == null) return;

    fZEma = fEma1 + (fEma1 - fEma2);


    return (nZEma, fZEma);
    }

    Comment


    • #3
      thanks...

      how come it only draw 1 line? I like to have 2 lines..one is ema_7, another one is ema_21.


      function preMain() {
      setPriceStudy(false);
      setStudyTitle("Zero Lag EMA ");
      setCursorLabelName("sEMA", 0);
      setDefaultBarFgColor(Color.red, 0);
      setDefaultBarThickness(1, 0);
      setCursorLabelName("fEMA", 1);
      setDefaultBarFgColor(Color.green, 1);
      setDefaultBarThickness(1, 1);


      var fp1 = new FunctionParameter("sPeriods", FunctionParameter.NUMBER);
      fp1.setName("Periods");
      fp1.setLowerLimit(1);
      fp1.setDefault(7);

      var fp2 = new FunctionParameter("fPeriods", FunctionParameter.NUMBER);
      fp2.setName("Periods");
      fp2.setLowerLimit(1);
      fp2.setDefault(21);
      }

      // Global Variables
      var bVersion = null; // Version flag
      var bInit = false; // Initialization flag

      var xEma1 = null;
      var xEma2 = null;

      var fEma1 = null;
      var fEma2 = null;

      function main(sPeriods, fPeriods) {
      var nState = getBarState();
      var nIndex = getCurrentBarIndex();



      if (bInit == false) {
      xEma1 = ema(sPeriods);
      xEma2 = ema(sPeriods, xEma1);

      fEma1 = ema(fPeriods);
      fEma2 = ema(fPeriods, fEma1);
      bInit = true;
      }

      var nZEma = null;
      var nEma1 = xEma1.getValue(0);
      var nEma2 = xEma2.getValue(0);
      if (nEma1 == null || nEma2 == null) return;

      nZEma = nEma1 + (nEma1 - nEma2);


      var fZEma = null;
      var fnEma1 = fEma1.getValue(0);
      var fnEma2 = fEma2.getValue(0);
      if (fnEma1 == null || fnEma2 == null) return;

      fZEma = fnEma1 + (fnEma1 - fnEma2);


      return (nZEma, fZEma);
      }
      Last edited by vincentjiang; 03-13-2009, 04:35 PM.

      Comment


      • #4
        vincentjianq
        I did not see that you were already using variables with the same name I was suggesting.
        Using the initial script repeat the steps I outlined earlier but instead of replacing the letter f with n replace it with z [ie zEma1, etc]
        Once you have done that you also need to change the return statement from return (...) to return new Array (...) as you are returning more than one item
        Alex


        Originally posted by vincentjiang
        thanks...

        how come it only draw 1 line? I like to have 2 lines..one is ema_7, another one is ema_21.


        function preMain() {
        setPriceStudy(false);
        setStudyTitle("Zero Lag EMA ");
        setCursorLabelName("sEMA", 0);
        setDefaultBarFgColor(Color.red, 0);
        setDefaultBarThickness(1, 0);
        setCursorLabelName("fEMA", 1);
        setDefaultBarFgColor(Color.green, 1);
        setDefaultBarThickness(1, 1);


        var fp1 = new FunctionParameter("sPeriods", FunctionParameter.NUMBER);
        fp1.setName("Periods");
        fp1.setLowerLimit(1);
        fp1.setDefault(7);

        var fp2 = new FunctionParameter("fPeriods", FunctionParameter.NUMBER);
        fp2.setName("Periods");
        fp2.setLowerLimit(1);
        fp2.setDefault(21);
        }

        // Global Variables
        var bVersion = null; // Version flag
        var bInit = false; // Initialization flag

        var xEma1 = null;
        var xEma2 = null;

        var fEma1 = null;
        var fEma2 = null;

        function main(sPeriods, fPeriods) {
        var nState = getBarState();
        var nIndex = getCurrentBarIndex();



        if (bInit == false) {
        xEma1 = ema(sPeriods);
        xEma2 = ema(sPeriods, xEma1);

        fEma1 = ema(fPeriods);
        fEma2 = ema(fPeriods, fEma1);
        bInit = true;
        }

        var nZEma = null;
        var nEma1 = xEma1.getValue(0);
        var nEma2 = xEma2.getValue(0);
        if (nEma1 == null || nEma2 == null) return;

        nZEma = nEma1 + (nEma1 - nEma2);


        var fZEma = null;
        var fnEma1 = fEma1.getValue(0);
        var fnEma2 = fEma2.getValue(0);
        if (fnEma1 == null || fnEma2 == null) return;

        fZEma = fnEma1 + (fnEma1 - fnEma2);


        return (nZEma, fZEma);
        }

        Comment

        Working...
        X