VIDYA.efs EFSLibrary - Discussion Board
File Name: VIDYA.efs
Description:
Indicator - VIDYA (StdDev)
Formula Parameters:
Length: 21
Price: Close
Alpha: 0.02
Notes:
This indicator plots volatility adjusted length exponential MA based
on standard deviation of prices as a measure of volatility. It is dynamic,
not static indicator: a variable-length moving average, which adapts to the
volatility in question by exponentially smoothing data based on standard deviation.
Download File:
VIDYA.efs
EFS Code:
/*********************************Provided By: eSignal (Copyright c eSignal), a division of Interactive Data Corporation. 2008. All rights reserved. This sample eSignal Formula Script (EFS) is for educational purposes only and may be modified and saved under a new file name. eSignal is not responsible for the functionality once modified. eSignal reserves the right to modify and overwrite this EFS file with each new release.Description: Indicator - VIDYA (StdDev) Version: 1.0 09/26/2008Notes: This indicator plots volatility adjusted length exponential MA based on standard deviation of prices as a measure of volatility. It is dynamic, not static indicator: a variable-length moving average, which adapts to the volatility in question by exponentially smoothing data based on standard deviation. Formula Parameters: Default: Length 21 Price Close Alpha 0.02**********************************/ var fpArray = new Array(); var bInit = false; function preMain() { setPriceStudy(true); setStudyTitle("VIDYA (StdDev)"); setCursorLabelName("VIDYA"); var x = 0; fpArray[x] = new FunctionParameter("Length", FunctionParameter.NUMBER); with (fpArray[x++]) { setLowerLimit(1); setDefault(20); } fpArray[x] = new FunctionParameter("Price", FunctionParameter.STRING); with (fpArray[x++]) { setName("Price Data To Use"); addOption("open"); addOption("high"); addOption("low"); addOption("close"); addOption("hl2"); addOption("hlc3"); addOption("ohlc4"); setDefault("close"); } fpArray[x] = new FunctionParameter("Alpha", FunctionParameter.NUMBER); with (fpArray[x++]) { setLowerLimit(0.01); setDefault(0.2); } } var xMyPrice = null; var xStdDev = null; var xStdDevAvg = null; function main(Alpha, Price, Length) { var nState = getBarState(); var nRef = ref(-1); var nStdDevVidya = 0; var nStdDev = 0; var nStdDevAvg = 0; var nPrice = 0; var nResult = 0; var nBarCount = getCurrentBarCount(); if (nState == BARSTATE_ALLBARS) { if (Alpha == null) Alpha = 0.2; if (Price == null) Price = "close"; if (Length == null) Length = 20; } if (bInit == false) { xMyPrice = eval(Price)(); xStdDev = efsInternal("StdDev", xMyPrice, Length); xStdDevAvg = sma(Length, xStdDev); bInit = true; } if (nRef == null) nRef = 1; nStdDev = xStdDev.getValue(0); nStdDevAvg = xStdDevAvg.getValue(0); nPrice = xMyPrice.getValue(0); if (nBarCount > Length) nStdDevVidya = Alpha * (nStdDev / nStdDevAvg) * nPrice + (1 - Alpha * (nStdDev / nStdDevAvg)) * nRef; else if (nBarCount == Length) nStdDevVidya = nPrice; else return; return nStdDevVidya; } function StdDev(DataArray, Period) { var sum = 0; var avg = 0; var res = 0; if (getCurrentBarCount() < Period) return DataArray.getValue(0); for (var barsBack = Period - 1; barsBack >= 0; barsBack--) { sum += DataArray.getValue(barsBack * -1); } avg = sum / Period; sum = 0; for (var barsBack = Period - 1; barsBack >= 0; barsBack--) { sum += (DataArray.getValue(barsBack * -1) - avg) * (DataArray.getValue(barsBack * -1) - avg); } res = Math.sqrt(sum / Period); return res; }