Announcement

Collapse
No announcement yet.

VPO Background change

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

  • VPO Background change

    Is there a way to edit the enclosed EFS so as when the VPO goes below 0 is changes the background color of the chart and when above 0 it changes the background color to a different color?
    Here is the efs:
    /************************************************** *******************************************/
    /* Volume Price Momentum Oscillator */
    /* ver 2.0.0 - Apr 01, 2004 by R.L. Brecko (aka Gavishti) */
    /* */
    /* NO GUARANTEES. USE AT YOUR OWN RISK. */
    /* */
    /* Based on the Volume * Price Momentum Oscillator (V*PMO) found on page 774 of The */
    /* Encyclopedia of Technical Market Indicators. The original used crossing of zero of the */
    /* three day exponential moving average of volume times the current close less the previous */
    /* close as a reversal signal. */
    /************************************************** *******************************************/
    /* REVISIONS: */
    /* 2.1.0 - Apr 02, 2004 by R.L. Brecko */
    /* - Added price source option. */
    /************************************************** *******************************************/

    var aVP, aVPMO;
    var pctMA;
    var i, iType;
    var tmp;

    function preMain()
    {
    setShowTitleParameters(false);
    setShowCursorLabel(true);
    var fp01 = new FunctionParameter("pPeriod", FunctionParameter.NUMBER);
    fp01.setLowerLimit(1);
    fp01.setUpperLimit(100);
    fp01.setDefault(3);
    var fp02 = new FunctionParameter("pLookBack", FunctionParameter.NUMBER);
    fp02.setLowerLimit(1);
    fp02.setUpperLimit(100);
    fp02.setDefault(1);
    var fp03 = new FunctionParameter("pType", FunctionParameter.STRING);
    fp03.addOption("EXPONENTIAL");
    fp03.addOption("SIMPLE");
    fp03.addOption("WEIGHTED");
    fp03.setDefault("EXPONENTIAL");
    var fp04 = new FunctionParameter("pSrc", FunctionParameter.STRING);
    fp04.addOption("O");
    fp04.addOption("H");
    fp04.addOption("L");
    fp04.addOption("C");
    fp04.addOption("HL/2");
    fp04.addOption("HLC/3");
    fp04.addOption("OHLC/4");
    fp04.setDefault("C");
    var fp80 = new FunctionParameter("pThkHist", FunctionParameter.NUMBER);
    fp80.setLowerLimit(1);
    fp80.setUpperLimit(15);
    fp80.setDefault(5);
    var fp90 = new FunctionParameter("pClrBull", FunctionParameter.COLOR);
    fp90.setDefault(Color.RGB(0,144,0)); // green
    var fp91 = new FunctionParameter("pClrBear", FunctionParameter.COLOR);
    fp91.setDefault(Color.RGB(233,0,0)); // red
    var fp92 = new FunctionParameter("pClrNeut", FunctionParameter.COLOR);
    fp92.setDefault(Color.RGB(153,204,255)); // pale blue
    }

    function main(pPeriod, pLookBack, pType, pSrc, pThkHist, pClrBull, pClrBear, pClrNeut)
    {
    if(getBarState() == 2)
    {
    setStudyTitle("VPMO(" + pPeriod + "," + pLookBack + "," + pType.substr(0,1) +
    "," + pSrc + ") v2.1.0");
    setCursorLabelName("VPO", 0);
    setPlotType(PLOTTYPE_HISTOGRAM, 0);
    setDefaultBarThickness(pThkHist, 0);
    aVP = new Array(pPeriod+pLookBack);
    aVPMO = new Array(pPeriod+pLookBack);
    iType = pType == "EXPONENTIAL" ? 1 : pType = "SIMPLE" ? 2 : 3;
    tmp = volume();
    for (i = 0; i < (pPeriod+pLookBack); i++)
    {
    aVP[i] = tmp;
    aVPMO[i] = tmp;
    }
    pctMA = (2.0 / (pPeriod + 1.0));
    return;
    }
    if(getBarState() == 0)
    {
    aVP.pop();
    aVP.unshift(0.0);
    aVPMO.pop();
    aVPMO.unshift(0.0);
    }
    switch (pSrc)
    {
    case "O":
    aVP[0] = volume() * (open() - open(-pLookBack));
    break;
    case "H":
    aVP[0] = volume() * (high() - high(-pLookBack));
    break;
    case "L":
    aVP[0] = volume() * (low() - low(-pLookBack));
    break;
    case "C":
    aVP[0] = volume() * (close() - close(-pLookBack));
    break;
    case "HL/2":
    aVP[0] = volume() * ((high() - high(-pLookBack) + low() - low(-pLookBack)) / 2);
    break;
    case "HLC/3":
    aVP[0] = volume() * ((high() - high(-pLookBack) + low() - low(-pLookBack) +
    close() - close(-pLookBack) ) / 3);
    break;
    case "OHLC/4":
    aVP[0] = volume() *
    (( open() - open(-pLookBack) + high() - high(-pLookBack) +
    low() - low(-pLookBack) + close() - close(-pLookBack) ) / 4);
    }
    switch (iType)
    {
    case 1:
    aVPMO[0] = (aVP[0] - aVPMO[1]) * pctMA + aVPMO[1];
    break;
    case 2:
    tmp = 0;
    for (i = 0; i < pPeriod; i++) tmp += aVP[i];
    aVPMO[0] = tmp / pPeriod;
    break;
    case 3:
    tmp = 0;
    for (i = 0; i < pPeriod; i++) tmp += (pPeriod - i) * aVP[i];
    aVPMO[0] = tmp / pPeriod;
    }
    if(aVPMO[0] > 0) setBarFgColor(pClrBull, 0);
    else if(aVPMO[0] < 0) setBarFgColor(pClrBear, 0);
    else setBarFgColor(pClrNeut, 0);
    return aVPMO[0];
    }
    Thanks for your time...Greg

  • #2
    Greg
    To do what you want replace the following section of code



    with the following



    Replace the colors used in the example with ones of your choice. This modification will paint the entire chart background depending if the VPO is above, below or equal to 0
    Alex

    Comment


    • #3
      VPO Background error

      Alex;
      Thanks for the quick response.
      I did as you said but I get an error saying "line 141 syntax error:invalid return:
      Here is the changed efs;

      /************************************************** *******************************************/
      /* Volume Price Momentum Oscillator */
      /* ver 2.0.0 - Apr 01, 2004 by R.L. Brecko (aka Gavishti) */
      /* */
      /* NO GUARANTEES. USE AT YOUR OWN RISK. */
      /* */
      /* Based on the Volume * Price Momentum Oscillator (V*PMO) found on page 774 of The */
      /* Encyclopedia of Technical Market Indicators. The original used crossing of zero of the */
      /* three day exponential moving average of volume times the current close less the previous */
      /* close as a reversal signal. */
      /************************************************** *******************************************/
      /* REVISIONS: */
      /* 2.1.0 - Apr 02, 2004 by R.L. Brecko */
      /* - Added price source option. */
      /************************************************** *******************************************/

      var aVP, aVPMO;
      var pctMA;
      var i, iType;
      var tmp;

      function preMain()
      {
      setShowTitleParameters(false);
      setShowCursorLabel(true);
      var fp01 = new FunctionParameter("pPeriod", FunctionParameter.NUMBER);
      fp01.setLowerLimit(1);
      fp01.setUpperLimit(100);
      fp01.setDefault(3);
      var fp02 = new FunctionParameter("pLookBack", FunctionParameter.NUMBER);
      fp02.setLowerLimit(1);
      fp02.setUpperLimit(100);
      fp02.setDefault(1);
      var fp03 = new FunctionParameter("pType", FunctionParameter.STRING);
      fp03.addOption("EXPONENTIAL");
      fp03.addOption("SIMPLE");
      fp03.addOption("WEIGHTED");
      fp03.setDefault("EXPONENTIAL");
      var fp04 = new FunctionParameter("pSrc", FunctionParameter.STRING);
      fp04.addOption("O");
      fp04.addOption("H");
      fp04.addOption("L");
      fp04.addOption("C");
      fp04.addOption("HL/2");
      fp04.addOption("HLC/3");
      fp04.addOption("OHLC/4");
      fp04.setDefault("C");
      var fp80 = new FunctionParameter("pThkHist", FunctionParameter.NUMBER);
      fp80.setLowerLimit(1);
      fp80.setUpperLimit(15);
      fp80.setDefault(5);
      var fp90 = new FunctionParameter("pClrBull", FunctionParameter.COLOR);
      fp90.setDefault(Color.RGB(0,144,0)); // green
      var fp91 = new FunctionParameter("pClrBear", FunctionParameter.COLOR);
      fp91.setDefault(Color.RGB(233,0,0)); // red
      var fp92 = new FunctionParameter("pClrNeut", FunctionParameter.COLOR);
      fp92.setDefault(Color.RGB(153,204,255)); // pale blue
      }

      function main(pPeriod, pLookBack, pType, pSrc, pThkHist, pClrBull, pClrBear, pClrNeut)
      {
      if(getBarState() == 2)
      {
      setStudyTitle("VPMO(" + pPeriod + "," + pLookBack + "," + pType.substr(0,1) +
      "," + pSrc + ") v2.1.0");
      setCursorLabelName("VPO", 0);
      setPlotType(PLOTTYPE_HISTOGRAM, 0);
      setDefaultBarThickness(pThkHist, 0);
      aVP = new Array(pPeriod+pLookBack);
      aVPMO = new Array(pPeriod+pLookBack);
      iType = pType == "EXPONENTIAL" ? 1 : pType = "SIMPLE" ? 2 : 3;
      tmp = volume();
      for (i = 0; i < (pPeriod+pLookBack); i++)
      {
      aVP[i] = tmp;
      aVPMO[i] = tmp;
      }
      pctMA = (2.0 / (pPeriod + 1.0));
      return;
      }
      if(getBarState() == 0)
      {
      aVP.pop();
      aVP.unshift(0.0);
      aVPMO.pop();
      aVPMO.unshift(0.0);
      }
      switch (pSrc)
      {
      case "O":
      aVP[0] = volume() * (open() - open(-pLookBack));
      break;
      case "H":
      aVP[0] = volume() * (high() - high(-pLookBack));
      break;
      case "L":
      aVP[0] = volume() * (low() - low(-pLookBack));
      break;
      case "C":
      aVP[0] = volume() * (close() - close(-pLookBack));
      break;
      case "HL/2":
      aVP[0] = volume() * ((high() - high(-pLookBack) + low() - low(-pLookBack)) / 2);
      break;
      case "HLC/3":
      aVP[0] = volume() * ((high() - high(-pLookBack) + low() - low(-pLookBack) +
      close() - close(-pLookBack) ) / 3);
      break;
      case "OHLC/4":
      aVP[0] = volume() *
      (( open() - open(-pLookBack) + high() - high(-pLookBack) +
      low() - low(-pLookBack) + close() - close(-pLookBack) ) / 4);
      }
      switch (iType)
      {
      case 1:
      aVPMO[0] = (aVP[0] - aVPMO[1]) * pctMA + aVPMO[1];
      break;
      case 2:
      tmp = 0;
      for (i = 0; i < pPeriod; i++) tmp += aVP[i];
      aVPMO[0] = tmp / pPeriod;
      break;
      case 3:
      tmp = 0;
      for (i = 0; i < pPeriod; i++) tmp += (pPeriod - i) * aVP[i];
      aVPMO[0] = tmp / pPeriod;
      }
      if(aVPMO[0] > 0) {
      setBarFgcolor(pClrBull, 0);
      setchartBG(color.cyan);
      }
      else if (aVPMO[0] < 0) {
      setBarFgcolor(pClrBear, 0);
      setchartBG(color.yellow);
      }
      else
      setBarFgcolor(pClrNeut, 0);
      setchartBG(color.white);
      }
      return aVPMO[0];
      }

      Can you suggest anything to fix the error?
      Thanks again for everything...Greg

      Comment


      • #4
        Greg
        See the comments in the screenshot enclosed below.
        JavaScript is a case sensitive language so you need to use the proper upper/lower case characters
        Alex

        Comment


        • #5
          VPO Background error

          Alex;
          Many thanks for your time and patience. Works like a charm.
          Have a great week, Greg

          Comment


          • #6
            Greg
            You are most welcome and thank you for letting me know it is now working fine
            Have a great weekend
            Alex

            Comment

            Working...
            X