Announcement

Collapse
No announcement yet.

amvwap.efs

Collapse
This topic is closed.
X
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • amvwap.efs

    Hi Alex,

    Finally someone created a nice vwap plot. Thank you very much.

    Suggestion:

    Would you be able to make it plot the 1st and 2nd deviations? This would create 4 more lines, two above and two below the vwap for a total of 5 lilnes, acting as supp/resist points.

    Thanks greatly,

    Nereus

  • #2
    Searching for amvwap.efs

    Hello - I'm wondering if amvwap.efs is posted somewhere for download. Still haven't quite gotten the hang of searching the bulletin board for specific study names...

    Thanks,
    Steve

    Comment


    • #3
      Steve
      See this post for information on the VWAP study.
      Alex

      Comment


      • #4
        Thanks!

        Alex - don't know if this is overuse of a post, but thanks! Steve

        Comment


        • #5
          amvwap.efs with std. dev. lines

          Hello Alex and Nereus - any further thoughts on adding the std. dev. lines? the amvwap. efs is helpful; just wondering if the std. dev. lines would enhance it... thanks - Steve

          Comment


          • #6
            Nereus, Steve
            If you are interested in adding the standard deviations to the VWAP study then you can easily do this by using the dsStdDev() function contained in the dsFunctions.efsLib library which is already installed on your computers.
            Here is how you would need to modify the formula
            You first need to add the addLibrary() call to load the function library in the efs. Insert the following line just below the existing addLibrary() call for the amStudies.efsLib

            var dsLib = addLibrary("dsFunctions.efsLib");

            Then add a global variable called for example xStdDev and set it to null.
            Once you have done that you can add the function inside the bInit statement immediately following the line in which the amVWAP() is called.

            xStdDev = dsLib.dsStdDev(length,xVWAP);

            where length is the period over which you wish to calculate the standard deviation.
            At that point after the bInit statement create local variables to retrieve the VWAP and its standard deviation values and run a null check on both

            var nVWAP = xVWAP.getValue(0);
            var nStdDev = xStdDev.getValue(0);
            if(nVWAP==null || nStdDev == null) return;


            Having done this simply replace the return statement with one that contains the plots you want. For example

            return new Array (nVWAP+(2*nStdDev), nVWAP, nVWAP-(nStdDev));

            will return the VWAP with a 2 standard deviation plot above and a 1 standard deviation plot below.
            Add whatever other plots you may want to the return statement and adjust preMain to include the statements required to define these plots (plot type, color, thickness, etc)
            Alex

            Originally posted by Nereus
            Hi Alex,

            Finally someone created a nice vwap plot. Thank you very much.

            Suggestion:

            Would you be able to make it plot the 1st and 2nd deviations? This would create 4 more lines, two above and two below the vwap for a total of 5 lilnes, acting as supp/resist points.

            Thanks greatly,

            Nereus

            Comment


            • #7
              Thanks Alex... but I am a total idiot when it comes to coding. Wish I had the knowledge and/or time to learn it.

              I can cut and paste but I would not know where specifically to paste it. Any further help from you would be greatly appreciated.
              Sorry to be a such a complete ignoramus.

              Cheers

              PS: Steve.. if you are familiar with efs code.. and are able to create this.. would you mind sharing? Thanks

              Comment


              • #8
                OK.. Alex... I have found some help with this task, however, in this statement:

                xStdDev = dsLib.dsStdDev(length,xVWAP);

                where length is the period over which you wish to calculate the standard deviation... etc.

                Is there a command (code) that specifies that it should be calc'd from the market open? Supposedly this is what is needed for these to work properly. Here is the calx that was presented to me by a fellow trader.

                quote:
                "STandard Deviations computed from (Price-Vwap)^2 summed over total price data for the day. It's the standard formula for computing Standard deviations."

                Thanks

                Comment


                • #9
                  amvwap.efs with std. dev. lines

                  Nereus - I too am learning .efs slowly.. was going to take a crack at it but you beat me to it. Alex - thanks for the instructions. Looking forward to the finished piece. Steve

                  Comment


                  • #10
                    Nereus and Steve
                    If you need to reset the Standard Deviation at the start of every day then you need to implement a different solution
                    Add the following Standard Deviation function to the script.



                    Then declare a global variable (ie outside of function main) calling it vCounter and set it initially to 0 ie
                    var vCounter = 0;
                    This variable will be used to define the length of the Standard Deviation as the day progresses.
                    Then inside main immediately after the bInit statement you will first retrieve the VWAP series and declare the nStdDev variable both of which will be used later in the script



                    Since you need to reset vCounter at every new day you have to define when that event occurrs



                    Then you need to increment vCounter by 1 at every new bar.



                    At this point you are ready to set the conditions to calculate the Standard Deviation using the function shown in the first image. You need at least three data points before you can do that so set the conditions as shown below.



                    Once you have done that you will use nVWAP and nStdDev as the elements of the return statement ie
                    return new Array (nVWAP+(2*nStdDev), nVWAP, nVWAP-(2*nStdDev))
                    Add the necessary statements in preMain to define the names, colors, plot types etc.
                    If you want to plot additional lines at different standard deviations then add them to the return array eg
                    return new Array (nVWAP+(3*nStdDev), nVWAP+(2*nStdDev), nVWAP, nVWAP-(2*nStdDev), etc)
                    and again adjust your preMain statements accordingly
                    Alex

                    Comment


                    • #11
                      Originally posted by Alexis C. Montenegro
                      Nereus and Steve
                      If you need to reset the Standard Deviation at the start of every day then you need to implement a different solution
                      Add the following Standard Deviation function to the script.
                      Hi Alex

                      Thanks for your work on this. Its well appreciated. I have tried to copy the new code you put up in your last message, but keep getting syntax errors each time i run it. Probably because its difficult to accurately copy some else's coding. Also it was in graphic form , so i couldnt copy and paste. To get over this, would you instead place the full .efs script here in text format.

                      Many thanks
                      Les

                      Comment


                      • #12
                        Les
                        Post the code that is returning syntax errors and I or someone else can guide you in fixing it
                        Alex

                        Comment


                        • #13
                          Originally posted by Alexis C. Montenegro
                          Les
                          Post the code that is returning syntax errors and I or someone else can guide you in fixing it
                          Alex
                          Here it is:

                          PHP Code:
                          /*********************************************************
                          Alexis C. Montenegro © July 2005                          
                          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.                      
                          **********************************************************/

                          //NOTE:                                                                          
                          //This efs requires amStudies.efsLib in the FunctionLibrary folder.              
                          //If you do not have this file you can download it at the link below.            
                          //http://share.esignal.com/groupcontents.jsp?folder=Formulas-Libraries&groupid=10

                          var fpArray = new Array();

                          function 
                          preMain() {

                              
                          setPriceStudy(true);
                              
                          setStudyTitle("VWAP");
                              
                          setCursorLabelName("VWAP",0);
                              
                          setDefaultBarFgColor(Color.green,0);
                              
                          setPlotType(PLOTTYPE_SQUAREWAVE,0);
                              
                          setDefaultBarThickness(2,0);
                              
                          askForInput();

                              var 
                          x=0;
                              
                          fpArray[x] = new FunctionParameter("Symbol"FunctionParameter.STRING);
                              
                          with(fpArray[x++]){
                                  
                          setDefault();
                              }
                              
                          fpArray[x] = new FunctionParameter("Interval"FunctionParameter.STRING);
                              
                          with(fpArray[x++]){
                                  
                          setDefault();
                              }
                              
                          fpArray[x] = new FunctionParameter("Params"FunctionParameter.BOOLEAN);
                              
                          with(fpArray[x++]){
                                  
                          setName("Show Parameters");
                                  
                          setDefault(false);
                              }
                          }

                          var 
                          amLib addLibrary("amStudies.efsLib");
                          var 
                          dsLib addLibrary("dsFunctions.efsLib");
                          var 
                          xStdDev null
                          var bInit false
                          var xVWAP null;

                          function 
                          main(Symbol,Interval,Params) {

                              if(
                          bInit==false){
                                  
                          withamLib ) {
                                  if(
                          Symbol == nullSymbol getSymbol();
                                  if(
                          Interval == nullInterval getInterval();
                                  var 
                          vSymbol Symbol+","+Interval;
                                  
                          // xVWAP = amVWAP(sym(vSymbol));
                                  
                          xStdDev dsLib.dsStdDev(20,xVWAP);
                                  
                          setShowTitleParameters(eval(Params));
                                  
                          bInit=true;
                                  }
                              }
                          var 
                          vCounter 0;

                          function 
                          StdDev(lengthprice) {
                              if (
                          getCurrentBarCount()<length){
                              return;
                              }
                              var 
                          sumX 0;
                              var 
                          sumY 0;
                              for (var 
                          i=0i<lengthi++) {
                                  
                          sumX += price.getValue(-i);
                                  
                          sumY += (price.getValue(-i)*price.getValue(-i));
                              }
                              var 
                          meanX = (sumX/length);
                              var 
                          stddev Math.sqrt((sumY/length)-(meanX*meanX));
                              return 
                          stddev;
                          }
                              
                              var 
                          nVWAP getSeries(xVWAP); //retrieve the VWAP series
                              
                          var nStdDev 0;
                              
                              if(
                          getDay(0)!=getDay(-1)&&getBarState()==BARSTATE_NEWBAR){ //if a new day and new bar
                                  
                          vCounter=0//se vCounter to 0
                              
                          }
                              if(
                          getBarState()==BARSTATE_NEWBAR){ //if a new bar
                                      
                          vCounter++; //increment vCounter by 1
                              
                          }
                              
                              if(
                          vCounter>3){ //if Counter > 3
                                  
                          nStdDev StdDev(vCounter,nVWAP); //compute the SD
                              
                          }else{ //else if < 3
                                  
                          nStdDev null//set SD to null
                              
                          }
                              
                              var 
                          nVWAP xVWAP.getValue(0);
                              var 
                          nStdDev xStdDev.getValue(0);
                              if(
                          nVWAP==null || nStdDev == null) return;
                              
                              
                          setBarFgColor(Color.purple,0);
                              
                          setBarThickness(2,0);
                              return new Array (
                          nVWAP+(2*nStdDev), nVWAPnVWAP-(nStdDev));
                              } 
                          Les

                          Comment


                          • #14
                            Hello Les,

                            The vCounter variable and the StdDev() function need to be moved outside of the main() function. Then in the bInit code block at the top of main() you need to uncomment the line of code that initializes the xVWAP series. This series is being used later in the formula, which is causing a formula error. To uncomment that line of code, remove the two forward slashes at the front of the line (i.e. //). After making these changes you should be good to go.
                            Jason K.
                            Project Manager
                            eSignal - an Interactive Data company

                            EFS KnowledgeBase
                            JavaScript for EFS Video Series
                            EFS Beginner Tutorial Series
                            EFS Glossary
                            Custom EFS Development Policy

                            New User Orientation

                            Comment


                            • #15
                              Originally posted by JasonK
                              Hello Les,

                              The vCounter variable and the StdDev() function need to be moved outside of the main() function. Then in the bInit code block at the top of main() you need to uncomment the line of code that initializes the xVWAP series. This series is being used later in the formula, which is causing a formula error. To uncomment that line of code, remove the two forward slashes at the front of the line (i.e. //). After making these changes you should be good to go.
                              Jason

                              Thanks. Have followed your suggestions and now have this study running. However visually it doesnt look right to me. What i mean is:



                              The thicker jagged line is the vwap, and if so the Std Deviation lines should be above and below it, which they clearly are not. Here's the code again:

                              var fpArray = new Array();

                              function preMain() {

                              setPriceStudy(true);
                              setStudyTitle("VWAP");
                              setCursorLabelName("VWAP",0);
                              setDefaultBarFgColor(Color.green,0);
                              setPlotType(PLOTTYPE_SQUAREWAVE,0);
                              setDefaultBarThickness(2,0);
                              askForInput();

                              var x=0;
                              fpArray[x] = new FunctionParameter("Symbol", FunctionParameter.STRING);
                              with(fpArray[x++]){
                              setDefault();
                              }
                              fpArray[x] = new FunctionParameter("Interval", FunctionParameter.STRING);
                              with(fpArray[x++]){
                              setDefault();
                              }
                              fpArray[x] = new FunctionParameter("Params", FunctionParameter.BOOLEAN);
                              with(fpArray[x++]){
                              setName("Show Parameters");
                              setDefault(false);
                              }
                              }

                              var amLib = addLibrary("amStudies.efsLib");
                              var dsLib = addLibrary("dsFunctions.efsLib");
                              var xStdDev = null
                              var bInit = false
                              var vCounter = 0
                              var xVWAP = null;

                              function StdDev(length, price) {
                              if (getCurrentBarCount()<length){
                              return;
                              }
                              var sumX = 0;
                              var sumY = 0;
                              for (var i=0; i<length; i++) {
                              sumX += price.getValue(-i);
                              sumY += (price.getValue(-i)*price.getValue(-i));
                              }
                              var meanX = (sumX/length);
                              var stddev = Math.sqrt((sumY/length)-(meanX*meanX));
                              return stddev;
                              }

                              function main(Symbol,Interval,Params) {

                              if(bInit==false){
                              with( amLib ) {
                              if(Symbol == null) Symbol = getSymbol();
                              if(Interval == null) Interval = getInterval();
                              var vSymbol = Symbol+","+Interval;
                              xVWAP = amVWAP(sym(vSymbol));
                              xStdDev = dsLib.dsStdDev(20,xVWAP);
                              setShowTitleParameters(eval(Params));
                              bInit=true;
                              }
                              }

                              var nVWAP = getSeries(xVWAP); //retrieve the VWAP series
                              var nStdDev = 0;

                              if(getDay(0)!=getDay(-1)&&getBarState()==BARSTATE_NEWBAR){ //if a new day and new bar
                              vCounter=0; //se vCounter to 0
                              }
                              if(getBarState()==BARSTATE_NEWBAR){ //if a new bar
                              vCounter++; //increment vCounter by 1
                              }

                              if(vCounter>3){ //if Counter > 3
                              nStdDev = StdDev(vCounter,nVWAP); //compute the SD
                              }else{ //else if < 3
                              nStdDev = null; //set SD to null
                              }

                              var nVWAP = xVWAP.getValue(0);
                              var nStdDev = xStdDev.getValue(0);
                              if(nVWAP==null || nStdDev == null) return;

                              return new Array (nVWAP+(2*nStdDev), nVWAP, nVWAP-(2*nStdDev));
                              }
                              Les

                              Comment

                              Working...
                              X