Announcement

Collapse
No announcement yet.

Polarized Fractal Efficiency Modification Request

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

  • Polarized Fractal Efficiency Modification Request

    Hi all, I'm a new eSignal user, but not new to trading. I'm moving over my indicators from my current software platform, but I'm having difficulty with one of them. This is the PFE indicator originally developed by Hans Hannula.

    I like this indicator; I find it to be a very useful indicator in providing me with clues about what the market is doing. However, I find the eSignal efs version of it (which can be found here in the forum ) to be limited.

    I know very little about javascript; I have been able to go into it and modify the length, but the code from my broker contains an additional input for smoothing length... here is their version in its entirety:

    declare lower;

    input length = 10;
    input smoothingLength = 5;

    def diff = close - close[length - 1];
    def val = 100 * Sqrt(Sqr(diff) + Sqr(length)) / sum(Sqrt(1 + Sqr(close - close[1])), length - 1);

    plot PFE = ExpAverage(if diff > 0 then val else -val, smoothingLength);
    plot UpperLevel = 50;
    plot ZeroLine = 0;
    plot LowerLevel = -50;

    PFE.SetDefaultColor(GetColor(8)); UpperLevel.SetDefaultColor(GetColor(5)); ZeroLine.SetDefaultColor(GetColor(5)); LowerLevel.SetDefaultColor(GetColor(5));
    Would someone help me modify the PFE.efs file to include a smoothing length and two inputs that I can change without having to go into the efs file - one for length and the other for smoothing length?

    Any help would be greatly appreciated.

  • #2
    Re: Polarized Fractal Efficiency Modification Request

    fmanu1
    The efs you referenced actually uses both parameters except that they were not set to be user definable.
    To add that functionality is relatively simple.
    As a first step add the following lines of code in the preMain function
    PHP Code:
    var fp1 = new FunctionParameter("Length"FunctionParameter.NUMBER);
     
    fp1.setDefault(10); 
     
     var 
    fp2 = new FunctionParameter("Smoothing"FunctionParameter.NUMBER);
     
    fp2.setDefault(5); 
    These use the FunctionParameter Object to create user definable parameters (see the link to the corresponding article in the EFS KnowledgeBase for more information and other examples)
    Now you need to add these parameters to the arguments of the main function eg
    PHP Code:
    function main(LengthSmoothing) { 
    Once you have done that you need to add the Length parameter in the efsInternal() call so as to pass it to the corresponding function eg
    PHP Code:
    xFracEff efsInternal("Calc_FracEff"Length); 
    Then replace the 5 with Smoothing in the line of code where the ema is initialized eg
    PHP Code:
    xEMA ema(SmoothingxFracEff
    Now you also need to add the Length parameter to the arguments of the CalcFracEff function eg
    PHP Code:
    function Calc_FracEff(Length){ 
    At this point you need to replace close(-9) with close(-(Length-1)) in lines 65 and 69 of the original formula eg
    PHP Code:
    PFE Math.sqrt(Math.pow((close(0) - close(-(Length-1))),2) + 100);
    //and
    if ((close(0) - close(-(Length-1))) > 0FracEff Math.round((PFE C2C) * 100); 
    and replace Counter < 10 with Counter < Length in line 66 eg
    PHP Code:
    for (Counter 1Counter LengthCounter++)    { 
    Once you have implemented these changes save the efs with a new name so as not to overwrite the original.
    Then load the efs and you should be able to adjust the Length and Smoothing parameters from Edit Studies
    If you are unfamiliar with programming in efs and are interested in learning then I would suggest that you begin by reviewing the JavaScript for EFS video series and the Core JavaScript Reference Guide. Those will provide you with a thorough introduction to programming in JavaScript which is at the foundation of EFS. Then go through the EFS KnowledgeBase and study the Help Guides and Tutorials which will provide you with the specifics of EFS.
    Alex


    Originally posted by fmanu1
    Hi all, I'm a new eSignal user, but not new to trading. I'm moving over my indicators from my current software platform, but I'm having difficulty with one of them. This is the PFE indicator originally developed by Hans Hannula.

    I like this indicator; I find it to be a very useful indicator in providing me with clues about what the market is doing. However, I find the eSignal efs version of it (which can be found here in the forum ) to be limited.

    I know very little about javascript; I have been able to go into it and modify the length, but the code from my broker contains an additional input for smoothing length... here is their version in its entirety:



    Would someone help me modify the PFE.efs file to include a smoothing length and two inputs that I can change without having to go into the efs file - one for length and the other for smoothing length?

    Any help would be greatly appreciated.

    Comment


    • #3
      Thanks for the help, Alex. Unfortunately, I think I made a mistake. When I tried to do a syntax check I got an error saying that I was missing a } after the function body, which is right at the end of the code, but I wasn't able to correct this.

      This is the code based upon what I could figure out.

      PHP Code:
      Formula Parameters
      Default: **********************************/

        var 
      bInit false;  function preMain() {     setStudyTitle("Polarized Fractal Efficiency");     
      setCursorLabelName("EMA"0);     
      setDefaultBarFgColor(Color.aqua0);      
      addBand(50PS_SOLID1Color.blue);         
      addBand(-50PS_SOLID1Color.red);            
      var 
      fp1 = new FunctionParameter("Length"FunctionParameter.NUMBER);
       
      fp1.setDefault(10);       
      var 
      fp2 = new FunctionParameter("Smoothing"FunctionParameter.NUMBER);   fp2.setDefault(5);   }  
      var 
      xEMA null; var xFracEff null;   
      function 
      main() { var nBarState getBarState(); 
      var 
      nEMA 0;         
      if ( 
      bInit == false ) {          xFracEff efsInternal("Calc_FracEff"Length);         
      xEMA ema(SmoothingxFracEff)         bInit true;      }       
      nEMA xEMA.getValue(0);     
      if (
      nEMA == null) return;          
      return 
      nEMA;     
      function 
      main(LengthSmoothing) { }   function Calc_FracEff(Length){ var PFE 0; var C2C 0
      var 
      Counter 0
      var 
      FracEff 0;     
      PFE Math.sqrt(Math.pow((close(0) - close(-(Length-1))),2) + 100);      
      for (
      Counter 1Counter LengthCounter++)    {         C2C += Math.sqrt(Math.pow((close(-Counter 1) - close(-Counter)), 2) + 1);     }     
      if ((
      close(0) - close(-(Length-1))) > 0FracEff Math.round((PFE C2C) * 100);     
      else 
      FracEff Math.round(-(PFE C2C) * 100);     if (FracEff == nullFracEff 1;     return FracEff; } 
      Can you help me clarify my mistake?

      Thanks

      Comment


      • #4
        While I wasn't able to get the code right, I was able to figure out what the smoothing length was. I've created a couple of different instances of the indicator. That's all I need, since I only use a coupe of different settings. I appreciate the help.

        Comment


        • #5
          fmanu1
          Enclosed below is the corrected version of your revision so that you can compare them
          Alex


          PHP Code:
          var bInit false;
          function 
          preMain() {
              
          setStudyTitle("Polarized Fractal Efficiency");
              
          setCursorLabelName("EMA"0);
              
          setDefaultBarFgColor(Color.aqua0);
              
          addBand(50PS_SOLID1Color.blue);
              
          addBand( - 50PS_SOLID1Color.red);
              var 
          fp1 = new FunctionParameter("Length"FunctionParameter.NUMBER);
              
          fp1.setDefault(10);
              var 
          fp2 = new FunctionParameter("Smoothing"FunctionParameter.NUMBER);
              
          fp2.setDefault(5);
          }
          var 
          xEMA null;
          var 
          xFracEff null;
          function 
          main(LengthSmoothing) {
              var 
          nBarState getBarState();
              var 
          nEMA 0;
              if (
          bInit == false) {
                  
          xFracEff efsInternal("Calc_FracEff"Length);
                  
          xEMA ema(SmoothingxFracEff) ;
                  
          bInit true;
              }
              
          nEMA xEMA.getValue(0);
              if (
          nEMA == null) return;
              return 
          nEMA;
          }
          function 
          Calc_FracEff(Length) {
              var 
          PFE 0;
              var 
          C2C 0;
              var 
          Counter 0;
              var 
          FracEff 0;
              
          PFE Math.sqrt(Math.pow((close(0) - close( - (Length 1))), 2) + 100);
              for (
          Counter 1Counter LengthCounter++) {
                  
          C2C += Math.sqrt(Math.pow((close( - Counter 1) - close( - Counter)), 2) + 1);
              }
              if ((
          close(0) - close( - (Length 1))) > 0FracEff Math.round((PFE C2C) * 100);
              else 
          FracEff Math.round( - (PFE C2C) * 100);
              if (
          FracEff == nullFracEff 1;
              return 
          FracEff;


          Originally posted by fmanu1
          Thanks for the help, Alex. Unfortunately, I think I made a mistake. When I tried to do a syntax check I got an error saying that I was missing a } after the function body, which is right at the end of the code, but I wasn't able to correct this.

          This is the code based upon what I could figure out.

          PHP Code:
          Formula Parameters
          Default: **********************************/

            var 
          bInit false;  function preMain() {     setStudyTitle("Polarized Fractal Efficiency");     
          setCursorLabelName("EMA"0);     
          setDefaultBarFgColor(Color.aqua0);      
          addBand(50PS_SOLID1Color.blue);         
          addBand(-50PS_SOLID1Color.red);            
          var 
          fp1 = new FunctionParameter("Length"FunctionParameter.NUMBER);
           
          fp1.setDefault(10);       
          var 
          fp2 = new FunctionParameter("Smoothing"FunctionParameter.NUMBER);   fp2.setDefault(5);   }  
          var 
          xEMA null; var xFracEff null;   
          function 
          main() { var nBarState getBarState(); 
          var 
          nEMA 0;         
          if ( 
          bInit == false ) {          xFracEff efsInternal("Calc_FracEff"Length);         
          xEMA ema(SmoothingxFracEff)         bInit true;      }       
          nEMA xEMA.getValue(0);     
          if (
          nEMA == null) return;          
          return 
          nEMA;     
          function 
          main(LengthSmoothing) { }   function Calc_FracEff(Length){ var PFE 0; var C2C 0
          var 
          Counter 0
          var 
          FracEff 0;     
          PFE Math.sqrt(Math.pow((close(0) - close(-(Length-1))),2) + 100);      
          for (
          Counter 1Counter LengthCounter++)    {         C2C += Math.sqrt(Math.pow((close(-Counter 1) - close(-Counter)), 2) + 1);     }     
          if ((
          close(0) - close(-(Length-1))) > 0FracEff Math.round((PFE C2C) * 100);     
          else 
          FracEff Math.round(-(PFE C2C) * 100);     if (FracEff == nullFracEff 1;     return FracEff; } 
          Can you help me clarify my mistake?

          Thanks

          Comment


          • #6
            Excellent! Yes that pretty much captures what it does and the variable length inputs are convenient too. Thanks again for the help and here is a EFS file of it.
            Attached Files

            Comment


            • #7
              fmanu1
              You are most welcome
              Alex


              Originally posted by fmanu1
              Excellent! Yes that pretty much captures what it does and the variable length inputs are convenient too. Thanks again for the help and here is a EFS file of it.

              Comment

              Working...
              X