Announcement

Collapse
No announcement yet.

EFS for (H+L/2), w/ offset - SMA, w/ offset , then plot result

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

  • EFS for (H+L/2), w/ offset - SMA, w/ offset , then plot result

    Racking my head trying to figure out what I think is a simple EFS….perhaps it is, or maybe not.

    Want to plot the delta between a SMA and (H+L)/2. I have the SMA part down pat, but the OHLC material is confusing since most is daily or weekly.

    I get stuck in the formula wizard trying to define X, which is ((H+L)/2 offset by say -10), and then subtracting a SMA, offset by 10 as well, from X. then, of course, plot X on a histrograph.


    TIA for your help..

  • #2
    rayl542921
    (H+L)/2 is the same as the Basis line of the Donchian channel for 1 period.
    Alex

    Comment


    • #3
      Originally posted by Alexis C. Montenegro
      rayl542921
      (H+L)/2 is the same as the Basis line of the Donchian channel for 1 period.
      Alex
      Thanks Alex.

      So in the "returned data points" section of wizard the formula should read:

      vSMA27 - VDochian?

      Problems here for me is the subtraction function, when i hit "edit" to select VSMA27 and enter "-" for subtraction, and then hit "edit" again to place VDochin - the vSMA and "-" go away.

      My question then is how do i subtract one study from another and then plot the difference.

      TIA

      Comment


      • #4
        rayl542921
        Yes, that is one of the limitations of the Formula Wizard at this time (changes are in the works BTW).
        The easiest workaround is to edit the script with the Editor and create the equation for the Returned Data Points in there.
        Alex

        Comment


        • #5
          Originally posted by rayl542921
          Thanks Alex.

          So in the "returned data points" section of wizard the formula should read:

          vSMA27 - VDochian?

          Problems here for me is the subtraction function, when i hit "edit" to select VSMA27 and enter "-" for subtraction, and then hit "edit" again to place VDochin - the vSMA and "-" go away.

          My question then is how do i subtract one study from another and then plot the difference.

          TIA
          Cool. here is what i have in editor, if you could just guide me through the formula is should be home free.

          //{{EFSWizard_Description
          //
          // This formula was generated by the Alert Wizard
          //
          //}}EFSWizard_Description 7532


          //{{EFSWizard_Declarations

          var vDonchian = new DonchianStudy(1, -14);
          var vSMA27 = new MAStudy(27, -14, "Close", MAStudy.SIMPLE);
          var vLastAlert = -1;

          //}}EFSWizard_Declarations 16194


          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("IMA");
          setCursorLabelName("?", 0);
          setDefaultBarStyle(PS_SOLID, 0);
          setDefaultBarFgColor(Color.red, 0);
          setDefaultBarThickness(1, 0);
          setPlotType(PLOTTYPE_HISTOGRAM, 0);
          //}}EFSWizard_PreMain 29399

          }

          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 0

          //}}EFSWizard_Expressions 9063


          //{{EFSWizard_Return
          return (vDonchian) - (vSMA27)
          //}}EFSWizard_Return 4313

          }

          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() {
          setBarFgColor(Color.RGB(155,0,0));
          vLastAlert = 1;
          }
          //}}EFSWizard_Action_1 10981

          //}}EFSWizard_Actions 20204




          Alex, is the formula correct? i get a ) annd Q error when i run this.

          TIA

          Comment


          • #6
            You need to replace the following section

            //{{EFSWizard_Return
            return (vDonchian) - (vSMA27)
            //}}EFSWizard_Return 4313

            with

            //{{EFSWizard_Return
            return vDonchian.getValue(DonchianStudy.BASIS)-vSMA27.getValue(MAStudy.MA);
            //}}EFSWizard_Return 4313

            I think that should do it. If not let me know
            Alex

            Comment


            • #7
              PERFECT! Thank you so very much!

              let mne know if you ever make it to CA, beers on me!

              Thxs again!

              Comment


              • #8
                Cloudy wheat is my preferred kind, thank you.
                Alex

                Comment


                • #9
                  Originally posted by Alexis C. Montenegro
                  Cloudy wheat is my preferred kind, thank you.
                  Alex
                  Cloudy wheat it is! LOL!

                  this works perfect so long as i don't offset the SMA, if i do, then scaling falls apart becasue the SMA is offset, but Donchian is not. (I don't want to offest doncian, just the SMA)

                  the delta (SMA less Donchian) figures are correct in Cursor lable, but the plotting blows up by the number of offset bars - so like if i offset by 10, i get lots of dots (assuming they're very small bars) across the histrogram (w/correct figures) and 10 very large bars on the left side.

                  I've tried a few condtional things on formula wizard without any luck. i'm sure i'm just missing some "stop plotting instruction" until new SMA number is ready, just can't figure out the code.

                  Here is what I have:

                  //{{EFSWizard_Description
                  //
                  // This formula was generated by the Alert Wizard
                  //
                  //}}EFSWizard_Description 7532


                  //{{EFSWizard_Declarations

                  var vSMA27 = new MAStudy(27, -14, "Close", MAStudy.SIMPLE);
                  var vDonchian = new DonchianStudy(1, 0);
                  var vLastAlert = -1;

                  //}}EFSWizard_Declarations 15636


                  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("IVM");
                  setCursorLabelName("IMV", 0);
                  setDefaultBarStyle(PS_SOLID, 0);
                  setDefaultBarFgColor(Color.red, 0);
                  setDefaultBarThickness(1, 0);
                  setPlotType(PLOTTYPE_HISTOGRAM, 0);
                  //}}EFSWizard_PreMain 28595

                  }

                  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
                  if (
                  vSMA27.getValue(MAStudy.MA) > 0
                  ) onAction1();
                  //}}EFSWizard_Expression_1 8204

                  //}}EFSWizard_Expressions 18787


                  //{{EFSWizard_Return
                  return vDonchian.getValue(DonchianStudy.BASIS) -vSMA27.getValue(MAStudy.MA);
                  //}}EFSWizard_Return 5458

                  }

                  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() {
                  setBarFgColor(Color.RGB(155,0,0));
                  vLastAlert = 1;
                  }
                  //}}EFSWizard_Action_1 10981

                  //}}EFSWizard_Actions 20204


                  TIA. I apprecaite the assistance.

                  Comment


                  • #10
                    rayl542921
                    The spike in the last nn bars (where nn is the offset applied to the SMA) is due to the fact that you are shifting the SMA backwards hence the current value is 0.
                    To see this go to Basic Studies->Moving Average and add a simple MA to the chart with a negative offset. You will see that there is no plot for the current bar.
                    Are you sure that your intention is to shift it backwards and not forward? If the latter is what you want then the offset needs to be a positive number.
                    Alex

                    Comment


                    • #11
                      Originally posted by Alexis C. Montenegro
                      rayl542921
                      The spike in the last nn bars (where nn is the offset applied to the SMA) is due to the fact that you are shifting the SMA backwards hence the current value is 0.
                      To see this go to Basic Studies->Moving Average and add a simple MA to the chart with a negative offset. You will see that there is no plot for the current bar.
                      Are you sure that your intention is to shift it backwards and not forward? Ifd the latter is what you want then the offset needs to be a positive number.
                      Alex
                      Yes. Want to shift backward. looking for automated "Inverse Moving Average" (IMA) - which was created by John Hurst, legednary cycle guy.

                      The current EFS works fine, so long as i don't ofset.

                      So, i think, i need to include a line of code that will stop the histogram if the SMA = 0. i understand that this indicator will be lagging the currect price action, that's okay/ IMA is just used to help ID cycles. TIA again.

                      Comment


                      • #12
                        rayl542921
                        You may want to try the following revision. It should not plot the spikes when the vSMA27 is 0 and should update historical bars as new bars get added.
                        Alex


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


                        //{{EFSWizard_Declarations

                        var vSMA27 = new MAStudy(27, -14"Close"MAStudy.SIMPLE);
                        var 
                        vDonchian = new DonchianStudy(10);
                        var 
                        vLastAlert = -1;

                        //}}EFSWizard_Declarations 15636


                        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("IVM");
                        setCursorLabelName("IMV"0);
                        setDefaultBarStyle(PS_SOLID0);
                        setDefaultBarFgColor(Color.red0);
                        setDefaultBarThickness(10);
                        setPlotType(PLOTTYPE_HISTOGRAM0);
                        //}}EFSWizard_PreMain 28595

                        }

                        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
                        if (
                        vSMA27.getValue(MAStudy.MA) > 0
                        onAction1();
                        //}}EFSWizard_Expression_1 8204

                        //}}EFSWizard_Expressions 18787

                         
                        if(getBarState()==BARSTATE_NEWBAR){
                         var 
                        vDiff vDonchian.getValue(DonchianStudy.BASIS,-15) -vSMA27.getValue(MAStudy.MA,-15);
                         
                        setBar(Bar.Value,-14,vDiff);
                         
                        setBar(Bar.FgColor,-14,Color.RGB(155,0,0));
                         }
                         if(
                        vDonchian.getValue(DonchianStudy.BASIS)==null||vSMA27.getValue(MAStudy.MA)==null)
                         return;

                        //{{EFSWizard_Return
                        return vDonchian.getValue(DonchianStudy.BASIS) -vSMA27.getValue(MAStudy.MA);
                        //}}EFSWizard_Return 5458

                        }

                        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() {
                        setBarFgColor(Color.RGB(155,0,0));
                        vLastAlert 1;
                        }
                        //}}EFSWizard_Action_1 10981

                        //}}EFSWizard_Actions 20204 

                        Comment


                        • #13
                          Too cool! very nice, thanks so much again! really apprecaite the support and fast response, thank you!

                          Comment


                          • #14
                            mutliple var inputs

                            Hello,

                            looking for help with var inputs. second efs below Alexis helped with (thanks again!), need to add input option if possible. would like to be able to define length and offset on the MAs - don't really need "type", SMA will do - and an option to set NEWBAR offset to match longest MA lenght plus 1 as in first EFS below.

                            TIA!



                            //{{EFSWizard_Description
                            //
                            // This formula was generated by the Alert Wizard
                            //
                            //}}EFSWizard_Description 7532


                            //{{EFSWizard_Declarations

                            var vSMA14 = new MAStudy(14, -7, "Close", MAStudy.SIMPLE);
                            var vSMA27 = new MAStudy(27, -14, "Close", MAStudy.SIMPLE);
                            var vLastAlert = -1;

                            //}}EFSWizard_Declarations 15636


                            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("Wave");
                            setCursorLabelName("Wave", 0);
                            setDefaultBarStyle(PS_SOLID, 0);
                            setDefaultBarFgColor(Color.red, 0);
                            setDefaultBarThickness(2, 0);
                            setPlotType(PLOTTYPE_LINE, 0);
                            //}}EFSWizard_PreMain 28595

                            }

                            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
                            if (
                            vSMA27.getValue(MAStudy.MA) > 0
                            ) onAction1();
                            //}}EFSWizard_Expression_1 8204

                            //}}EFSWizard_Expressions 18787

                            if(getBarState()==BARSTATE_NEWBAR){
                            var vDiff = vSMA14.getValue(MAStudy.MA,-15) - vSMA27.getValue(MAStudy.MA,-15);
                            setBar(Bar.Value,-28,vDiff);
                            setBar(Bar.FgColor,-28,Color.RGB(155,0,0));
                            }
                            if(vSMA14.getValue(MAStudy.MA)==null||vSMA27.getVa lue(MAStudy.MA)==null)
                            return;

                            //{{EFSWizard_Return
                            return vSMA14.getValue(MAStudy.MA) - vSMA27.getValue(MAStudy.MA);
                            //}}EFSWizard_Return 5458

                            }

                            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() {
                            setBarFgColor(Color.RGB(155,0,0));
                            vLastAlert = 1;
                            }
                            //}}EFSWizard_Action_1 10981

                            //}}EFSWizard_Actions 20204


                            /************************************************** *******
                            Alexis C. Montenegro © July 2003
                            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.
                            ************************************************** ********/

                            //my intent was to define vMA as the lesser MA

                            var vMA = null;
                            var vMA_02 = null;// 2 MAs need to be defined, then smaller MA subtraced from larger

                            function preMain() {
                            setPriceStudy(true);
                            setStudyTitle("Wave");
                            setCursorLabelName("Wave", 0);
                            setDefaultBarFgColor(Color.blue, 0);
                            setDefaultBarThickness(1,0);//delta of MAs to be plotted on single line

                            var fp1 = new FunctionParameter("Length", FunctionParameter.NUMBER);
                            fp1.setLowerLimit(1);
                            fp1.setDefault(10); //Edit this value to set a new default

                            var fp2 = new FunctionParameter("Offset", FunctionParameter.NUMBER);
                            fp2.setDefault(0); //Edit this value to set a new default

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

                            //Here is where i get confused, need input for VMA_02, and var fp3 does not make sense
                            //how is it best defined? var_02? if so, that makes 2 "fp1s" and "fp2s"


                            var_02 fp1 = new FunctionParameter("Length", FunctionParameter.NUMBER);
                            fp1.setLowerLimit(1);
                            fp1.setDefault(10); //Edit this value to set a new default

                            var_02 fp2 = new FunctionParameter("Offset", FunctionParameter.NUMBER);
                            fp2.setDefault(0); //Edit this value to set a new default


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

                            }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
                            if (
                            vMA_02.getValue(MAStudy.MA) > 0
                            ) onAction1();
                            //}}EFSWizard_Expression_1 8204

                            //}}EFSWizard_Expressions 18787

                            if(getBarState()==BARSTATE_NEWBAR){
                            var vDiff = vMA.getValue(MAStudy.MA,null) - vMA_02.getValue(MAStudy.MA,null);
                            setBar(Bar.Value,null,vDiff);
                            setBar(Bar.FgColor,null,Color.RGB(155,0,0));
                            }
                            if(vMA.getValue(MAStudy.MA)==null||vMA_02.getValue (MAStudy.MA)==null)


                            //Help! need the offset+1 number input as well. for example in "vMA.getValue(MAStudy.MA,-15)"
                            // from another EFS has -15 to stop printing bars. if the latter can be automated to add 1 to
                            //vMA_02 that would be cool, if not, i need the input option. i put the NULLS in there.
                            return;

                            //{{EFSWizard_Return
                            return vMA_02.getValue(MAStudy.MA) - vMA.getValue(MAStudy.MA);
                            //}}EFSWizard_Return 5458

                            }

                            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() {
                            setBarFgColor(Color.RGB(155,0,0));
                            vLastAlert = 1;
                            }
                            //}}EFSWizard_Action_1 10981

                            //}}EFSWizard_Actions 20204

                            Comment


                            • #15
                              rayl542921
                              Not quite sure as to what you are trying to achieve but it would appear that you want to calculate two MAs.
                              If that is the case may I suggest that you download basicMAx2.efs which is avaialble here.
                              Once you have downloaded it then it may be simpler to adapt that to your needs as all the parameters for both MAs can be modified through Edit Studies.
                              Alex

                              Comment

                              Working...
                              X