Announcement

Collapse
No announcement yet.

Trailing Stop p15, with inv()

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

  • Trailing Stop p15, with inv()

    Hi I try to make the following .efs, Trailing Stop p15, with inv(1).
    I made some changes but still not working what do I do wrong? Any Ideas
    Elias
    ............
    /************************************************** ***************
    Provided By : eSignal (c) Copyright 2004
    Description: Volatility Trailing Stop P15 - by Jim Berg

    Version 1.0

    Notes:
    February 2005 Issue - "The Truth About Volatility"

    Formula Parameters: Defaults:
    ATR Periods 10
    Thickness 2
    ************************************************** ***************/

    function preMain() {
    setPriceStudy(true);
    setStudyTitle("AAA_Volatility Trailing Stop P15 ");
    setCursorLabelName("VStop", 0);
    setDefaultBarThickness(2, 0);
    setDefaultBarFgColor(Color.red, 0);

    setShowTitleParameters(false);

    // Formula Parameters
    var fp1 = new FunctionParameter("nATRlen", FunctionParameter.NUMBER);
    fp1.setName("ATR Periods");
    fp1.setLowerLimit(1);
    fp1.setDefault(10);

    // Study Parameters
    var sp1 = new FunctionParameter("nThick", FunctionParameter.NUMBER);
    sp1.setName("Thickness");
    sp1.setDefault(2);
    }

    var bEdit = true;
    var vATR = null;
    var aStop = new Array(15,inv(1));


    function main(nATRlen, nThick) {
    if (bEdit == true) {
    vATR = new ATRStudy(nATRlen);
    setDefaultBarThickness(nThick, 0);
    bEdit = false;
    }

    var nState = getBarState();
    if (nState == BARSTATE_NEWBAR) {
    aStop.pop();
    aStop.unshift(0);
    }

    var ATR = vATR.getValue(0);
    if (ATR == null) return;

    var c = close();
    var vStop = (c - (2*ATR));
    aStop[0] = vStop;

    var vStop15 = vStop;
    for (var i = 0; i < 15; i++) {
    vStop15 = Math.max(aStop[i], vStop15);
    }

    return vStop15;
    }

  • #2
    Elias
    Simply adding an inv() series to any function does not automatically make a study usable with multiple time frames. You need to first ensure that the function actually accepts the inv() series and the way to do this is to check the EFS2 Function Reference in the EFS KnowledgeBase
    In the case of your script you used inv() inside an array which does not accept that series as an input.
    The easiest way to convert your study to use multiple intervals is to actually call it from a new efs using the efsExternal() function and passing the inv() series as the last parameter.
    For explanations on the efsExternal() function and examples on how to use it see this thread.
    If you instead prefer to mantain the efs as a single script you will need to modify it in the same way I showed you in this thread.
    In this case remove all instances of inv() and rename the current function main(nATRlen,nThick) to (for example) function calcATR(nATRlen,interval).
    Once you have done that create a new function main in which you will use the efsInternal() function to call the calcATR function ie.
    function main(nATRlen,nThick){
    var Stop = efsInternal("calcATR",nATRlen, inv(1));
    return Stop;
    }

    As you can see the logic and the process are virtually identical to the one used in the other thread
    Alex

    Comment


    • #3
      Ok Alex I wrote a new efs to call an external file and is the following
      ......
      PHP Code:
      function preMain() {
          
      setPriceStudy(true);
          
      setStudyTitle("AAA_Volatility Trailing Stop P15_ext2 ");
          
      setCursorLabelName("VStop"0);
          
      setDefaultBarThickness(20);
          
      setDefaultBarFgColor(Color.red0);
          
          
      setShowTitleParameters(false);
          





      function 
      main(nATRlen,nThick) {
         
          
        
      var 
      Stop efsExternal("AAA_VolatilityTrailingStopP15_ext.efs",nATRleninv(1));
      return 
      Stop;
      }
      }
      .............
      what thios above efs calls is the following in the same folder

      ..........
      /*****************************************************************
      Provided By : eSignal (c) Copyright 2004
      Description:  Volatility Trailing Stop P15 - by Jim Berg

      Version 1.0

      Notes:
      February 2005 Issue - "The Truth About Volatility"

      Formula Parameters:                 Defaults:
      ATR Periods                         10
      Thickness                           2
      *****************************************************************/

      function preMain() {
          
      setPriceStudy(true);
          
      setStudyTitle("AAA_Volatility Trailing Stop P15 ");
          
      setCursorLabelName("VStop"0);
          
      setDefaultBarThickness(20);
          
      setDefaultBarFgColor(Color.red0);
          
          
      setShowTitleParameters(false);
          
          
      // Formula Parameters
          
      var fp1 = new FunctionParameter("nATRlen"FunctionParameter.NUMBER);
              
      fp1.setName("ATR Periods");
              
      fp1.setLowerLimit(1);
              
      fp1.setDefault(10);

          
      // Study Parameters
          
      var sp1 = new FunctionParameter("nThick"FunctionParameter.NUMBER);
              
      sp1.setName("Thickness");
              
      sp1.setDefault(2);
      }

      var 
      bEdit true;
      var 
      vATR null;
      var 
      aStop = new Array(15);
      function 
      calcATR(nATRleninterval){

      function 
      main(nATRlennThick) {
          if (
      bEdit == true) {
              
      vATR = new ATRStudy(nATRlen);
              
      setDefaultBarThickness(nThick0);
              
      bEdit false;
          }
          
          var 
      nState getBarState();
          if (
      nState == BARSTATE_NEWBAR) {
              
      aStop.pop();
              
      aStop.unshift(0);
          }
          
          var 
      ATR vATR.getValue(ATRStudy.ATR);
          if (
      ATR == null) return;
          
          var 
      close();
          var 
      vStop = (- (2*ATR));
          
      aStop[0] = vStop;
          
          var 
      vStop15 vStop;
          for (var 
      015i++) {
              
      vStop15 Math.max(aStop[i], vStop15);
          }
          
          return 
      vStop15;
      }

      .............
      but is not working. What do I do wrong?
      Elias

      Comment


      • #4
        Elias
        There are several errors in both scripts.
        In the calling efs when using efsExternal() you are passing the nATRlen parameter but the value for that parameter is not defined anywhere. You need to either add a Function Parameter in preMain or initialize the parameter in main (I would suggest the former since you already have an example of that in the called efs).
        In the calling efs you are also missing a closing bracket for function preMain and you have a redundant closing bracket after the one that ends function main.
        As to the called efs the function calcATR(nATRlen, interval){ should not have been added (that change was applicable only if you were going to use the script you posted originally as a single efs).
        Also in the called efs you have a redundant closing bracket after the one that ends function main.
        Once you have fixed these errors you will also need to remove or comment out setDefaultBarThickness(nThick, 0); from the called efs else you will get an error. Lastly even though this will not generate an error I would suggest replacing nThick in function main(nATRlen, nThick) { of the called efs with Interval so that you can identify what that parameter is actually for.
        Alex

        Comment


        • #5
          I made some modif but still error at 43: ATRStudy parameter 1 invalid, on calledefs.



          calledefs
          .......
          PHP Code:
          /*****************************************************************
          Provided By : eSignal (c) Copyright 2004
          Description:  Volatility Trailing Stop P15 - by Jim Berg

          Version 1.0

          Notes:
          February 2005 Issue - "The Truth About Volatility"

          Formula Parameters:                 Defaults:
          ATR Periods                         10
          Thickness                           2
          *****************************************************************/

          function preMain() {
              
          setPriceStudy(true);
              
          setStudyTitle("AAA_Volatility Trailing Stop P15 ");
              
          setCursorLabelName("VStop"0);
              
          setDefaultBarThickness(20);
              
          setDefaultBarFgColor(Color.red0);
              
              
          setShowTitleParameters(false);
              
              
          // Formula Parameters
              
          var fp1 = new FunctionParameter("nATRlen"FunctionParameter.NUMBER);
                  
          fp1.setName("ATR Periods");
                  
          fp1.setLowerLimit(1);
                  
          fp1.setDefault(10);

              
          // Study Parameters
              
          var sp1 = new FunctionParameter("nThick"FunctionParameter.NUMBER);
                  
          sp1.setName("Thickness");
                  
          sp1.setDefault(2);
          }

          var 
          bEdit true;
          var 
          vATR null;
          var 
          aStop = new Array(15);


          function 
          main(nATRlenInterval) {
              if (
          bEdit == true) {
               
          vATR = new ATRStudy(nATRlen);

              
          bEdit false;
              }
              
              var 
          nState getBarState();
              if (
          nState == BARSTATE_NEWBAR) {
                  
          aStop.pop();
                  
          aStop.unshift(0);
              }
              
              var 
          ATR vATR.getValue(ATRStudy.ATR);
              if (
          ATR == null) return;
              
              var 
          close();
              var 
          vStop = (- (2*ATR));
              
          aStop[0] = vStop;
              
              var 
          vStop15 vStop;
              for (var 
          015i++) {
                  
          vStop15 Math.max(aStop[i], vStop15);
              }
              
              return 
          vStop15;

          CallerEfs

          PHP Code:
          function preMain() {
              
          setPriceStudy(true);
              
          setStudyTitle("AAA_Volatility Trailing Stop P15_ext2 ");
              
          setCursorLabelName("VStop"0);
              
          setDefaultBarThickness(20);
              
          setDefaultBarFgColor(Color.red0);
              
              
          setShowTitleParameters(false);
              
          }



          function 
          main(nATRlen,interval) {
              
          vATR = (nATRlen);
              var 
          Stop efsExternal("AAA_VolatilityTrailingStopP15_ext.efs",nATRleninv(1));
              return 
          Stop;

          Any Ideas I did not understand well the modifications about nATRlen I sould of done on calledefs sorry

          Elias

          Comment


          • #6
            I DID IT
            CallerEfs
            ..................

            function preMain() {
            setPriceStudy(true);
            setStudyTitle("AAA_Volatility Trailing Stop P15_ext2 ");
            setCursorLabelName("VStop", 0);
            setDefaultBarThickness(2, 0);
            setDefaultBarFgColor(Color.red, 0);

            setShowTitleParameters(false);
            // Formula Parameters
            var fp1 = new FunctionParameter("nATRlen", FunctionParameter.NUMBER);
            fp1.setName("ATR Periods");
            fp1.setLowerLimit(1);
            fp1.setDefault(10);

            // Study Parameters
            var sp1 = new FunctionParameter("nThick", FunctionParameter.NUMBER);
            sp1.setName("Thickness");
            sp1.setDefault(2);

            }
            var bEdit = true;
            var vATR = null;
            var aStop = new Array(15);


            function main(nATRlen,interval) {
            if (bEdit == true) {
            vATR = new ATRStudy(nATRlen);
            bEdit = false;
            }
            var Stop = efsExternal("AAA_VolatilityTrailingStopP15_ext.efs ",nATRlen, inv(1));
            return Stop;
            }



            CallingEfs
            ........
            /************************************************** ***************
            Provided By : eSignal (c) Copyright 2004
            Description: Volatility Trailing Stop P15 - by Jim Berg

            Version 1.0

            Notes:
            February 2005 Issue - "The Truth About Volatility"

            Formula Parameters: Defaults:
            ATR Periods 10
            Thickness 2
            ************************************************** ***************/

            function preMain() {
            setPriceStudy(true);
            setStudyTitle("AAA_Volatility Trailing Stop P15 ");
            setCursorLabelName("VStop", 0);
            setDefaultBarThickness(2, 0);
            setDefaultBarFgColor(Color.red, 0);

            setShowTitleParameters(false);

            // Formula Parameters
            var fp1 = new FunctionParameter("nATRlen", FunctionParameter.NUMBER);
            fp1.setName("ATR Periods");
            fp1.setLowerLimit(1);
            fp1.setDefault(10);

            // Study Parameters
            var sp1 = new FunctionParameter("nThick", FunctionParameter.NUMBER);
            sp1.setName("Thickness");
            sp1.setDefault(2);
            }

            var bEdit = true;
            var vATR = null;
            var aStop = new Array(15);


            function main(nATRlen, Interval) {
            if (bEdit == true) {
            vATR = new ATRStudy(nATRlen);
            bEdit = false;
            }

            var nState = getBarState();
            if (nState == BARSTATE_NEWBAR) {
            aStop.pop();
            aStop.unshift(0);
            }

            var ATR = vATR.getValue(ATRStudy.ATR);
            if (ATR == null) return;

            var c = close();
            var vStop = (c - (2*ATR));
            aStop[0] = vStop;

            var vStop15 = vStop;
            for (var i = 0; i < 15; i++) {
            vStop15 = Math.max(aStop[i], vStop15);
            }

            return vStop15;
            }

            ...........
            I am sure that I can erase few not nessaisary things but I think I will let as it is due that is working.

            Thanks
            Elias

            Comment


            • #7
              Elias
              That is correct. To clean the script remove the following two groups of lines from the caller efs as they are not required (or used)
              Alex

              PHP Code:
              var bEdit true;
              var 
              vATR null;
              var 
              aStop = new Array(15); 
              PHP Code:
              if (bEdit == true) {
              vATR = new ATRStudy(nATRlen);
              bEdit false;

              Comment


              • #8
                Everything fine this is my 3rd modifiv=cation. I start understanding some more now.
                Thanks again Alex and congratulation for your knowlege and profesinalism
                Elias

                Comment


                • #9
                  Elias
                  My pleasure and thank you for the compliments
                  Alex

                  Comment

                  Working...
                  X