Announcement

Collapse
No announcement yet.

Connors volatility

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

  • Connors volatility

    I did a search in the EFS library and came up with the Connors volatlity formula but it has an error. Could someone assist me in debugging it?
    michael

  • #2
    Michael
    Could you attach the efs and what is the error
    Alex

    Comment


    • #3
      here is the formula:
      Provided By : eSignal. (c) Copyright 2003
      *********************************/

      function preMain() {
      setStudyTitle("Historical Volatility");
      setCursorLabelName("HV ", 0);
      setCursorLabelName(" ", 1);
      setDefaultBarFgColor(Color.blue, 0);
      setDefaultBarFgColor(Color.black, 1);
      }

      function STDV(length) {
      var sumX = 0;
      var sumX2 = 0;
      for (i = 0; i < length; ++i) {
      sumX += aLog[i];
      sumX2 += (aLog[i] * aLog[i])
      }
      var meanX = (sumX/length);
      var stdev = Math.sqrt((sumX2/length) - (meanX*meanX));

      return stdev;
      }

      var aLog = null;

      function main(nLength1, nLength2) {
      if (nLength1 == null || nLength1 < 3)
      nLength1 = 6;
      if (nLength2 == null)
      nLength2 = 100;

      var c = close();
      if (c == null)
      return;

      if (aLog == null && close(-nLength2-1) != null) {
      aLog = new Array(nLength2);
      for (i = 0; i < nLength2; ++i) {
      aLog[i] = Math.log(close(-i)/close(-i-1));
      }
      }

      if (aLog[nLength2-1] == null)
      return;

      if (getBarState() == BARSTATE_NEWBAR) {
      aLog.pop()
      aLog.unshift(Math.log(c/close(-1)));
      } else {
      aLog[0] = Math.log(c/close(-1));
      }

      var stdv1 = STDV(nLength1);
      var stdv2 = STDV(nLength2);

      var HV = (stdv1 * Math.sqrt(256) * 100) / (stdv2 * Math.sqrt(256) * 100);

      if (HV < .5) {
      //setPriceBarColor(Color.cyan);
      setBarBgColor(Color.red);
      } else {
      setBarBgColor(Color.white);
      }

      return new Array(HV, .5);
      }
      michael

      Comment


      • #4
        Michael
        Seems to be working fine here (see image below)



        Did you copy the code to your message exactly as it appears in the Editor?
        If so put a /* in a line above Provided By : eSignal. (c) Copyright 2003
        Alex

        Comment

        Working...
        X