Announcement

Collapse
No announcement yet.

amvwap.efs

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

  • #16
    FWIW, the end effect we are looking for with the vwap and std deviations is shown in the pic below.

    Thanks
    Attached Files

    Comment


    • #17
      Hello Les,

      The bold green line is actually the +2 standard deviation line. The second (or middle) green line is the vwap line. The reason you are confused is because you have yet to update the preMain settings to properly label and format the three lines. Also the jagged affect of the top line is due to the square wave plot type that is currently being applied. For more specifics on the available preMain settings, please see the preMain Functions folder in the EFS2 Function Reference in the EFS Knowledgebase (see link at bottom of this post).
      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


      • #18
        Originally posted by JasonK
        Hello Les,

        The bold green line is actually the +2 standard deviation line. The second (or middle) green line is the vwap line. The reason you are confused is because you have yet to update the preMain settings to properly label and format the three lines. Also the jagged affect of the top line is due to the square wave plot type that is currently being applied. For more specifics on the available preMain settings, please see the preMain Functions folder in the EFS2 Function Reference in the EFS Knowledgebase (see link at bottom of this post).
        Hi Jason

        Thanks, thats worked well, but its highlighted another problem: In main() there's the following line:

        xStdDev = dsLib.dsStdDev(20,xVWAP);

        That sets a 20-day period for the calculation of the SD, however the whole pupose of altering the script with the latest pieces of code was to get the SD calculated afresh from each market open. That line is forcing a 20-day period. I tried removing it, but then got a script error, so could u tell me what to do with that one? If you look at my last post - the chart graphic there is updated and will show what i mean

        Thanks

        Les
        Les

        Comment


        • #19
          Les

          Thanks, thats worked well, but its highlighted another problem: In main() there's the following line:

          xStdDev = dsLib.dsStdDev(20,xVWAP);
          That line was part of the first solution I suggested and should be deleted.
          The error you get though is caused by this line
          var nStdDev = xStdDev.getValue(0);
          which should also be deleted. Once you have done that remove
          || nStdDev == null
          from the following line of code
          if(nVWAP==null || nStdDev == null) return;
          Lastly to complete cleaning up residual code left over from the first solution you should also remove the following two lines
          var dsLib = addLibrary("dsFunctions.efsLib");
          var xStdDev = null

          which are not required
          Alex

          Comment


          • #20
            Originally posted by Alexis C. Montenegro
            Les
            That line was part of the first solution I suggested and should be deleted. The error you get is caused by this line
            var nStdDev = xStdDev.getValue(0);
            which should also be deleted. Once you have done that remove
            || nStdDev == null
            from the following line of code
            if(nVWAP==null || nStdDev == null) return;
            Lastly to complete cleaning up residual code left over from the first solution you should also remove the following two lines
            var dsLib = addLibrary("dsFunctions.efsLib");
            var xStdDev = null

            which are not required
            Alex
            Alex

            I did as you said, and then got another syntax error regarding line 77, viz:

            xStdDev = dsLib.dsStdDev(20,xVWAP);

            I commented this out, and now seems ok, but could you confirm this as well. I updated the chart graphic posted below, which reflects the change.

            Thanks

            Les
            Les

            Comment


            • #21
              Les
              That is the line you asked about in your prior message (see quote below) to which I replied saying it should be deleted
              Alex

              Originally posted by Les Carlin
              Hi Jason

              Thanks, thats worked well, but its highlighted another problem: In main() there's the following line:

              xStdDev = dsLib.dsStdDev(20,xVWAP);

              Comment


              • #22
                Originally posted by Alexis C. Montenegro
                Les
                That is the line you asked about in your prior message (see quote below) to which I replied saying it should be deleted
                Alex
                Oops yes, quite right. Many thanks for your and Jason's efforts with this one. I suggest, if you've not done so already that the original VWAP study and this VWAP study with SD's, is made available to others. Perhaps on this board under the Volume section.
                Les

                Comment


                • #23
                  Posting amvwap.efs with std. dev.

                  Les
                  I would love a copy of the amvwap.efs w/std. dev. lines if it could be posted somewhere.

                  To contribute to the .efs library, here is the code for a small .efs I had programed called X Day Hi/Lo. It plots any number of previous day am and/or pm hi/lo's. The am/pm cutoff times are user controlled, and colors and line widths are customizable. If someone could post it in an appropriate folder I would be appreciative. Thanks. Happy Holidays! Steve


                  X Day Hi/Lo

                  01/30/2005 - Initial Release
                  1.0.0

                  ================================================== ===================
                  Project Description:

                  Gathers the high/low values from the last "x" days and overlays
                  those values as lines in the current day. Only works on intraday
                  charts.

                  Dislaimer: For educational purposes only! Obviously, no guarantees
                  whatsoever and use at your own risk.

                  ************************************************** ********************/


                  //External Variables
                  var grID = 0;
                  var nBarCounter = 0;
                  var nDays = 0;
                  var nOffset = 0;
                  var nThick = 0;
                  var nTime = 0;
                  var nDisplay = 0;
                  var aData = null;
                  var vSymbol = null;
                  var aFPArray = new Array();
                  var bDone = false;
                  var bDrawn = false;
                  var bInitialized = false;


                  //== PreMain function required by eSignal to set things up
                  function preMain() {
                  var x;

                  setPriceStudy(true);
                  setStudyTitle("X-Day H/L");
                  setShowCursorLabel(false);
                  setShowTitleParameters( false );

                  //unrem this if you don't want the labels in cursor window
                  //setShowCursorLabel(false);

                  //unrem this if you don't want the study to update on every tick
                  //setComputeOnClose();
                  grID = 0;

                  //initialize formula parameters
                  x=0;
                  aFPArray[x] = new FunctionParameter( "fDays", FunctionParameter.NUMBER);
                  with( aFPArray[x] ) {
                  setName( "# of Days" );
                  setLowerLimit( 1 );
                  setUpperLimit( 10 );
                  setDefault( 1 );
                  }
                  x++;
                  aFPArray[x] = new FunctionParameter( "fTime", FunctionParameter.STRING);
                  with( aFPArray[x] ) {
                  setName( "Intraday Cutoff Time" );
                  setDefault( "13:00" );
                  }
                  x++;
                  aFPArray[x] = new FunctionParameter( "fDisplay", FunctionParameter.STRING);
                  with( aFPArray[x] ) {
                  setName( "Display Type" );
                  addOption( "Both" );
                  addOption( "AM-Only" );
                  addOption( "PM-Only" );
                  setDefault( "Both" );
                  }
                  x++;
                  aFPArray[x] = new FunctionParameter( "fHighColor", FunctionParameter.COLOR);
                  with( aFPArray[x] ) {
                  setName( "Highs Color" );
                  setDefault( Color.green );
                  }
                  x++;
                  aFPArray[x] = new FunctionParameter( "fLowColor", FunctionParameter.COLOR);
                  with( aFPArray[x] ) {
                  setName( "Lows Color" );
                  setDefault( Color.red );
                  }
                  x++;
                  aFPArray[x] = new FunctionParameter( "fThick", FunctionParameter.NUMBER);
                  with( aFPArray[x] ) {
                  setName( "Line Thickness" );
                  setLowerLimit( 1 );
                  setUpperLimit( 10 );
                  setDefault( 2 );
                  }

                  }

                  //== Main processing function
                  function main( fDays, fTime, fDisplay, fHighColor, fLowColor, fThick ) {
                  var x;

                  //script is initializing
                  if ( getBarState() == BARSTATE_ALLBARS ) {
                  return null;
                  }

                  if ( !isIntraday() ) return;

                  if ( bInitialized == false ) {


                  nDays = Math.round( fDays );
                  nThick = Math.round( fThick );
                  nTime = TimeToMinutes( fTime );
                  nDisplay = (fDisplay=="Both") ? 0 : (fDisplay=="AM-Only") ? -1 : 1;

                  aData = new Array();

                  bInitialized = true;
                  }

                  //called on each new bar
                  if ( getBarState() == BARSTATE_NEWBAR ) {

                  if ( getDay(0) != getDay(-1) ) {
                  nOffset = nBarCounter;
                  }

                  bDrawn = false;
                  nBarCounter++;

                  }

                  if ( isLastBarOnChart() && bDone==false ) {
                  bDone = true;
                  //run the scan
                  scan( nDays, nTime, aData );

                  }

                  if ( isLastBarOnChart() && bDrawn==false && bDone==true ) {
                  bDrawn = true;
                  x=0;
                  clearLines();
                  clearText();
                  nX = nBarCounter-nOffset-1;
                  while( x<nDays ) {
                  if ( aData[x] != null ) {
                  with ( aData[x] ) {

                  if ( nDisplay <= 0 ) {
                  drawLineRelative( -nX, AMH, 0, AMH, PS_SOLID, nThick, fHighColor, "H1"+x );
                  drawTextRelative( 1, AMH, "AM"+(x+1), fHighColor, null, Text.BOLD | Text.ONTOP | Text.VCENTER, null, 10, "A1"+x );
                  }
                  if ( nDisplay >= 0 ) {
                  drawLineRelative( -nX, PMH, 0, PMH, PS_SOLID, nThick, fHighColor, "H2"+x );
                  drawTextRelative( 1, PMH, "PM"+(x+1), fHighColor, null, Text.BOLD | Text.ONTOP | Text.VCENTER, null, 10, "A2"+x );
                  }
                  }
                  with ( aData[x] ) {

                  if ( nDisplay <= 0 ) {
                  drawLineRelative( -nX, AML, 0, AML, PS_SOLID, nThick, fLowColor, "L1"+x );
                  drawTextRelative( 1, AML, "AM"+(x+1), fLowColor, null, Text.BOLD | Text.ONTOP | Text.VCENTER, null, 10, "B1"+x );
                  }
                  if ( nDisplay >= 0 ) {
                  drawLineRelative( -nX, PML, 0, PML, PS_SOLID, nThick, fLowColor, "L2"+x );
                  drawTextRelative( 1, PML, "PM"+(x+1), fLowColor, null, Text.BOLD | Text.ONTOP | Text.VCENTER, null, 10, "B2"+x );
                  }
                  }

                  }
                  x++;
                  }
                  }

                  }


                  /*************************************************
                  SUPPORT FUNCTIONS
                  **************************************************/

                  //== gID function assigns unique identifier to graphic/text routines
                  function gID() {
                  grID ++;
                  return( grID );
                  }

                  //== Converts string time representation to minutes
                  function TimeToMinutes( sStr ) {
                  var i;
                  var nTmp;

                  if ( sStr == "0" ) return( -1 );

                  i = sStr.split( ":" );
                  nTmp = 0 + (i[0] * 60) + (i[1]*1);
                  return ( nTmp );
                  }

                  //return the bar time as elapsed minutes
                  function getTime( nOffset ) {
                  return( (getHour(-nOffset)*60) + getMinute(-nOffset) );
                  }

                  function scan( nDays, nCutoff, aArray ) {
                  var x=0;
                  var nH1 = -999999999999.0;
                  var nL1 = 999999999999.0;
                  var nH2 = -999999999999.0;
                  var nL2 = 999999999999.0;
                  var nTotDays = 1;
                  var nThisDay;
                  var nOffset = 0;
                  var nObj = null;
                  var xTime = getValue( "rawtime", 0 );

                  if ( xTime==null ) return( null );

                  //get offset back to first bar of today
                  if ( xTime != null ) {
                  nOffset = getFirstBarIndexOfDay( xTime );
                  }
                  if ( nOffset==null ) return( null );
                  nOffset--;

                  //walk back through time
                  x=nOffset;
                  while( true ) {
                  nThisDay = getDay(x);
                  //error, so get out
                  if ( nThisDay==null ) return( null );
                  nTime = getTime( Math.abs( x ) );
                  //get h/l from afternoon
                  if ( nTime>=nCutoff ) {
                  nH1 = Math.max( nH1, high(x) );
                  nL1 = Math.min( nL1, low(x) );
                  }
                  //get h/l from morning
                  else if ( nTime<nCutoff ) {
                  nH2 = Math.max( nH2, high(x) );
                  nL2 = Math.min( nL2, low(x) );
                  }
                  x--;
                  //moving into a new day
                  if ( getDay(x) != nThisDay ) {
                  nObj = new Object();
                  nObj.AMH = nH2;
                  nObj.AML = nL2;
                  nObj.PMH = nH1;
                  nObj.PML = nL1;
                  aArray[nTotDays-1] = nObj;
                  nObj = null;
                  //collected enough days, get out
                  nTotDays++;
                  if ( nTotDays>nDays ) {
                  break;
                  }

                  //reset our accumulators
                  nH1 = -999999999999.0;
                  nL1 = 999999999999.0;
                  nH2 = -999999999999.0;
                  nL2 = 999999999999.0;
                  }
                  }
                  return( true );
                  }



                  function getMMDDYY( nOffset, sSymbol ) {

                  if ( sSymbol==null ) sSymbol = getSymbol();

                  nMM = iPad( getMonth( -nOffset, sSymbol ) );
                  nYY = getYear( -nOffset, sSymbol );
                  nDD = iPad( getDay( -nOffset, sSymbol ) );

                  return( nMM + nDD + nYY );

                  }


                  function iPad( nVal ) {

                  if ( nVal<10 ) return( "0"+nVal );
                  return( ""+nVal );

                  }
                  Attached Files

                  Comment


                  • #24
                    Inaccurate stdDev Calx

                    Hi guys,

                    I have learned and was able to add the plot types for the lines and changed the colors of each line to meet my needs... However... there is a new problem. The stdDev lines are not plotted in the correct locations.

                    I consulted with a colleague who uses the vwap with stdDev's. He doesnt use esignal but is somewhat versed in java and other code. It seems that the calx for the stdDev is wrong. Here is our conversation:

                    "
                    <jp> Remember that the 1st Stdev has to be weighted by volume
                    <jp> so how does he compute nSTdDev
                    <Nereus> i don't know
                    <jp> all I need to see is the class for nSTDev
                    <Nereus>ok... here it is...

                    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;
                    }

                    <Nereus> is that it?
                    <jp> yes
                    <jp> I think I see the problem...
                    <jp> He didn't weight each summation by the volume at each price...
                    <jp> Each sumX should be weighted by its volume
                    <Nereus> so... everywhere is says SumX?
                    <jp> yes...when he computes the variance(the difference between each price and the VWAP...
                    <jp> he has to multiply it by the volume at that price
                    <jp> And then divide the whole sum by the total current volume
                    for the day.
                    <Nereus> which lines need this change?
                    <jp> the sumX lines and the meanX
                    <jp> tell him to read the section on STDEV at this link:
                    <jp> http://mathworld.wolfram.com/StandardDeviation.html
                    <jp> and previous sections on that site...
                    <jp> It gives a very coherent explanation on how to compute...
                    <jp> the StDev from the distribution function
                    <Nereus> ok... i will convey this to my buddy "

                    Could someone post what the correct efs script should be that will enable the calx to work properly?

                    Thanks very much,

                    Nereus

                    Comment


                    • #25
                      Hello Nereus,

                      I'm certain that the standard deviation function Alex is using is correct. I think you need to send the EFS code to your friend in its entirety. What you are missing is that the price parameter being passed to the function is already adjusted for volume so there's no need to do it within the function. If the price parameter was simply the close, then yes, you would need to make the volume adjustments within the function. Hope this helps.
                      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


                      • #26
                        Thanx Jason for your reply...
                        However.. there is something not quite right. Below are pics of my colleage's chart and of mine for Dec, 6th. Please notice key price points such as at 11:15est, approx 688.40, touches the -2 stdDev on one (his) chart, while on my chart it just barely penetrates the -1 stdDev. Also note where the +2 stdDev closes at 16:15est on his chart (approx 694.1) and on my chart (693.2).

                        Also.. here is further corresponce with colleague...

                        <jp> also take a look at equation 2 here for the variance computation...
                        <jp> http://mathworld.wolfram.com/Variance.html
                        <jp> You will note that each term in the variance is multiplied....
                        <jp> by P(x) before the summation is done....
                        <jp> P(x) is the volume distribution function I have been talking about.

                        Thanks again,
                        Nereus
                        Attached Files

                        Comment


                        • #27
                          Here is my chart... (I dont know how to post two pics in the same post).
                          Attached Files

                          Comment


                          • #28
                            Nereus
                            I have checked my code and as far as I can see it is computing the Standard Deviation of the VWAP correctly .
                            At this point I would suggest that you have your colleague or alternatively one of the EFS Consultants write the efs for you.
                            Alex

                            Comment

                            Working...
                            X