Announcement

Collapse
No announcement yet.

PPO.efs

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

  • PPO.efs

    I am using the PPO.efs and I noted that the data from it do not appear in the Cursor Window.
    Please, could someone help me to fix this problem?

  • #2
    Barros
    You may want to provide a link to the efs or post the code
    Alex

    Comment


    • #3
      Ok Alex:

      /************************************************
      Alexis C. Montenegro © August 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 vMA1 = null;
      var vMA2 = null;

      function preMain() {

      setStudyTitle("PPO");
      setShowCursorLabel(false);
      setDefaultBarFgColor(Color.cyan,0);
      setDefaultBarFgColor(Color.red,1);
      setDefaultBarFgColor(Color.lightgrey,2);
      //addBand(0, PS_SOLID, 1, Color.lightgrey,"zero");
      setDefaultBarThickness(2,0);
      setDefaultBarThickness(1,1);
      setDefaultBarThickness(2,2);
      setPlotType(PLOTTYPE_HISTOGRAM,2);
      //checkVersion(1,"http://share.esignal.com/ContentRoot/ACM%20Test/Formulas/basicMAx2.efs"); //Comment this line out if modifying the code

      var fp1 = new FunctionParameter("MALength", FunctionParameter.NUMBER);
      fp1.setLowerLimit(1);
      fp1.setDefault(9);

      var fp2 = new FunctionParameter("MAType", FunctionParameter.STRING);
      fp2.setName("MAType");
      fp2.addOption("Simple");
      fp2.addOption("Exponential");
      fp2.setDefault("Exponential"); //Edit this value to set a new default

      var fp3 = new FunctionParameter("MA1Length", FunctionParameter.NUMBER);
      fp3.setLowerLimit(1);
      fp3.setDefault(12); //Edit this value to set a new default

      var fp4 = new FunctionParameter("MA1Source", FunctionParameter.STRING);
      fp4.setName("MA1Source");
      fp4.addOption("Close");
      fp4.addOption("High");
      fp4.addOption("Low");
      fp4.addOption("Open");
      fp4.addOption("HL/2");
      fp4.addOption("HLC/3");
      fp4.addOption("OHLC/4");
      fp4.setDefault("Close"); //Edit this value to set a new default

      var fp5 = new FunctionParameter("MA1Type", FunctionParameter.STRING);
      fp5.setName("MA1Type");
      fp5.addOption("MAStudy.SIMPLE");
      fp5.addOption("MAStudy.EXPONENTIAL");
      fp5.addOption("MAStudy.WEIGHTED");
      fp5.addOption("MAStudy.VOLUMEWEIGHTED");
      fp5.setDefault("MAStudy.EXPONENTIAL"); //Edit this value to set a new default

      var fp6 = new FunctionParameter("MA2Length", FunctionParameter.NUMBER);
      fp6.setLowerLimit(1);
      fp6.setDefault(26); //Edit this value to set a new default

      var fp7 = new FunctionParameter("MA2Source", FunctionParameter.STRING);
      fp7.setName("MA1Source");
      fp7.addOption("Close");
      fp7.addOption("High");
      fp7.addOption("Low");
      fp7.addOption("Open");
      fp7.addOption("HL/2");
      fp7.addOption("HLC/3");
      fp7.addOption("OHLC/4");
      fp7.setDefault("Close"); //Edit this value to set a new default

      var fp8 = new FunctionParameter("MA2Type", FunctionParameter.STRING);
      fp8.setName("MA2Type");
      fp8.addOption("MAStudy.SIMPLE");
      fp8.addOption("MAStudy.EXPONENTIAL");
      fp8.addOption("MAStudy.WEIGHTED");
      fp8.addOption("MAStudy.VOLUMEWEIGHTED");
      fp8.setDefault("MAStudy.EXPONENTIAL"); //Edit this value to set a new default


      }

      var bPrimed = false;
      var vEMA = null;
      var vEMA1 = null;
      var dPercent = 0.0;
      var vValue = 0.0;
      var aValue = null;
      var vAvg = null;//used in the example provided

      function main(MALength,MAType,MA1Length,MA1Source,MA1Type,M A2Length,MA2Source,MA2Type) {

      var i;
      var vSum = 0.0;

      //insert below the calculations required for the user defined variable (example provided)
      if (vMA1 == null) vMA1 = new MAStudy(MA1Length, MA1Source, eval(MA1Type));
      if (vMA2 == null) vMA2 = new MAStudy(MA2Length, MA2Source, eval(MA2Type));

      var Avg1 = vMA1.getValue(MAStudy.MA)
      if(Avg1 == null) return;
      var Avg2 = vMA2.getValue(MAStudy.MA);
      if(Avg2 == null) return;

      vAvg = (Avg1-Avg2)/Avg1;

      //end section for user defined variable

      vValue = vAvg; //replace vAvg with the user defined variable

      if(vValue == null) {
      return;
      }

      if (aValue == null) {
      aValue = new Array(MALength);
      }
      if (getBarState() == BARSTATE_NEWBAR) {
      aValue.pop();
      aValue.unshift(vValue);
      } else {
      aValue[0] = vValue;
      }

      for(i = 0; i < MALength; i++) {
      vSum += aValue[i];
      }

      var vMA = (vSum/MALength);


      if(MAType=="Exponential"){
      if(aValue[MALength-1] != null) vEMA = EMA(MALength, aValue);
      return new Array( vValue,vEMA, (vValue-vEMA));
      }else{
      return new Array (vValue,vMA, (vValue-vMA));
      }
      }


      function EMA(MALength, aValue) {

      var dSum = 0.0;

      if(getBarState() == BARSTATE_ALLBARS || bPrimed == false) {
      dPercent = (2.0 / (MALength + 1.0));
      bPrimed = false;
      }

      if (getBarState() == BARSTATE_NEWBAR) {
      vEMA1 = vEMA;
      }

      if(bPrimed == false) {
      for(var i = 0; i < MALength; i++) {
      dSum += aValue[i];
      }
      bPrimed = true;
      return (dSum / MALength);
      } else {
      return (((vValue - vEMA1) * dPercent) + vEMA1);
      }
      }

      Comment


      • #4
        Barros
        Comment out or remove setShowCursorLabel(false); in preMain.
        Alex

        Comment


        • #5
          Obrigado

          Alex,
          It is working very well.
          Thank you very much.

          Comment


          • #6
            Barros
            You are most welcome
            Alex

            Comment

            Working...
            X