Announcement

Collapse
No announcement yet.

Add Parameter to EFS

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

  • Add Parameter to EFS

    I have just created a very simple indicator showing the difference between the price and the MA. How can I make the MA period a parameter rather than a hard coded number (currently 10)?

    Thanks in advance!!


    PHP Code:
    //{{EFSWizard_Description
    //
    //    This formula was generated by the Alert Wizard
    //
    //}}EFSWizard_Description


    //{{EFSWizard_Declarations
    var vSMA10 = new MAStudy(100"Close"MAStudy.SIMPLE);
    var 
    vLastAlert = -1;
    //}}EFSWizard_Declarations


    function preMain() {
       
    /**
        *  This function is called only once, before any of the bars are loaded.
        *  Place any study or EFS configuration commands here.
        */
    //{{EFSWizard_PreMain
        
    setPriceStudy(false);
        
    setStudyTitle("Price MA difference");
        
    setCursorLabelName("?"0);
        
    setDefaultBarStyle(PS_SOLID0);
        
    setDefaultBarFgColor(Color.red0);
        
    setDefaultBarThickness(10);
        
    setPlotType(PLOTTYPE_LINE0);
    //}}EFSWizard_PreMain

    }

    function 
    main() {
       
    /**
        *  The main() function is called once per bar on all previous bars, once per
        *  each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
        *  in your preMain(), it is also called on every tick.
        */

    //{{EFSWizard_Expressions
        //{{EFSWizard_Expression_1
        //}}EFSWizard_Expression_1
        
    //}}EFSWizard_Expressions


    //{{EFSWizard_Return
        
    return close() - vSMA10.getValue(MAStudy.MA);
    //}}EFSWizard_Return

    }

    function 
    postMain() {
       
    /**
        *  The postMain() function is called only once, when the EFS is no longer used for
        *  the current symbol (ie, symbol change, chart closing, or application shutdown).
        */
    }

    //{{EFSWizard_Actions
        //{{EFSWizard_Action_1
        
    function onAction1() {
            
    vLastAlert 1;
        }
        
    //}}EFSWizard_Action_1
        
    //}}EFSWizard_Actions 

  • #2
    Re: Add Parameter to EFS

    maninjapan
    You will not be able to do that using the Formula Wizard and you will need to use the EFS Editor
    That said you can accomplish that in one of two ways both of which are shown in this thread
    Alex


    Originally posted by maninjapan
    I have just created a very simple indicator showing the difference between the price and the MA. How can I make the MA period a parameter rather than a hard coded number (currently 10)?

    Thanks in advance!!


    PHP Code:
    //{{EFSWizard_Description
    //
    //    This formula was generated by the Alert Wizard
    //
    //}}EFSWizard_Description


    //{{EFSWizard_Declarations
    var vSMA10 = new MAStudy(100"Close"MAStudy.SIMPLE);
    var 
    vLastAlert = -1;
    //}}EFSWizard_Declarations


    function preMain() {
       
    /**
        *  This function is called only once, before any of the bars are loaded.
        *  Place any study or EFS configuration commands here.
        */
    //{{EFSWizard_PreMain
        
    setPriceStudy(false);
        
    setStudyTitle("Price MA difference");
        
    setCursorLabelName("?"0);
        
    setDefaultBarStyle(PS_SOLID0);
        
    setDefaultBarFgColor(Color.red0);
        
    setDefaultBarThickness(10);
        
    setPlotType(PLOTTYPE_LINE0);
    //}}EFSWizard_PreMain

    }

    function 
    main() {
       
    /**
        *  The main() function is called once per bar on all previous bars, once per
        *  each incoming completed bar, and if you don't have 'setComputeOnClose(true)'
        *  in your preMain(), it is also called on every tick.
        */

    //{{EFSWizard_Expressions
        //{{EFSWizard_Expression_1
        //}}EFSWizard_Expression_1
        
    //}}EFSWizard_Expressions


    //{{EFSWizard_Return
        
    return close() - vSMA10.getValue(MAStudy.MA);
    //}}EFSWizard_Return

    }

    function 
    postMain() {
       
    /**
        *  The postMain() function is called only once, when the EFS is no longer used for
        *  the current symbol (ie, symbol change, chart closing, or application shutdown).
        */
    }

    //{{EFSWizard_Actions
        //{{EFSWizard_Action_1
        
    function onAction1() {
            
    vLastAlert 1;
        }
        
    //}}EFSWizard_Action_1
        
    //}}EFSWizard_Actions 

    Comment


    • #3
      Alexis, thanks a lot. Exactly what I was after. Have come up with the following and it seems to work fine on a chart. However when I apply it to a WatchList it is showing a number that doesnt correspond with what I see on the chart (Chart is using the default setting).

      PHP Code:


      // var vSMA10 = new MAStudy(10, 0, "Close", MAStudy.SIMPLE);

      var vLastAlert = -1;



      function 
      preMain() {


          
      setPriceStudy(false);

          
      setStudyTitle("Close MA difference");

          
      setCursorLabelName("CMAdiff"0);

          
      setDefaultBarStyle(PS_SOLID0);

          
      setDefaultBarFgColor(Color.red0);

          
      setDefaultBarThickness(10);

          
      setPlotType(PLOTTYPE_LINE0);
          
           var 
      fp1 = new FunctionParameter("Length"FunctionParameter.NUMBER);

          
      fp1.setName("Length of MA");

          
      fp1.setLowerLimit(1);

          
      fp1.setUpperLimit(500);

          
      fp1.setDefault(200);

      }

      var 
      myAvg null;

      function 
      main(Length) {
          
          if(
      myAvg==nullmyAvg sma(Length);
          return 
      close() - myAvg.getValue(0);

      }

      function 
      postMain() {

      }

          function 
      onAction1() {

              
      vLastAlert 1;

          } 

      Comment


      • #4
        maninjapan
        A likely reason for the difference is that by default the Watch List will load 50 bars of data for all sessions which may be different than what you have in the Chart so you need to apply to the Watch List a Time Template that will load the same data [ie number of bars and session] as you have in the chart. See this article in the eSignal IKnowledgeBase for information on Time Templates
        Alex


        Originally posted by maninjapan
        Alexis, thanks a lot. Exactly what I was after. Have come up with the following and it seems to work fine on a chart. However when I apply it to a WatchList it is showing a number that doesnt correspond with what I see on the chart (Chart is using the default setting).

        PHP Code:


        // var vSMA10 = new MAStudy(10, 0, "Close", MAStudy.SIMPLE);

        var vLastAlert = -1;



        function 
        preMain() {


            
        setPriceStudy(false);

            
        setStudyTitle("Close MA difference");

            
        setCursorLabelName("CMAdiff"0);

            
        setDefaultBarStyle(PS_SOLID0);

            
        setDefaultBarFgColor(Color.red0);

            
        setDefaultBarThickness(10);

            
        setPlotType(PLOTTYPE_LINE0);
            
             var 
        fp1 = new FunctionParameter("Length"FunctionParameter.NUMBER);

            
        fp1.setName("Length of MA");

            
        fp1.setLowerLimit(1);

            
        fp1.setUpperLimit(500);

            
        fp1.setDefault(200);

        }

        var 
        myAvg null;

        function 
        main(Length) {
            
            if(
        myAvg==nullmyAvg sma(Length);
            return 
        close() - myAvg.getValue(0);

        }

        function 
        postMain() {

        }

            function 
        onAction1() {

                
        vLastAlert 1;

            } 

        Comment


        • #5
          Thanks again Alexis, I have been using the time templates and reviewed the link you put up. @I am not however able to find the time template application for the watch list. I tried right clicking on the watchlist but not able to view the time template option as I am with a chart.

          Comment


          • #6
            maninjapan
            That would suggest that you are running a version prior to 11.3 which is when the Time Templates were added to the Watch List
            Alex


            Originally posted by maninjapan
            Thanks again Alexis, I have been using the time templates and reviewed the link you put up. @I am not however able to find the time template application for the watch list. I tried right clicking on the watchlist but not able to view the time template option as I am with a chart.

            Comment


            • #7
              Alexis, All solved. Thank you very much for your help!!

              Comment


              • #8
                maninjapan
                You are welcome
                Alex


                Originally posted by maninjapan
                Alexis, All solved. Thank you very much for your help!!

                Comment

                Working...
                X