ConnorHistVolatility.efs

ICE Data Services -


ConnorHistVolatility.efs 
  

File Name: ConnorHistVolatility.efs


Description:
Larry Connor's Historical Volatility


Formula Parameters:
nLength1: Default is 6
nLength2: Default is 100

Notes:
NA

Download File:
ConnorHistVolatility.efs




EFS Code:

/*********************************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);}